static int GenerateVersionResource(ConsoleService c, string cmdName, string str) { ConsoleParam[] args = { new ConsoleParam("[targetFileName]", ConsoleService.Prompt, "Target Filename: ", ConsoleService.EvalNotEmpty, null), new ConsoleParam("OUT", ConsoleService.Prompt, "Dst Filename: ", ConsoleService.EvalNotEmpty, null), new ConsoleParam("PRODUCT"), new ConsoleParam("RC"), new ConsoleParam("POSTFIX"), }; ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); string targetFilename = vl.DefaultParam.StrValue; string outFilename = vl["OUT"].StrValue; string product_name = vl["PRODUCT"].StrValue; string postfix = vl["POSTFIX"].StrValue; Win32BuildTool.GenerateVersionInfoResource(targetFilename, outFilename, vl["RC"].StrValue, product_name, postfix, Paths.GetUltraSubmoduleCommitId(), Paths.GetUltraVersionLabel()); return(0); }
public static void SetManifest(string exe, string manifestName) { Mutex x = new Mutex(false, MutexName); x.WaitOne(); try { // Manifest file name string filename = Path.Combine(Paths.ManifestsDir, manifestName); if (File.Exists(filename) == false) { throw new FileNotFoundException(filename); } FileInfo fi = new FileInfo(exe); // Copy exe file to a temporary directory string exeTmp = IO.CreateTempFileNameByExt(".exe"); IO.FileCopy(exe, exeTmp); string mtFileName = Path.Combine(Paths.MicrosoftSDKBinDir, "mt.exe"); string mtArgs = string.Format("-nologo -manifest \"{0}\" -outputresource:\"{1}\";1", filename, exeTmp); Exception ex = null; int i; // Repeated 20 times in order to avoid locking the file by the anti-virus software for (i = 0; i < 20; i++) { try { // Execute Win32BuildTool.ExecCommand(mtFileName, mtArgs, false, true); ex = null; break; } catch (Exception ex2) { ex = ex2; } ThreadObj.Sleep(Secure.Rand31i() % 50); } if (ex != null) { throw new ApplicationException("mt.exe Manifest Processing for '" + exe + "' Failed."); } ex = null; // Revert to the original file for (i = 0; i < 20; i++) { try { IO.FileCopy(exeTmp, exe); ex = null; break; } catch (Exception ex2) { ex = ex2; } ThreadObj.Sleep(Secure.Rand31i() % 50); } // Restore the date and time File.SetCreationTime(exe, fi.CreationTime); File.SetLastAccessTime(exe, fi.LastAccessTime); File.SetLastWriteTime(exe, fi.LastWriteTime); } finally { x.ReleaseMutex(); } }
public static void Test() { Win32BuildTool.ExecCommand(@"C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x86\mt.exe", "-test", no_stdout: true); }