Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
#if(!DEBUG)
            Application.ThreadException += UnhandledExceptionsCatch;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
#endif

            // Check for an update command in the command line arguments.
            if (args.Length != 0)
            {
                int oldPID = 0;
                string oldVersion = "";
                switch (args[0])
                {
                    case "/update":
                        if (args.Length != 3) break;
                        try
                        {
                            oldPID = Convert.ToInt32(args[1]);
                            oldVersion = args[2];
                            try
                            {
                                Process p = Process.GetProcessById(oldPID);
                                DateTime hardStop = DateTime.Now.AddSeconds(2);
                                while (!p.HasExited && DateTime.Now < hardStop)
                                    Thread.Sleep(100);
                                if (!p.HasExited) p.Kill();
                            }
                            catch
                            {
                            }
                            string target = Path.Combine(BasePath, BaseFilename);
                            File.Delete(target);
                            File.Copy(Application.ExecutablePath, target);
                            Process.Start(target, "/flush " + Process.GetCurrentProcess().Id.ToString() + " " +
                                                  oldVersion + " " + Path.GetFileName(Application.ExecutablePath));
                            return;
                        }
                        catch
                        {
                            // Do nothing, just exit out as we're basically ignoring the command line here.
                        }
                        break;

                    case "/flush":
                        if (args.Length != 4) break;
                        try
                        {
                            oldPID = Convert.ToInt32(args[1]);
                            oldVersion = args[2];
                            var oldVer = new Version(oldVersion);
                            string updaterName = args[3];
                            try
                            {
                                Process p = Process.GetProcessById(oldPID);
                                DateTime hardStop = DateTime.Now.AddSeconds(2);
                                while (!p.HasExited && DateTime.Now < hardStop)
                                    Thread.Sleep(100);
                                if (!p.HasExited) p.Kill();
                            }
                            catch
                            {
                            }
                            File.Delete(Path.Combine(BasePath, updaterName));

                            // Perform any upgrades to the data files, if necessary.
                            Upgrades.PerformUpgrades(new Version(oldVersion));

                            var dialog = new frmUpdated(oldVer);
                            dialog.ShowDialog();
                            dialog.Close();
                        }
                        catch
                        {
                            // Do nothing, just exit out as we're basically ignoring the command line here.
                        }
                        break;
                }
            }

            var splash = new frmSplash();
            splash.FormClosed += SplashClosed;
            splash.Show();

            DateTime done = DateTime.Now.AddSeconds(3);
            while (done > DateTime.Now && !HasClosed)
            {
                Thread.Sleep(50);
                Application.DoEvents();
            }
            splash.Close();

            Application.Run(new FrmManager());
        }
 private void viewChangeLogToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var dialog = new frmUpdated(null);
     dialog.ShowDialog();
     dialog.Close();
 }