椅子ほしいよ

バロンチェア、コンテッサ、あとはレカロシート(車の?)が良さそう。と言うのを見た。
ついでに液晶テレビ買うので台とか。PS3と箱も欲しい。あとコンポ(というかスピーカー?)とアンプとPC新調と・・・。
あとカーペーットとかソファーとかコルクボードとか小物いろいろとかとかとかとかとか。
物欲ってのは無くならないもんすね。

AppAddonMakerは未だに仕様が決まってません。ごめんなさい。orz
どうせならjavascriptでリッチクライアントっぽくしようと思ったら・・・!
中途半端なWSHならあるのでとりあえずこちらで勘弁してくれるとうれしいっす。

if( /wscript\.exe$/i.test( WScript.FullName ) ) {
	new ActiveXObject("WScript.Shell").Run("cmd.exe /c %SystemRoot%\\System32\\CScript.exe \"" + WScript.ScriptFullName + "\" //nologo & pause");
	WScript.Quit();
}

var RecordSet = new ActiveXObject("ADODB.RecordSet")
var Nothing = RecordSet.ActiveConnection;

var intVersion = "2.0 Beta 2";

var FileSystem = WScript.CreateObject("Scripting.FileSystemObject");
var WshShell = WScript.CreateObject("WScript.Shell");

var strCurrentDirectory = FileSystem.GetParentFolderName(WScript.ScriptFullName);
var strSourceDirectory = strCurrentDirectory + "\\src";
var strWorkDirectory = strCurrentDirectory + "\\work";
var strBinDirectory = strCurrentDirectory + "\\bin";
var str7zrExe = strCurrentDirectory + "\\7zr.exe";
var str7zrSfx = strCurrentDirectory + "\\7zS.sfx";
var strHidExe = strCurrentDirectory + "\\hidcon.exe";
var strBaseConfigFile = strCurrentDirectory + "\\AAM.ini";

if(!FileSystem.FileExists(str7zrExe)) {
	Exit(1000);
}
if(!FileSystem.FileExists(str7zrSfx)) {
	Exit(1001);
}

var strBaseConfig = parseIniFile(strBaseConfigFile);
if(strBaseConfig["General"]["Debug"] == null) {
	var intDebug = 0;
} else {
	if(!/^[0-9]/.test(strBaseConfig["General"]["Debug"])) {
		var intDebug = 0;
	} else {
		var intDebug = strBaseConfig["General"]["Debug"];
	}
}
if(/No/i.test(strBaseConfig["General"]["CompressionRatio"])) {
	var intCompressionLevel = 0;
} else if (/Low/i.test(strBaseConfig["General"]["CompressionRatio"])) {
	var intCompressionLevel = 1;
} else if (/Med/i.test(strBaseConfig["General"]["CompressionRatio"])) {
	var intCompressionLevel = 5;
} else if (/High/i.test(strBaseConfig["General"]["CompressionRatio"])) {
	var intCompressionLevel = 9;
} else {
	Exit(1002);
}

if(!FileSystem.FolderExists(strSourceDirectory)) {
	var FileSystem = WScript.CreateObject("Scripting.FileSystemObject");

	FileSystem.CreateFolder(strSourceDirectory);
	FileSystem.CreateFolder(strSourceDirectory + "\\Sample_Projects_v1.0_r1");
	FileSystem.CreateFolder(strSourceDirectory + "\\Sample_Projects_v1.0_r1\\src");

	var objSampleProjects = FileSystem.CreateTextFile(strSourceDirectory + "\\Sample_Projects_v1.0_r1\\src\\sample.txt");
	objSampleProjects.WriteLine("Test");
	objSampleProjects.Close();
	var objSampleProjects = FileSystem.CreateTextFile(strSourceDirectory + "\\Sample_Projects_v1.0_r1\\src\\sample2.txt");
	objSampleProjects.WriteLine("Test");
	objSampleProjects.Close();

	FileSystem.CreateFolder(strSourceDirectory + "\\Sample_Projects_v1.0_r1\\src\\sample");
	var objSampleProjects = FileSystem.CreateTextFile(strSourceDirectory + "\\Sample_Projects_v1.0_r1\\src\\sample\\sample.txt");
	objSampleProjects.WriteLine("Test");
	objSampleProjects.Close();
	var objSampleProjects = FileSystem.CreateTextFile(strSourceDirectory + "\\Sample_Projects_v1.0_r1\\src\\sample\\sample2.txt");
	objSampleProjects.WriteLine("Test");
	objSampleProjects.Close();

	var objSampleProjects = FileSystem.CreateTextFile(strSourceDirectory + "\\Sample_Projects_v1.0_r1\\config.ini");
	objSampleProjects.WriteLine("[General]");
	objSampleProjects.WriteLine("BuildAddon = Yes");
	objSampleProjects.WriteBlankLines(1);
	//objSampleProjects.WriteLine("InnoSetup = No");
	//objSampleProjects.WriteLine("NSIS      = No");
	//objSampleProjects.WriteBlankLines(1);
	objSampleProjects.WriteLine("[Package]");
	objSampleProjects.WriteLine("ExtractPath = ProgramFiles");
	objSampleProjects.WriteLine("ExtractName = Sample Projects");
	objSampleProjects.WriteBlankLines(1);
	objSampleProjects.WriteLine("[Shortcut]");
	objSampleProjects.WriteLine("Path            Directory       Name            File       Description");
	objSampleProjects.WriteLine("AllUsersDesktop|Sample Projects|Sample Projects|sample.txt|Sample Projects Shortcut.");
	objSampleProjects.WriteBlankLines(1);
	objSampleProjects.WriteLine("[Addon]");
	objSampleProjects.WriteLine("Title       = Sample Projects");
	objSampleProjects.WriteLine("Description = Sample Projects Files.");
	objSampleProjects.WriteLine("Version     = 1.0");
	objSampleProjects.WriteLine("WebSite     = http://example.com/");
	objSampleProjects.WriteBlankLines(1);
	objSampleProjects.WriteLine("[RemoveFiles]");
	objSampleProjects.WriteLine("sample2.txt");
	objSampleProjects.WriteLine("sample\\sample2.txt");
	objSampleProjects.Close();

	//var objSampleProjects = FileSystem.CreateTextFile(strSourceDirectory + "\\Sample_Projects_v1.0\\run.cmd");
	//objSampleProjects.WriteLine("@echo off");
	//objSampleProjects.WriteLine("7zr x src.7z -o\"%ProgramFiles%\\Sample Projects\" -y");
	//objSampleProjects.WriteLine("cscript shortcut.js /b");
	//objSampleProjects.WriteLine("exit");
	//objSampleProjects.Close();

	Exit(1003);
}

if(FileSystem.FolderExists(strBinDirectory)) {
	FileSystem.DeleteFolder(strBinDirectory);
	FileSystem.CreateFolder(strBinDirectory);
} else {
	FileSystem.CreateFolder(strBinDirectory);
}
if(FileSystem.FolderExists(strWorkDirectory)) {
	FileSystem.DeleteFolder(strWorkDirectory);
	FileSystem.CreateFolder(strWorkDirectory);
} else {
	FileSystem.CreateFolder(strWorkDirectory);
}

var objSourceList = FileSystem.getFolder(strSourceDirectory);
var objSourceList = new Enumerator(objSourceList.SubFolders);
if(objSourceList.item() == undefined) {
	Exit(1004);
}
/*
for(objSourceList.moveFirst(); !objSourceList.atEnd(); objSourceList.moveNext()) {
	if(null != /(.*)_v(.*)_r([0-9]+)/.exec(objSourceList.item().Name)) {
		var strProjectName = RegExp.$1;
		var strProjectVersion = RegExp.$2;
		var strProjectRevision = RegExp.$3;
		strProjectName = strProjectName.replace(/\s/, "_");
		strProjectVersion = parseFloat(strProjectVersion.replace(/(\.?Alpha\.?|\.?Beta\.?|\.?RC\.?)/, ""));
		WScript.Echo("\"" + strProjectName + "\"");
		WScript.Echo("\"" + strProjectVersion + "\"");
		WScript.Echo("\"" + RegExp.$1.replace("_", "") + "\"");
		WScript.Echo("\"" + strProjectRevision + "\"");
		WScript.Echo("");
	} else {
		//var objSourceList.push(colSourceList.item());
	}
}
*/
WScript.Echo("==============================================================================\n");
WScript.Echo("Application Addon Maker Ver." + intVersion + "\n");
WScript.Echo("==============================================================================\n");

for(objSourceList.moveFirst(); !objSourceList.atEnd(); objSourceList.moveNext()) {
	var strAppName = objSourceList.item().Name;
	var strAppDirectory = strSourceDirectory + "\\" + strAppName;
	var strAppSourceDirectory = strAppDirectory + "\\src";
	var strAppExtraDirectory = strAppDirectory + "\\ext";
	var strAppWorkDirectory = strWorkDirectory + "\\" + strAppName;

	var strAppConfigFile = strAppDirectory + "\\config.ini";

	var strAppCompressionConfigFile = strAppWorkDirectory + "\\config.txt";
	var strAppCompressionTemp = strAppWorkDirectory + "\\temp.7z";
	var strAppCompressionSrc = strAppWorkDirectory + "\\src.7z";
	var strAppTempRemoveFile = strAppWorkDirectory + "\\remove.txt";

	if(FileSystem.FolderExists(strAppWorkDirectory)) {
		FileSystem.DeleteFolder(strAppWorkDirectory);
		FileSystem.CreateFolder(strAppWorkDirectory);
	} else {
		FileSystem.CreateFolder(strAppWorkDirectory);
	}

	WScript.Echo(strAppName + " の作業を開始します。");

	var strAppConfig = parseIniFile(strAppConfigFile);

	if(/Yes/i.test(strAppConfig["General"]["InnoSetup"])) {
		Exit(1);
	}

	if(/Yes/i.test(strAppConfig["General"]["NSIS"])) {
		Exit(1);
	}

	if(strAppConfig["RemoveFiles"][0] != 0) {
		var objTempRemoveFile = FileSystem.OpenTextFile(strAppTempRemoveFile, 8, true);
		for(var i = 1; i <= strAppConfig["RemoveFiles"][0]; i++) {
			objTempRemoveFile.WriteLine(strAppConfig["RemoveFiles"][i]);
		}
		objTempRemoveFile.Close();
	}

	var objAppConfigFile = FileSystem.CreateTextFile(strAppCompressionConfigFile);
	objAppConfigFile.WriteLine(";!@Install@!UTF-8!");
	if(FileSystem.FileExists(strHidExe)) {
		objAppConfigFile.WriteLine("RunProgram=\"hidcon.exe run.cmd\"");
	} else {
		objAppConfigFile.WriteLine("RunProgram=\"run.cmd\"");
	}
	objAppConfigFile.WriteLine(";!@InstallEnd@!");
	objAppConfigFile.Close();

	for(var i = 1; i <= strAppConfig["Shortcut"][0]; i++) {
		Shortcut(
			strAppWorkDirectory,
			strAppSourceDirectory,
			strAppName,
			strAppConfig["Package"]["ExtractPath"],
			strAppConfig["Package"]["ExtractName"],
			strAppConfig["Shortcut"][i + "_Path"],
			strAppConfig["Shortcut"][i + "_Dir"],
			strAppConfig["Shortcut"][i + "_Name"],
			strAppConfig["Shortcut"][i + "_Target"],
			strAppConfig["Shortcut"][i + "_Desc"]
		);
	}

	var objAppCommandFile = FileSystem.CreateTextFile(strAppWorkDirectory + "\\run.cmd");
	objAppCommandFile.WriteLine("@echo off");
	if(strAppConfig["Package"]["ExtractPath"] == "ProgramFiles" || strAppConfig["Package"]["ExtractPath"] == "") {
		objAppCommandFile.WriteLine("7zr x src.7z -o\"%" + strAppConfig["Package"]["ExtractPath"] + "%\\" + strAppConfig["Package"]["ExtractName"] + "\" -y");
	} else {
		objAppCommandFile.WriteLine("7zr x src.7z -o\"" + strAppConfig["Package"]["ExtractPath"] + "\\" + strAppConfig["Package"]["ExtractName"] + "\" -y");
	}
	if(FileSystem.FileExists(strAppWorkDirectory + "\\shortcut.js")) {
		objAppCommandFile.WriteLine("cscript shortcut.js /b");
	}
	objAppCommandFile.WriteLine("exit");
	objAppCommandFile.Close();

	// srcフォルダとextフォルダを同時に処理しよう(配列に渡そう)とすると7zr.exeがエラーを吐く為分離
	var objArchiveFile = new Array(strAppSourceDirectory + "\\*");
	Compression7zip(intDebug, str7zrExe, strAppCompressionSrc, objArchiveFile, strAppTempRemoveFile, intCompressionLevel);
	if(FileSystem.FolderExists(strAppExtraDirectory)) {
		var objArchiveFile = new Array(strAppExtraDirectory + "\\*");
		Compression7zip(intDebug, str7zrExe, strAppCompressionSrc, objArchiveFile, null, intCompressionLevel);
	}

	var objArchiveFile = new Array(strAppCompressionSrc);
	if(FileSystem.FileExists(strHidExe)) {
		objArchiveFile.push(strHidExe);
	}
	if(/Yes/i.test(strBaseConfig["General"]["Include7zipExe"])) {
		objArchiveFile.push(str7zrExe);
	}
	if(FileSystem.FileExists(strAppWorkDirectory + "\\shortcut.js")) {
		objArchiveFile.push(strAppWorkDirectory + "\\shortcut.js");
	}
	if(FileSystem.FileExists(strAppDirectory + "\\run.cmd")) {
		objArchiveFile.push(strAppDirectory + "\\run.cmd");
	} else {
		objArchiveFile.push(strAppWorkDirectory + "\\run.cmd");
	}
	Compression7zip(intDebug, str7zrExe, strAppCompressionTemp, objArchiveFile, null, intCompressionLevel);

	if(/Yes/i.test(strAppConfig["General"]["BuildAddon"])) {
		WScript.Echo("nLite Add-On(CAB圧縮)を作成します。");

		var strAppAddonSvcpackDirectory = strAppWorkDirectory + "\\SVCPACK";
		var strAppAddonFile = strBinDirectory + "\\" + strAppName + ".cab";
		var strAppAddonConfigFile = "ENTRIES_" + strAppName + ".ini";
		var strAppAddonProgramFile = strAppName + ".exe";
		var strAppAddonConfigFilePath = strAppWorkDirectory + "\\" + strAppAddonConfigFile;
		var strAppAddonProgramFilePath = strAppAddonSvcpackDirectory + "\\" + strAppAddonProgramFile;

		FileSystem.CreateFolder(strAppAddonSvcpackDirectory);
		var objAppAddonConfigFile = FileSystem.CreateTextFile(strAppAddonConfigFilePath);
		objAppAddonConfigFile.WriteLine("[General]");
		objAppAddonConfigFile.WriteLine("BuildDate=" + DateFormat("MM/DD/YYYY"));
		objAppAddonConfigFile.WriteLine("Description=" + strAppConfig["Addon"]["Description"]);
		objAppAddonConfigFile.WriteLine("Language=Japanese");
		objAppAddonConfigFile.WriteLine("Title=" + strAppConfig["Addon"]["Title"]);
		objAppAddonConfigFile.WriteLine("Version=" + strAppConfig["Addon"]["Version"]);
		objAppAddonConfigFile.WriteLine("WebSite=" + strAppConfig["Addon"]["WebSite"]);
		objAppAddonConfigFile.WriteBlankLines(1);
		objAppAddonConfigFile.WriteLine("[EditFile]");
		objAppAddonConfigFile.WriteLine("I386\SVCPACK.INF,SetupHotfixesToRun,AddProgram");
		objAppAddonConfigFile.WriteBlankLines(1);
		objAppAddonConfigFile.WriteLine("[AddProgram]");
		objAppAddonConfigFile.WriteLine(strAppName + ".exe");
		objAppAddonConfigFile.Close();

		var objExec = WshShell.Exec("cmd.exe /c copy /b " + str7zrSfx + " + \"" +
			strAppCompressionConfigFile + "\" + \"" + strAppCompressionTemp + "\" \"" + strAppAddonProgramFilePath + "\"");
		while(objExec.Status == 0) {
			WScript.Sleep(100);
		}

		var objMakeCab = new ActiveXObject("MakeCab.MakeCab.1");
		objMakeCab.CreateCab(strAppAddonFile, false, false, false); // Windows 2000 & Windows Vistaだとエラーかも?
		objMakeCab.AddFile(strAppAddonConfigFilePath, strAppAddonConfigFile);
		objMakeCab.AddFile(strAppAddonProgramFilePath, "SVCPACK\\" + strAppAddonProgramFile);
		objMakeCab.CloseCab();
	} else if(/No/i.test(strAppConfig["General"]["BuildAddon"])) {
		WScript.Echo("自己解凍書庫を作成します。");
		var strAppCompressionFile = strBinDirectory + "\\" + strAppName + ".exe";

		var objExec = WshShell.Exec("cmd.exe /c copy /b " + str7zrSfx + " + \"" +
			strAppCompressionConfigFile + "\" + \"" + strAppCompressionTemp + "\" \"" + strAppCompressionFile + "\"");
		while(objExec.Status == 0) {
			WScript.Sleep(100);
		}
	} else {
		Exit(1005);
	}

	WScript.Echo(strAppName + " の作業を終了します。\n");
}

if(intDebug == 0) {
	FileSystem.DeleteFolder(strWorkDirectory);
}

WScript.Echo("全ての作業を終了しました。\n");
WScript.Quit(0);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Exit(intExitCode) {
	/*
	 * 終了コード
	 *
	 *    0: 正常終了
	 *
	 */
	switch(intExitCode) {
		default:
			WScript.Echo("ExitCode " + intExitCode + " です。");
			break;
	}

	WScript.Quit(intExitCode);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// http://d.hatena.ne.jp/teru_while/20070224/1172316315
function parseIniFile(path) {
	var fileSystemObject = WScript.CreateObject("Scripting.FileSystemObject")
	
	var iniHash = {};
	var currentSection, secondSection, currentDate, split;
	var removeCount = 0;
	var shortcutCount = 0;
	var trim = function(str) { return str.replace(/^\s+|\s+$/g, ""); };
	
	if(intDebug >= 1) {
		WScript.Echo("==============================================================================");
	}
	var textStream = fileSystemObject.OpenTextFile(path, 1);
	while(!textStream.AtEndOfStream) {
		var line = trim(textStream.ReadLine());
		if(line.length <= 0) {
			continue;
		}
		if(null != /^\[([^\[]+)\]$/.exec(line)) {
			currentSection = trim(RegExp.$1);
			iniHash[currentSection] = {};
			continue;
		}
		if(null != /^([^=]+)=(.+)$/.exec(line)) {
			secondSection = RegExp.$1;
			currentDate = RegExp.$2;
			secondSection = trim(secondSection);
			currentDate = trim(currentDate);
			if(null == currentSection) {
				iniHash[secondSection] = currentDate;
				if(intDebug >= 1) {
					WScript.Echo("Section = \"" + secondSection + "\"\n" +
					"Date    = \"" + iniHash[secondSection] + "\"\n");
				}
			} else {
				iniHash[currentSection][secondSection] = currentDate;
				if(intDebug >= 1) {
					WScript.Echo("Section = \"" + currentSection + "\"\n" +
						"Name    = \"" + secondSection + "\"\n" +
						"Date    = \"" + iniHash[currentSection][secondSection] + "\"\n");
				}
			}
			continue;
		}
		if("Shortcut" == currentSection) {
			if(null != /(.*)\|(.*)\|(.*)\|(.*)\|(.*)/.exec(line)) {
				shortcutCount++;
				iniHash[currentSection][0] = shortcutCount;
				iniHash[currentSection][shortcutCount + "_Path"] = trim(RegExp.$1);
				iniHash[currentSection][shortcutCount + "_Dir"] = trim(RegExp.$2);
				iniHash[currentSection][shortcutCount + "_Name"] = trim(RegExp.$3);
				iniHash[currentSection][shortcutCount + "_Target"] = trim(RegExp.$4);
				iniHash[currentSection][shortcutCount + "_Desc"] = trim(RegExp.$5);
				if(intDebug >= 1) {
					WScript.Echo("Section = \"" + currentSection + "\"\nCount   = " + iniHash[currentSection][0] + "\n" +
						"Path    = \"" + iniHash[currentSection][shortcutCount + "_Path"] + "\"\n" +
						"Dir     = \"" + iniHash[currentSection][shortcutCount + "_Dir"] + "\"\n" +
						"Name    = \"" + iniHash[currentSection][shortcutCount + "_Name"] + "\"\n" +
						"Target  = \"" + iniHash[currentSection][shortcutCount + "_Target"] + "\"\n" +
						"Desc    = \"" + iniHash[currentSection][shortcutCount + "_Desc"] + "\"\n");
				}
			}
			continue;
		}
		if("RemoveFiles" == currentSection) {
			if(null != /(.*)/.exec(line)) {
				removeCount++;
				iniHash[currentSection][0] = removeCount;
				iniHash[currentSection][removeCount] = trim(RegExp.$1);
				if(intDebug >= 1) {
					WScript.Echo("Section = \"" + currentSection + "\"\n" +
						"Count   = " + iniHash[currentSection][0] + "\n" +
						"Data    = \"" + iniHash[currentSection][removeCount] + "\"\n");
				}
			}
			continue;
		}
	}
	textStream.Close();
	if(intDebug >= 1) {
		WScript.Echo("==============================================================================");
	}

	var textStream = Nothing;
	var trim = Nothing;
	var shortcutCount = Nothing;
	var removeCount = Nothing;
	var currentSection = Nothing;
	var secondSection = Nothing;
	var currentDate = Nothing;
	var splitShortcut = Nothing;
	var fileSystemObject = Nothing;
	var path = Nothing;

	return iniHash;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Shortcut(
		strAppWorkDirectory,
		strAppSourceDirectory,
		strAppName,
		strExtractDirectory,
		strExtractDirectoryName,
		strShortcutPath,
		strShortcutDirectory,
		strShortcutName,
		strShortcutTargetFile,
		strShortcutDescription) {

	var WshShell = WScript.CreateObject("WScript.Shell");
	var FileSystem = WScript.CreateObject("Scripting.FileSystemObject");

	if(strExtractDirectory == "" || strExtractDirectory == "ProgramFiles") {
		var strExtractDirectory = "WshShell.ExpandEnvironmentStrings(\"%ProgramFiles%\")";
	} else {
		var strExtractDirectory = strExtractDirectory;
	}

	if(strExtractDirectoryName) {
		var strExtractDirectoryName = strExtractDirectoryName;
	} else if(strExtractDirectoryName == "") {
		var strExtractDirectoryName = strAppName;
	} else {
		Exit(2000);
	}

	if(strShortcutPath == "AllUsersDesktop") {
		var strShortcutPath = "AllUsersDesktop";
	} else if(strShortcutPath == "AllUsersPrograms") {
		var strShortcutPath = "AllUsersPrograms";
	} else if(strShortcutPath == "AllUsersStartup") {
		var strShortcutPath = "AllUsersStartup";
	} else if(strShortcutPath == "Desktop") {
		var strShortcutPath = "Desktop";
	} else if(strShortcutPath == "Programs") {
		var strShortcutPath = "Programs";
	} else if(strShortcutPath == "Startup") {
		var strShortcutPath = "Startup";
	} else {
		Exit(2001);
	}

	if(strShortcutName) {
		var strShortcutName = strShortcutName;
	} else if(strShortcutName == "") {
		var strShortcutName = strAppName;
	} else {
		Exit(2002);
	}

	if(!FileSystem.FileExists(strAppSourceDirectory + "\\" + strShortcutTargetFile)) {
		Exit(2003);
	}

	if(strShortcutDescription) {
		var strShortcutDescription = strShortcutDescription;
	} else if(strShortcutDescription == "") {
		var strShortcutDescription = strAppName;
	} else {
		Exit(2004);
	}

	var objAppShortcutFile = FileSystem.OpenTextFile(strAppWorkDirectory + "\\shortcut.js", 8, true);
	objAppShortcutFile.WriteLine("var WshShell = WScript.CreateObject(\"WScript.Shell\");");
	objAppShortcutFile.WriteLine("var FileSystem = WScript.CreateObject(\"Scripting.FileSystemObject\");");
	if(strShortcutDirectory == "") {
		objAppShortcutFile.WriteLine("if(!FileSystem.FolderExists(WshShell.SpecialFolders(\"" + strShortcutPath + "\"))) {");
		objAppShortcutFile.WriteLine("\tFileSystem.CreateFolder(WshShell.SpecialFolders(\"" + strShortcutPath + "\"));");
		objAppShortcutFile.WriteLine("}");
		objAppShortcutFile.WriteLine("var objShortCut = WshShell.CreateShortcut(WshShell.SpecialFolders(\"" + strShortcutPath + "\") + \"\\\\\" + \"" + strShortcutName + "\" + \".lnk\");");
	} else {
		objAppShortcutFile.WriteLine("if(!FileSystem.FolderExists(WshShell.SpecialFolders(\"" + strShortcutPath + "\") + \"\\\\\" + \"" + strShortcutDirectory + "\")) {");
		objAppShortcutFile.WriteLine("\tFileSystem.CreateFolder(WshShell.SpecialFolders(\"" + strShortcutPath + "\") + \"\\\\\" + \"" + strShortcutDirectory + "\");");
		objAppShortcutFile.WriteLine("}");
		objAppShortcutFile.WriteLine("var objShortCut = WshShell.CreateShortcut(WshShell.SpecialFolders(\"" + strShortcutPath + "\") + \"\\\\\" + \"" + strShortcutDirectory + "\" + \"\\\\\" + \"" + strShortcutName + "\" + \".lnk\");");
	}
	objAppShortcutFile.WriteLine("objShortCut.TargetPath = " + strExtractDirectory + " + \"\\\\\" + \"" + strExtractDirectoryName + "\" + \"\\\\\" + \"" + strShortcutTargetFile + "\";");
	objAppShortcutFile.WriteLine("objShortCut.Description = \"" + strShortcutDescription + "\";");
	objAppShortcutFile.WriteLine("objShortCut.Save();");
	objAppShortcutFile.Close();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * 7zr.exeのaオプションラッパー関数
 * 変数名              [ リテラル ]  説明
 * intDebug            [   数値   ]  デバッグフラグ
 * str7zrExe           [  文字列  ]  7zr.exeのファイルパス
 * strArchiveName      [  文字列  ]  書庫ファイル名
 * objArchiveFile      [   配列   ]  書庫に含めるファイル一覧の配列
 * strNonArchiveFile   [  文字列  ]  書庫に含めないファイル一覧のテキストファイル nullだと無視
 * intCompressionLevel [   数値   ]  圧縮レベル
 **/

function Compression7zip(intDebug, str7zrExe, strArchiveName, objArchiveFile, strNonArchiveFile, intCompressionLevel) {
	var FileSystem = WScript.CreateObject("Scripting.FileSystemObject");
	var WshShell = WScript.CreateObject("WScript.Shell");

	if(FileSystem.FileExists(str7zrExe)) {
		str7zrCommand = str7zrExe + " a -t7z"
	} else {
		Exit(3000);
	}

	if(strArchiveName != "") {
		strArchiveName = "\"" + strArchiveName + "\""
	} else {
		Exit(3001);
	}

	var strArchiveFile = "";
	if(objArchiveFile.length > 0) {
		for(var i = 0; objArchiveFile.length > i; i++) {
			strArchiveFile = strArchiveFile + "\"" + objArchiveFile[i] + "\" ";
		}
	} else {
		Exit(3002);
	}

	if(strNonArchiveFile == null) {
		strNonArchiveFile = "";
	} else if(FileSystem.FileExists(strNonArchiveFile)) {
		strNonArchiveFile = "-x@\"" + strNonArchiveFile + "\"";
	} else {
		Exit(3003);
	}

	if(!/^[0-9]/.test(intCompressionLevel)) {
		Exit(3004);
	}

	var objExec = WshShell.Exec(str7zrCommand + " " + strArchiveName + " " + strArchiveFile + " " + strNonArchiveFile + " -mx=" + intCompressionLevel);
	while(objExec.Status == 0) {
		WScript.Sleep(100);
	}
	if(intDebug >= 1) {
		WScript.Echo("==============================================================================");
		while (!objExec.StdOut.AtEndOfStream) {
			WScript.Echo(objExec.StdOut.ReadLine());
		}
		WScript.Echo("==============================================================================");
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function DateFormat(strFormat) {
	var objDate = new Date();
	if(strFormat == "MM/DD/YYYY") {
		var intYear = objDate.getFullYear();
		if(objDate.getMonth() < 9) {
			var intMonth = "0" + (objDate.getMonth() + 1);
		} else {
			var intMonth = (objDate.getMonth() + 1);
		}
		if(objDate.getDate() < 10) {
			var intDate = "0" + objDate.getDate();
		} else {
			var intDate = objDate.getDate();
		}
		var strTime = intMonth + "/" + intDate + "/" + intYear;
	} else {
		var strTime = objDate;
	}
	return strTime;
}