Exemplo n.º 1
0
        private void UpdateForm_Shown(object sender, EventArgs e)
        {
            var cmd = Environment.GetCommandLineArgs();
#if DEBUG
            cmd[1] = "0.00";
#endif
            if(cmd.Length < 2)
            {
#if DEBUG
                cmd = new[] { "", "0.00" };
#else
                MessageBox.Show("Information losted.", "Updater", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                Application.Exit();
                return;
#endif
            }
            double ver = double.Parse(cmd[1]);
            Write("初期化しています...");
            up = new UpdateProcessor(Write);
            this.Text = "Krile Update " + up.UpdaterVersion;
            up.Destination = Application.StartupPath;
            up.SetCancellable += new Action<bool>(up_SetCancellable);
            WriteLine("完了.");
            Write("Krileの終了を待機しています...");
            int pid;
            if (cmd.Length >= 3 &&
                int.TryParse(cmd[2], out pid))
            {
                //プロセス終了を待つ
                Write("(プロセスID:" + pid.ToString() + ")...");
                try
                {
                    var p = Process.GetProcessById(pid);
                    for(int i = 0; i < 10 && !p.HasExited; i++)
                    {
                        p.WaitForExit(1000);
                        Write(".");
                    }
                    WriteLine("");

                    if (!p.HasExited)
                    {
                        //Krileがシャットダウンしない
                        WriteLine("<!>Krileがハングアップしている可能性があります。強制終了します...");
                        p.Kill();
                        Write("強制終了を待機しています...");
                        for (int i = 0; i < 10; i++)
                        {
                            Write(".");
                            p.WaitForExit(100);
                        }
                        WriteLine("");
                        if(p.HasExited)
                            WriteLine("Krileは終了されました。");
                        else
                        {
                            WriteLine("Krileを終了できませんでした。");
                            MessageBox.Show(
                                "Krileを終了できないため、更新を継続できません。" + Environment.NewLine +
                                "Windowsを再起動した後、手動での更新を試みてください。" + Environment.NewLine + 
                                "(エラーコード:00)",
                                "更新エラー",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            Application.Exit();
                        }
                    }
                }
                catch(ArgumentException)
                {
                    WriteLine("::プロセス情報を取得できません。Krileはすでに終了しています。");
                }
            }
            else
            {
                Write("(プロセスID不明)");
                MessageBox.Show(
                    "Krileを終了できないため、更新を継続できません。" + Environment.NewLine +
                    "Windowsを再起動した後、手動での更新を試みてください。" + Environment.NewLine + 
                    "(エラーコード:02)",
                    "更新エラー",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            var task = Task.Factory.StartNew(() =>
            {
                up.DoUpdate(ver);
                WriteLine("自動更新が完了しました!");
                WriteLine("Krileを再起動します。しばらくお待ちください...");
                System.IO.File.Create(Application.ExecutablePath + ".completed");
                System.Threading.Thread.Sleep(100);
                Application.Exit();
            });
        }
Exemplo n.º 2
0
 void p_Exited(object sender, EventArgs e)
 {
     var up = new UpdateProcessor(null);
     System.Diagnostics.Process.Start(Path.Combine(Application.StartupPath, up.GetCallbackFile()));
     Application.Exit();
 }