private void MainForm_Shown(object sender, EventArgs e) { // kup.exe [ver_str] [pubkey path] [base path] [process id] [runas] var args = Environment.GetCommandLineArgs().Skip(1).ToArray(); if (args.Length < 5) { MessageBox.Show("Invalid argument." + Environment.NewLine + Environment.GetCommandLineArgs(), "Update error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); Environment.Exit(-1); } var ver = Version.Parse(args[0]); var pubkey = File.ReadAllText(args[1]); var exec = new UpdateTaskExecutor(ver, pubkey, args[2], int.Parse(args[3]), args[0].Count(c => c == '.') == 3); exec.OnNotifyProgress += str => this.Invoke(new Action(() => this.logField.AppendText(str))); Task.Run(async () => { try { await exec.StartUpdate(this._cancelSource.Token); } catch (Exception ex) { MessageBox.Show("Fatal error occured." + Environment.NewLine + ex); Application.Exit(); Environment.Exit(-1); } Application.Exit(); }); }
public override async Task DoWork(UpdateTaskExecutor executor) { executor.NotifyProgress("removing file: " + _path + " ...", false); await Task.Run(() => File.Delete(Path.Combine(executor.BasePath, _path))); executor.NotifyProgress("ok."); }
public override async Task DoWork(UpdateTaskExecutor executor) { if (_path.EndsWith("/")) { // directory var target = Path.Combine(executor.BasePath, _path.Substring(0, _path.Length - 1)); if (Directory.Exists(target)) { executor.NotifyProgress("removing directory: " + _path + " ...", false); await Task.Run(() => Directory.Delete(target, true)); } else { executor.NotifyProgress("directory " + _path + " is not existed. nothing to do."); } } else { // file var target = Path.Combine(executor.BasePath, _path); if (File.Exists(target)) { executor.NotifyProgress("removing file: " + _path + " ...", false); await Task.Run(() => File.Delete(target)); } else { executor.NotifyProgress("file " + _path + " is not existed. nothing to do."); } } executor.NotifyProgress("ok."); }
private void MainForm_Shown(object sender, EventArgs e) { //todo: fill parameters var exec = new UpdateTaskExecutor("PUBLIC KEY", "BASEPATH"); exec.OnNotifyProgress += str => this.Invoke(new Action(() => this.logField.AppendText(str))); Task.Run(() => exec.StartUpdate(this._cancelSource.Token)); }
private void MainForm_Shown(object sender, EventArgs e) { // kup.exe [ver_str] [pubkey path] [base path] [process id] [runas] var args = Environment.GetCommandLineArgs().Skip(1).ToArray(); if (args.Length < 5) { MessageBox.Show("Invalid argument." + Environment.NewLine + Environment.GetCommandLineArgs(), "Update error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); Environment.Exit(-1); } var ver = Version.Parse(args[0]); var pubkey = File.ReadAllText(args[1]); var exec = new UpdateTaskExecutor(ver, pubkey, args[2], int.Parse(args[3]), args[0].Count(c => c == '.') == 3); exec.OnNotifyProgress += str => this.Invoke(new Action(() => this.logField.AppendText(str))); Task.Run(async() => { try { await exec.StartUpdate(this._cancelSource.Token); } catch (Exception ex) { MessageBox.Show("Fatal error occured." + Environment.NewLine + ex); Application.Exit(); Environment.Exit(-1); } Application.Exit(); }); }
public override async Task DoWork(UpdateTaskExecutor executor) { var process = Process.Start(Path.Combine(executor.BasePath, _path)); if (_awaitProcess && process != null) { await Task.Run(() => process.WaitForExit()); } }
public override async Task DoWork(UpdateTaskExecutor executor) { executor.NotifyProgress("executing binary: " + _path); var process = Process.Start(Path.Combine(executor.BasePath, _path)); if (_awaitProcess && process != null) { executor.NotifyProgress("waiting exit...", false); await Task.Run(() => process.WaitForExit()); executor.NotifyProgress("ok."); } }
public async override Task DoWork(UpdateTaskExecutor executor) { executor.NotifyProgress("downloading patch package..."); var file = await executor.DownloadBinary(Url); using (var ms = new MemoryStream(file)) using (var ss = new MemoryStream()) { if (!Cryptography.Verify(ms, ss, executor.PublicKey)) { executor.NotifyProgress("Invalid signature."); throw new Exception("Package signature is not matched."); } var archive = new ZipArchive(ss); foreach (var entry in archive.Entries) { await this.Extract(entry, executor.BasePath); } } }
public async override Task DoWork(UpdateTaskExecutor executor) { executor.NotifyProgress("downloading patch package..."); byte[] file = null; for (var i = 0; i < 3; i++) { file = await executor.DownloadBinary(this.Url); if (file != null) { break; } executor.NotifyProgress("<!> patch package download failed. awaiting server a few seconds...", false); await Task.Run(() => Thread.Sleep(10000)); executor.NotifyProgress("retrying download patch package..."); } if (file == null) { executor.NotifyProgress("***** FATAL: patch package download failed! *****"); throw new UpdateException("patch package download failed."); } using (var ms = new MemoryStream(file)) using (var ss = new MemoryStream()) { executor.NotifyProgress("verifying patch pack...", false); if (!Cryptography.Verify(ms, ss, executor.PublicKey)) { executor.NotifyProgress("Invalid signature."); throw new UpdateException("patch package signature is not valid."); } executor.NotifyProgress("verified."); executor.NotifyProgress("applying patches."); var archive = new ZipArchive(ss); foreach (var entry in archive.Entries) { executor.NotifyProgress("patching " + entry.Name + "..."); await this.Extract(entry, executor.BasePath); } executor.NotifyProgress("patch completed."); } }
public async override Task DoWork(UpdateTaskExecutor executor) { executor.NotifyProgress("downloading patch package..."); byte[] file = null; for (var i = 0; i < 3; i++) { file = await executor.DownloadBinary(this.Url); if (file != null) break; executor.NotifyProgress("<!> patch package download failed. awaiting server a few seconds...", false); await Task.Run(() => Thread.Sleep(10000)); executor.NotifyProgress("retrying download patch package..."); } if (file == null) { executor.NotifyProgress("***** FATAL: patch package download failed! *****"); throw new UpdateException("patch package download failed."); } using (var ms = new MemoryStream(file)) using (var ss = new MemoryStream()) { executor.NotifyProgress("verifying patch pack...", false); if (!Cryptography.Verify(ms, ss, executor.PublicKey)) { executor.NotifyProgress("Invalid signature."); throw new UpdateException("patch package signature is not valid."); } executor.NotifyProgress("verified."); executor.NotifyProgress("applying patches."); var archive = new ZipArchive(ss); foreach (var entry in archive.Entries) { executor.NotifyProgress("patching " + entry.Name + "..."); await this.Extract(entry, executor.BasePath); } executor.NotifyProgress("patch completed."); } }
public abstract Task DoWork(UpdateTaskExecutor executor);
public override async Task DoWork(UpdateTaskExecutor executor) { if (_path.EndsWith("/")) { // directory executor.NotifyProgress("removing directory: " + _path + " ...", false); await Task.Run(() => Directory.Delete( Path.Combine(executor.BasePath, _path.Substring(0, _path.Length - 1)), true)); } else { // file executor.NotifyProgress("removing file: " + _path + " ...", false); await Task.Run(() => File.Delete(Path.Combine(executor.BasePath, _path))); } executor.NotifyProgress("ok."); }