예제 #1
0
 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();
     });
 }
예제 #2
0
        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.");
        }
예제 #3
0
 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.");
 }
예제 #4
0
 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));
 }
예제 #5
0
        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();
            });
        }
예제 #6
0
 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());
     }
 }
예제 #7
0
        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.");
            }
        }
예제 #8
0
 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);
         }
     }
 }
예제 #9
0
        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.");
                }
        }
예제 #10
0
 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.");
     }
 }
예제 #11
0
 public abstract Task DoWork(UpdateTaskExecutor executor);
예제 #12
0
 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.");
 }
예제 #13
0
 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.");
     }
 }
예제 #14
0
 public abstract Task DoWork(UpdateTaskExecutor executor);
예제 #15
0
 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.");
 }
예제 #16
0
 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.");
 }