void IEnvironmentManager.ExecuteUpdater(PatcherConfig patcherConfig) { //the patcher directory will contain the patcher executable file aswell as it's dependencies var patcherDirectory = GetTempDirectory(patcherConfig.ProjectId).CreateSubdirectory("patcher"); //copy patcher assembly var patcherAssembly = new FileInfo(Assembly.GetAssembly(typeof(WindowsPatcher)).Location); var targetLocation = Path.Combine(patcherDirectory.FullName, Path.GetFileNameWithoutExtension(patcherAssembly.Name) + ".exe"); if (File.Exists(targetLocation)) { File.Delete(targetLocation); } patcherAssembly.CopyTo(targetLocation); //copy dependencies CopyFileSameName(Assembly.GetAssembly(typeof(UpdateController <>)).Location, patcherDirectory); CopyFileSameName(Assembly.GetAssembly(typeof(JsonConvert)).Location, patcherDirectory); var arguments = new List <string>(); ActionConfig = patcherConfig; File.WriteAllText(Path.Combine(patcherDirectory.FullName, "patcher.cfg"), JsonConvert.SerializeObject(this, typeof(WindowsPatcherConfig), Formatting.Indented, Program.JsonSerializerSettings)); arguments.Add("/config patcher.cfg"); if (CustomUi != null) { //copy custom ui assemblies to subfolder var updaterUiDirectory = patcherDirectory.CreateSubdirectory("updaterUi"); var customUiFilename = Path.Combine(updaterUiDirectory.FullName, "CustomUi.dll"); File.Copy(CustomUi.AssemblyPath, customUiFilename); if (CustomUi.RequiredLibraries?.Count > 0) { foreach (var requiredLibrary in CustomUi.RequiredLibraries) { CopyFileSameName(requiredLibrary, updaterUiDirectory); } } arguments.Add("/updaterUi updaterUi\\CustomUi.dll"); } if (Language == null) { Language = WindowsUpdaterTranslation.English; } if (Language is ImplementedUpdaterTranslation implementedUpdaterTranslation) { arguments.Add("/language " + implementedUpdaterTranslation.KeyName); } else { File.WriteAllText(Path.Combine(patcherDirectory.FullName, "language.json"), JsonConvert.SerializeObject(Language.Values)); arguments.Add("/languageFile language.json"); } var currentProcess = Process.GetCurrentProcess(); arguments.Add("/hostProcess " + currentProcess.Id); var startInfo = new ProcessStartInfo(patcherAssembly.FullName, "patch " + string.Join(" ", arguments)) { UseShellExecute = true, //required for runas WorkingDirectory = patcherDirectory.FullName }; if (RunAsAdministrator) { startInfo.Verb = "runas"; } var process = Process.Start(startInfo); if (process == null) { throw new InvalidOperationException("Unable to start patcher process."); } //close this application _applicationCloser?.ExitApplication(); }
public WindowsPatcherTranslation(IWindowsUpdaterTranslation windowsUpdaterTranslation) { _translations = windowsUpdaterTranslation.Values; }