private async Task <bool> UpdateRegistry(ServerResponse <GetHospitalServersResponse> getHospitalServerResponse) { var freeze = FreezeHelper.IsFreezeEnabled(); using (var key = Registry.LocalMachine.OpenSubKey("Software", true)) using (var panacea = key.CreateSubKey("Panacea")) { if (panacea.GetValue("HospitalServer", "").ToString() == getHospitalServerResponse.Result.HospitalServers[0] && panacea.GetValue("TerminalServerResponse", "").ToString() == JsonSerializer.SerializeToString(getHospitalServerResponse)) { return(true); } if (await LockdownManager.IsFrozen() == true) { ReportProgress("Rebooting to unfreeze (apply new settings)"); LockdownManager.Unfreeze(); App.ShutdownSafe(false); return(false); } panacea.SetValue("TerminalServer", _server); panacea.SetValue("HospitalServer", getHospitalServerResponse.Result.HospitalServers[0]); panacea.SetValue("TerminalServerResponse", JsonSerializer.SerializeToString(getHospitalServerResponse)); return(true); } }
internal override async Task <bool> OnPreUpdate(SafeDictionary <string, object> keys) { if (!File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NDP46-KB3045557-x86-x64-AllOS-ENU.exe"))) { return(true); } ReportProgress("Checking framework version..."); if (!DotNetVersionHelper.RequiresUpdate()) { return(true); } if (await LockdownManager.IsFrozen() == true) { LockdownManager.Unfreeze(); App.ShutdownSafe(false); return(false); } ReportProgress("Installing Framework... (this might take a while)"); return(await Task.Run(() => { var p = Process.Start(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NDP46-KB3045557-x86-x64-AllOS-ENU.exe"), "/q"); p?.WaitForExit(); return true; })); }
internal override async Task <bool> OnAfterUpdate(SafeDictionary <string, object> keys) { return(true); if (!File.Exists(Common.Path() + FlashFileName)) { return(true); } using (var key = Registry.LocalMachine.OpenSubKey(RegistryPath)) { if (key != null) { if (key.GetValue("Version", "").ToString().StartsWith("27")) { return(true); } } if (await LockdownManager.IsFrozen() == true) { LockdownManager.Unfreeze(); ReportProgress("Rebooting to unfreeze..."); await Task.Delay(2000); App.ShutdownSafe(); return(false); } ReportProgress("Installing Flash..."); await InstallFlash(); } return(true); }
internal override async Task <bool> OnAfterUpdate(SafeDictionary <string, object> keys) { var unfreezeRequired = FreezeHelper.IsFreezeEnabled() && (await LockdownManager.IsFrozen()) == true; var filename = @"C:\Windows\SysWOW64\Macromed\Flash\FlashUtil32_21_0_0_242_Plugin.exe"; if (File.Exists(filename)) { try { File.Delete(filename); } catch { } } ReportProgress("Removing scheduled tasks..."); try { await System.Threading.Tasks.Task.Delay(1000); var res = await System.Threading.Tasks.Task.Run(() => { using (TaskService ts = new TaskService()) { foreach (var task in ts.AllTasks) { if (BadNames.Any(str => task.Name.Contains(str))) { if (unfreezeRequired) { LockdownManager.Unfreeze(); return(false); } task.Stop(); ReportProgress($"Removing scheduled task {task.Name}"); ts.RootFolder.DeleteTask(task.Name); } } } return(true); }); if (!res) { return(false); } ReportProgress("Removing services..."); await System.Threading.Tasks.Task.Delay(1000); res = await System.Threading.Tasks.Task.Run(() => { var services = ServiceController.GetServices(); int i = 0; foreach (var service in services) { Debug.WriteLine(i); i++; if (BadNames.Any(str => service.DisplayName.Contains(str))) { if (unfreezeRequired) { LockdownManager.Unfreeze(); return(false); } var ServiceInstallerObj = new ServiceInstaller(); var Context = new InstallContext(Common.Path(), null); ServiceInstallerObj.Context = Context; ServiceInstallerObj.ServiceName = service.ServiceName; ReportProgress($"Removing service {service.DisplayName}"); ServiceInstallerObj.Uninstall(null); } } return(true); }); return(res); } catch { } return(true); }
private async Task Load() { OnProgressTotal("Initializing..."); var info = await TerminalIdentification.TerminalIdentificationManager.GetIdentificationInfoAsync(); if (info?.Putik != null) { Putik.Text = info.Putik; } await Task.Run(() => { BuildArgumentsDictionary(); }); OnProgressTotal("Waiting for network..."); await Common.WaitForNetwork(); var dict = new SafeDictionary <string, object>(); foreach (var k in _keys.Keys) { dict.Add(k, _keys[k]); } PrepareModules(); var totalSteps = _modules.Count(module => module.GetType().GetMethod("OnPreUpdate", BindingFlags.NonPublic | BindingFlags.Instance).DeclaringType == module.GetType()) + _modules.Count(module => module.GetType().GetMethod("OnUpdate", BindingFlags.NonPublic | BindingFlags.Instance).DeclaringType == module.GetType()) + _modules.Count(module => module.GetType().GetMethod("OnAfterUpdate", BindingFlags.NonPublic | BindingFlags.Instance).DeclaringType == module.GetType()); TotalProgressBar.Maximum = totalSteps; try { if (!await ExecModuleFunc("OnPreUpdate", dict) || !await ExecModuleFunc("OnUpdate", dict) || !await ExecModuleFunc("OnAfterUpdate", dict)) { return; } } catch (Exception ex) { OnProgressTotal($"A module reported failure ({moduleName}): {ex.Message} {ex.InnerException?.Message}"); await Task.Delay(10000); App.ShutdownSafe(false); Process.Start(Common.Path("Updater.Replacer.exe")); return; } if (_modules.Any(m => m.RequiresUpdaterRestart)) { App.ShutdownSafe(false); Process.Start(Common.Path("Updater.Replacer.exe")); return; } if (await LockdownManager.IsFrozen() == false && FreezeHelper.IsFreezeEnabled()) { OnProgressTotal("Rebooting to freeze"); await Task.Delay(3500); LockdownManager.Freeze(); App.ShutdownSafe(false); return; } OnProgressTotal("Update completed"); StartPanacea(); }
internal override async Task <bool> OnAfterUpdate(SafeDictionary <string, object> keys) { if (Debugger.IsAttached) { if (MessageBox.Show("Install updates?", "Caution", MessageBoxButton.YesNo) == MessageBoxResult.No) { return(true); } } ReportProgress("Installing Updates"); await Task.Delay(1000); var dir = new DirectoryInfo(Common.Path() + "Updates"); if (!dir.Exists) { dir.Create(); } var name = Environment.MachineName; try { var resp = await ServerRequestHelper.GetObjectFromServerAsync <TerminalInfoResponse>(keys["hospitalserver"].ToString(), "get_terminal_info/"); name = resp.Result.TerminalName; } catch { //maybe get_terminal_info not implemented - compatibility } var nameRequiresChange = name != Environment.MachineName; ////throw new Exception("Sfgfg"); var response = await ServerRequestHelper.GetObjectFromServerAsync <List <UpdatePackage> >(keys["hospitalserver"].ToString(), "get_terminal_updates/"); var updates = new List <Update>(); var freeze = FreezeHelper.IsFreezeEnabled(); if (!response.Success) { return(true); } if (nameRequiresChange) { if (await LockdownManager.IsFrozen() == true) { ReportProgress("Rebooting to unfreeze"); await Task.Delay(1500); LockdownManager.Unfreeze(); App.ShutdownSafe(false); return(true); } } response.Result.ForEach(p => p.Updates.ForEach(u => u.PackageId = p.Id)); if (nameRequiresChange) { if (Debugger.IsAttached) { if (MessageBox.Show("Change hostname?", "Question", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Common.SetMachineName(name); } } else { Common.SetMachineName(name); ReportProgress("Rebooting to change hostname"); await Task.Delay(3000); ProcessHelper.Reboot(); return(true); } } foreach (var package in response.Result) { ReportProgress(package.Name); foreach (var update in package.Updates) { try { if (SkipUpdate(update.Id)) { continue; } if (await LockdownManager.IsFrozen() == true) { ReportProgress("Rebooting to unfreeze"); await Task.Delay(1500); LockdownManager.Unfreeze(); App.ShutdownSafe(false); return(true); } updates.Add(update); var tempPath = System.IO.Path.GetTempPath(); //C:\\Users\\<UserName>\\AppData\\Local\\Temp var updateDir = new DirectoryInfo(tempPath + "PanaceaUpdates\\" + update.Id); if (!updateDir.Exists) { updateDir.Create(); } await _webClient.DownloadFileTaskAsync( new Uri(keys["hospitalserver"] + "/" + update.PatchScript), updateDir + "\\" + Path.GetFileName(update.PatchScript)); foreach (var file in update.RequiredFiles) { await _webClient.DownloadFileTaskAsync( new Uri(keys["hospitalserver"] + "/" + file), updateDir + "\\" + Path.GetFileName(file)); } ReportProgress("Installing..."); var code = await Task.Run(() => { var info = new ProcessStartInfo() { WorkingDirectory = updateDir.ToString(), FileName = updateDir + "\\" + Path.GetFileName(update.PatchScript), CreateNoWindow = true, UseShellExecute = false, Verb = "runas" }; var p = new Process { StartInfo = info }; try { p.Start(); p.WaitForExit(); return(p.ExitCode); } catch { return(9001); } }); //OnProgressFiles(code == 0 ? "Installation successful!" : "Installation failed"); await Task.Delay(1000); update.Installed = code == 0; update.ExitCode = code; if (code != 0) { continue; } AddRegistryUpdate(update); await ReportToServer(keys["hospitalserver"].ToString(), update.Id, package.Id, code); try { File.Delete(updateDir + "\\" + Path.GetFileName(update.PatchScript)); foreach (var file in update.RequiredFiles) { File.Delete(updateDir + "\\" + Path.GetFileName(file)); } } catch { } if (update.RequiresReboot != "yes") { continue; } ProcessHelper.Reboot(); return(false); } catch { update.ExitCode = 9999; AddRegistryUpdate(update); await ReportToServer(keys["hospitalserver"].ToString(), update.Id, package.Id, 9999); } } } if (updates.All(u => u.ExitCode != 0)) { foreach (var update in updates) { AddRegistryUpdate(update); await ReportToServer(keys["hospitalserver"].ToString(), update.Id, update.PackageId, update.ExitCode); } } if (updates.Any(u => u.RequiresReboot == "batch" && u.ExitCode == 0)) { ReportProgress("Restarting..."); await Task.Delay(1500); ProcessHelper.Reboot(); return(false); } if (updates.Any(u => u.ExitCode != 0) && updates.Any(u => u.ExitCode == 0)) { ReportProgress("Rebooting to retry updates that failed..."); await Task.Delay(1500); ProcessHelper.Reboot(); return(false); } if (await LockdownManager.IsFrozen() == false && freeze) { if (updates.All(u => u.ExitCode == 0) || updates.All(u => u.ExitCode != 0)) { ReportProgress("Rebooting to freeze"); await Task.Delay(1500); LockdownManager.Freeze(); } App.ShutdownSafe(false); return(false); } return(true); }