コード例 #1
0
ファイル: WnmpUpdater.cs プロジェクト: goodww1/wnmp
        /// <summary>
        /// Checks for updates
        /// </summary>
        public void CheckForUpdates()
        {
            updater.currentVersion = new Version(Application.ProductVersion);
            updater.updateInfoURL  = new Uri(Constants.UpdateXMLUrl);
            updater.SaveName       = Main.StartupPath + @"\Wnmp-Upgrade-Installer.exe";

            updater.CheckForUpdate();

            if (updater.UpdateAvailable)
            {
                UpdatePrompt updatePrompt = new UpdatePrompt();
                updatePrompt.StartPosition       = FormStartPosition.CenterParent;
                updatePrompt.currentversion.Text = updater.currentVersion.ToString();
                updatePrompt.newversion.Text     = updater.newVersion.ToString();
                if (updatePrompt.ShowDialog() == DialogResult.Yes)
                {
                    mainForm.Enabled = false;
                    updater.Update(UpdateCanceled, UpdateDownloaded);
                }
            }
            else
            {
                Log.wnmp_log_notice("Your version: " + updater.currentVersion + " is up to date.", Log.LogSection.WNMP_MAIN);
            }
        }
コード例 #2
0
        /// <summary>
        /// Checks for updates
        /// </summary>
        public static void CheckForUpdates(bool AutoUpdate)
        {
            if (!ReadUpdateXML())
            {
                return;
            }

            if (WNMP_VER.CompareTo(NEW_WNMP_VERSION) < 0)   // If it returns less than 0 than theres a new version
            {
                var CV = new UpdatePrompt();
                CV.StartPosition   = FormStartPosition.CenterScreen;
                CV.cversion.Text   = WNMP_VER.ToString();
                CV.newversion.Text = NEW_WNMP_VERSION.ToString();
                if (CV.ShowDialog() == DialogResult.Yes)
                {
                    DownloadWnmpUpdate(Wnmp_Upgrade_URL, UpdateExe);
                }
            }
            else
            {
                Log.wnmp_log_notice("Your version: " + WNMP_VER + " is up to date.", Log.LogSection.WNMP_MAIN);
            }

            if (AutoUpdate)
            {
                Options.settings.Lastcheckforupdate = DateTime.Now;
                Options.settings.UpdateSettings();
            }
        }
コード例 #3
0
ファイル: Updater.cs プロジェクト: liujianguang/wnmp
        /// <summary>
        /// Checks for updates
        /// </summary>
        public static void CheckForUpdates(bool AutoUpdate)
        {
            var FoundWnmpUpdate = false; // Since were checking for two updates we have to check if it found the main one.

            if (!ReadUpdateXML())
            {
                return;
            }

            if (WNMP_VER.CompareTo(NEW_WNMP_VERSION) < 0)   // If it returns less than 0 than theres a new version
            {
                FoundWnmpUpdate = true;
                var CV = new UpdatePrompt();
                CV.StartPosition   = FormStartPosition.CenterScreen;
                CV.cversion.Text   = WNMP_VER.ToString();
                CV.newversion.Text = NEW_WNMP_VERSION.ToString();
                if (CV.ShowDialog() == DialogResult.Yes)
                {
                    DownloadWnmpUpdate(Wnmp_Upgrade_URL, UpdateExe);
                }
            }
            else
            {
                Log.wnmp_log_notice("Your version: " + WNMP_VER + " is up to date.", Log.LogSection.WNMP_MAIN);
            }
            if (FoundWnmpUpdate != true)
            {
                if (Main.GetCPVER.CompareTo(NEW_CP_VERSION) < 0)
                {
                    var CV = new UpdatePrompt();
                    CV.StartPosition   = FormStartPosition.CenterScreen;
                    CV.cversion.Text   = Main.GetCPVER.ToString();
                    CV.newversion.Text = NEW_CP_VERSION.ToString();

                    if (CV.ShowDialog() == DialogResult.Yes)
                    {
                        DownloadCPUpdate(CP_UPDATE_URL, WNMP_NEW);
                    }
                }
                else
                {
                    Log.wnmp_log_notice("Your control panel version: " + Main.GetCPVER + " is up to date.", Log.LogSection.WNMP_MAIN);
                }
            }
            if (AutoUpdate)
            {
                Options.settings.Lastcheckforupdate = DateTime.Now;
                Options.settings.UpdateSettings();
            }
        }
コード例 #4
0
        private static void CheckForUpdates(UpdateCheckInfo info, bool auto)
        {
            try
            {
                if (!ApplicationDeployment.IsNetworkDeployed)
                {
                    if (!auto)
                    {
                        Popup.Show(
                            $"{Resources.AppName} was not installed via ClickOnce and cannot be updated automatically.",
                            image: MessageBoxImage.Error);
                    }
                    return;
                }

                if (info == null)
                {
                    if (!auto)
                    {
                        Popup.Show(
                            "An error occurred while trying to check for updates.", image: MessageBoxImage.Error);
                    }
                    return;
                }

                Settings.Default.LastUpdateCheck = DateTime.Now;
                if (info.UpdateAvailable && !(Settings.Default.UpdateBranch != UpdateBranch.Beta &&
                                              info.AvailableVersion.Minor == Settings.Default.BetaVersion) &&
                    !(AssemblyInfo.Version.Major != ForgetUpdateVersion.Major &&
                      ForgetUpdateVersion.Major == info.AvailableVersion.Major))
                {
                    if (auto && info.AvailableVersion == ForgetUpdateVersion)
                    {
                        return;
                    }
                    var ad = ApplicationDeployment.CurrentDeployment;
                    ad.UpdateCompleted += delegate
                    {
                        var args = new List <string>();
                        if (auto && Settings.Default.AutoUpdate)
                        {
                            args.Add("updatingsilent");
                        }
                        else
                        {
                            args.Add("updating");
                        }
                        AppHelper.RestartApplication(args);
                    };
                    if (auto && Settings.Default.AutoUpdate)
                    {
                        try
                        {
                            ad.UpdateAsync();
                        }
                        catch
                        {
                            // ignored
                        }
                        return;
                    }

                    if (auto)
                    {
                        if (Settings.Default.UpdateWaiting != info.AvailableVersion)
                        {
                            Settings.Default.UpdateWaiting = info.AvailableVersion;
                            TrayIconHelper.ShowBalloon(
                                $"Update available ({info.AvailableVersion})\nClick to view details",
                                BalloonIcon.Info);
                        }
                    }
                    else
                    {
                        App.UpdateScheduler?.Stop();

                        var updateDialog = new UpdatePrompt(info.AvailableVersion, info.IsUpdateRequired);
                        updateDialog.ShowDialog();
                        updateDialog.Activate();

                        switch (updateDialog.SelectedUpdateMode)
                        {
                        case UpdatePrompt.UpdateMode.RemindNever:
                            Settings.Default.ForgetUpdateVersion = info.AvailableVersion;
                            break;

                        case UpdatePrompt.UpdateMode.UpdateNow:
                            try
                            {
                                var progressDialog = new UpdateProgress(info.AvailableVersion);
                                ad.UpdateProgressChanged +=
                                    delegate(object sender, DeploymentProgressChangedEventArgs args)
                                {
                                    if (args.State == DeploymentProgressState.DownloadingApplicationFiles)
                                    {
                                        progressDialog.CurrentProgress = args.ProgressPercentage;
                                    }
                                };
                                progressDialog.Show();
                                progressDialog.Activate();
                                ad.UpdateAsync();
                            }
                            catch (DeploymentDownloadException dde)
                            {
                                Popup.Show(
                                    $"Failed to download the latest version.\nPlease check your network connection, or try again later.\n\nError: {dde}",
                                    image: MessageBoxImage.Error);
                            }
                            break;
                        }

                        App.UpdateScheduler?.Start();
                    }
                }
                else
                {
                    if (!auto)
                    {
                        Popup.Show($"You have the latest version ({AssemblyInfo.Version}).");
                    }
                }
            }
            catch (Exception)
            {
                if (!auto)
                {
                    throw;
                }
            }
        }
コード例 #5
0
        private static void CheckForUpdates(UpdateCheckInfo info, bool auto)
        {
            try
            {
                if (!ApplicationDeployment.IsNetworkDeployed)
                {
                    if (!auto)
                        Popup.Show(
                            "This application was not installed via ClickOnce and cannot be updated automatically.");
                    return;
                }

                if (info == null)
                {
                    if (!auto)
                        Popup.Show(
                            "An error occurred while trying to check for updates.", image: MessageBoxImage.Error);
                    return;
                }

                Settings.Default.LastUpdateCheck = DateTime.Now;
                if (info.UpdateAvailable && !(Settings.Default.UpdateBranch != UpdateBranch.Beta &&
                                              info.AvailableVersion.Minor == Settings.Default.BetaVersion) &&
                    !(AssemblyInfo.Version.Major != ForgetUpdateVersion.Major &&
                      ForgetUpdateVersion.Major == info.AvailableVersion.Major))
                {
                    if (auto && info.AvailableVersion == ForgetUpdateVersion)
                        return;
                    var ad = ApplicationDeployment.CurrentDeployment;
                    ad.UpdateCompleted += delegate
                    {
                        var args = new List<string>();
                        if (auto && Settings.Default.AutoUpdate)
                            args.Add("updatingsilent");
                        else
                            args.Add("updating");
                        AppHelper.RestartApplication(args);
                    };
                    if (auto && Settings.Default.AutoUpdate)
                    {
                        try
                        {
                            ad.UpdateAsync();
                        }
                        catch
                        {
                            // ignored
                        }
                        return;
                    }

                    if (auto)
                    {
                        if (Settings.Default.UpdateWaiting != info.AvailableVersion)
                        {
                            Settings.Default.UpdateWaiting = info.AvailableVersion;
                            TrayIconHelper.ShowBalloon(
                                $"Update available ({info.AvailableVersion})\nClick to view details",
                                BalloonIcon.Info);
                        }
                    }
                    else
                    {
                        App.UpdateScheduler?.Stop();

                        var updateDialog = new UpdatePrompt(info.AvailableVersion, info.IsUpdateRequired);
                        updateDialog.ShowDialog();
                        updateDialog.Activate();

                        switch (updateDialog.SelectedUpdateMode)
                        {
                            case UpdatePrompt.UpdateMode.RemindNever:
                                Settings.Default.ForgetUpdateVersion = info.AvailableVersion;
                                break;
                            case UpdatePrompt.UpdateMode.UpdateNow:
                                try
                                {
                                    var progressDialog = new UpdateProgress(info.AvailableVersion);
                                    ad.UpdateProgressChanged +=
                                        delegate(object sender, DeploymentProgressChangedEventArgs args)
                                        {
                                            if (args.State == DeploymentProgressState.DownloadingApplicationFiles)
                                                progressDialog.CurrentProgress = args.ProgressPercentage;
                                        };
                                    progressDialog.Show();
                                    progressDialog.Activate();
                                    ad.UpdateAsync();
                                }
                                catch (DeploymentDownloadException dde)
                                {
                                    Popup.Show(
                                        "Cannot download the latest version of this application.\n\nPlease check your network connection, or try again later.\n\nError: " +
                                        dde, image: MessageBoxImage.Error);
                                }
                                break;
                        }

                        App.UpdateScheduler?.Start();
                    }
                }
                else
                {
                    if (!auto)
                        Popup.Show(
                            $"You have the latest version ({AssemblyInfo.Version}).");
                }
            }
            catch (Exception)
            {
                if (!auto)
                    throw;
            }
        }