Ejemplo n.º 1
0
        private void AutoUpdate()
        {
            AutoUpdateCheck checker = new AutoUpdateCheck(AppDomain.CurrentDomain.BaseDirectory,
                Globals.EMMAUpdateServer, Properties.Settings.Default.BetaUpdates);
            if (checker.UpdateNeeded)
            {
                checker.ShowDialog();
            }
            else
            {
                checker = null;
            }

            /*if (!Globals.EMMAUpdateServer.Equals(""))
            {
                string exeFile = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "AutoUpdater.exe";
                if (File.Exists(exeFile))
                {
                    string tmpDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                        Path.DirectorySeparatorChar + "EMMA";
                    string exeTmp = tmpDir + Path.DirectorySeparatorChar + "AutoUpdater.exe";
                    if (Directory.Exists(tmpDir))
                    {
                        Directory.Delete(tmpDir, true);
                    }
                    Directory.CreateDirectory(tmpDir);
                    File.Copy(exeFile, exeTmp);

                    string parameters = "/p " + System.Diagnostics.Process.GetCurrentProcess().Id +
                        " /s " + Globals.EMMAUpdateServer +
                        " /b " + Properties.Settings.Default.BetaUpdates.ToString() +
                        " /h \"" + AppDomain.CurrentDomain.BaseDirectory + "\"";
                    try
                    {
                        System.Diagnostics.Process updateProcess = System.Diagnostics.Process.Start(exeTmp, parameters);
                        while (!updateProcess.HasExited) { }
                    }
                    catch (Win32Exception ex)
                    {
                        if (ex.Message.Contains("The operation was canceled by the user"))
                        {
                            // If this happens then we just ignore it and continue.
                            // The user has cancelled the auto-update program for some reason
                            // (e.g. does not want to give the program admin rights on vista)
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Auto-updater cannot be found. EMMA will not be updated when new features " +
                        "become available.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }*/
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            AutoUpdateCheck checker = new AutoUpdateCheck(AppDomain.CurrentDomain.BaseDirectory,
                Globals.EMMAUpdateServer, Properties.Settings.Default.BetaUpdates);
            if (checker.UpdateNeeded)
            {
                checker.ShowDialog();
            }
            else
            {
                MessageBox.Show("No updates are currently available.", "Notification",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            /*if (!_main.CheckForUpdatesInProg())
            {
                if (MessageBox.Show("Running the updater will cause EMMA to close if updates are available." +
                    "Are you sure you wish to continue?", "Warning", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    string exeFile = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "AutoUpdater.exe";
                    if (File.Exists(exeFile))
                    {
                        string tmpDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                            Path.DirectorySeparatorChar + "EMMA";
                        string exeTmp = tmpDir + Path.DirectorySeparatorChar + "AutoUpdater.exe";
                        if (Directory.Exists(tmpDir))
                        {
                            Directory.Delete(tmpDir, true);
                        }
                        Directory.CreateDirectory(tmpDir);
                        File.Copy(exeFile, exeTmp);

                        string parameters = "/p " + System.Diagnostics.Process.GetCurrentProcess().Id +
                            " /s " + Globals.EMMAUpdateServer +
                            " /b " + Properties.Settings.Default.BetaUpdates.ToString() +
                            " /h \"" + AppDomain.CurrentDomain.BaseDirectory + "\"";
                        System.Diagnostics.Process updateProcess = System.Diagnostics.Process.Start(exeTmp, parameters);
                        while (!updateProcess.HasExited) { }

                        MessageBox.Show("No updates are currently available.", "Notification",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Updater program cannot be found.", "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }*/
        }