Exemple #1
0
        protected virtual void UpdateAsync(string url, string filename, bool silent, object userState)
        {
            WebClient client = null;
            WorkingUI work = null;

            try
            {
                if (silent == false)
                {
                    work = new WorkingUI();
                }

                string updatedExePath = Path.Combine(Program.AppData, filename);

                client = new WebClient();
                client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(updater_DownloadFileCompleted);
                client.DownloadFileAsync(new Uri(url), updatedExePath, new object[] { client, updatedExePath, silent, work, userState });
            }
            catch
            {
                if (client != null)
                {
                    client.Dispose();
                    client = null;
                }

                if (silent == false)
                {
                    work.Dispose();
                }

                throw;
            }
        }
        public void InstallAsync()
        {
            var work = new WorkingUI(cntx);

            IUpdater updater = new GitHubUpdater("iamxail", Program.SafeName);
            updater.CheckCompleted += new CheckCompletedEventHandler(updater_CheckCompleted);
            updater.CheckAsync(new object[] { updater, work } );
        }
        private void InstallInternal(WorkingUI work)
        {
            try
            {
                string installedExePath = Path.Combine(Program.AppData, Program.SafeName + "_" + Program.Version + ".exe");

                try
                {
                    if (Directory.Exists(Program.AppData) == false)
                    {
                        Directory.CreateDirectory(Program.AppData);
                    }

                    File.Copy(Application.ExecutablePath, installedExePath, true);
                    FileUnblocker.Unblock(installedExePath);
                }
                catch
                {
                }

                string argsStr = string.Empty;

                var args = Environment.GetCommandLineArgs();
                if (args.Length > 1)
                {
                    argsStr = string.Join(" ", args, 1, args.Length - 1);
                }

                argsStr += " /setstartup";

                Process.Start(installedExePath, argsStr + " /forcestart");
            }
            catch (Exception ex)
            {
                work.MessageBoxShow("Daily Wallpainter를 설치하는 중에 문제가 발견되었습니다.\r\n\r\n" + ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                try
                {
                    work.Dispose();
                }
                catch
                {
                }

                cntx.BeginInvoke(new MethodInvoker(() =>
                {
                    Application.Exit();
                }));
            }
        }
 private void updater_UpdateCompleted(object sender, UpdateCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         using (var work = new WorkingUI())
         {
             work.MessageBoxShow("업데이트 설치 중에 문제가 발견되었습니다.\r\n\r\n" + e.Error.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }