Esempio n. 1
0
        private bool CompareVersions(MUpdateXml update, bool notificateNoUpdates = true)
        {
            if (update != null && update.IsNewerThan(applicationInfo.ApplicationAssembly.GetName().Version))                          // If the update is not null and the version is newer than the current one
            {
                if (new MUpdateAcceptForm(this.applicationInfo, update).ShowDialog(this.applicationInfo.Context) == DialogResult.Yes) // If user accepts to do the update now
                {
                    DownloadUpdate(update);                                                                                           // Download update
                }

                CheckedAlreadyUpToDate = false;
                return(true);
            }
            else if (update != null && update.Version <= applicationInfo.ApplicationAssembly.GetName().Version)
            {
                if (notificateNoUpdates)
                {
                    MessageBox.Show(lang.latestVersionInstalledLbl + " " + applicationInfo.ApplicationAssembly.GetName().Version.ToString(),
                                    applicationInfo.ApplicationName + " - " + lang.updateChecking,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                CheckedAlreadyUpToDate = true;
            }
            else
            {
                CheckedAlreadyUpToDate = false;
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// <para>Launch the update process and wait for answer.</para>
        /// <para>Better wrap this function in a Try-Catch block or it may fail the calling application (e.g. internet connection problems).</para>
        /// <para>Returns True if updated successfully, False if no updates are available; throws Exception if error (e.g. no internet connection).<br/>
        /// If user already have last version installed, returns false because no updates were made. Use CheckedAlreadyUpToDate property.</para>
        /// </summary>
        /// <param name="notificateNoUpdates">If false, do not show message box saying 'You already have the latest version'.</param>
        /// <returns>True if updated successfully, False if not updated, Exception if error (e.g. no internet connection)</returns>
        public bool DoUpdateSync(bool notificateNoUpdates = true)
        {
            if (!Tools.CheckForInternetConnection())
            {
                throw new WebException(lang.noInternetConnectionError, WebExceptionStatus.ConnectFailure);
            }

            if (MUpdateXml.ExistsOnServer(applicationInfo.UpdateXmlLocation)) // Si le fichier de mise à jour existe
            {
                return(CompareVersions(MUpdateXml.Parse(applicationInfo.UpdateXmlLocation, applicationInfo.ApplicationID),
                                       notificateNoUpdates)); // Retourne si une nouvelle mise à jour est disponible et demande à l'utilisateur ce qu'il souhaite faire.
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Parses data from update.xml located on the specified Uri
        /// </summary>
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!Tools.CheckForInternetConnection())
            {
                throw new WebException(lang.noInternetConnectionError, WebExceptionStatus.ConnectFailure);
            }

            IMUpdatable application = (IMUpdatable)e.Argument;

            if (!MUpdateXml.ExistsOnServer(application.UpdateXmlLocation))
            {
                e.Cancel = true;
            }
            else
            {
                e.Result = MUpdateXml.Parse(application.UpdateXmlLocation, application.ApplicationID);
            }
        }
Esempio n. 4
0
        public MUpdateAcceptForm(IMUpdatable applicationInfo, MUpdateXml updateInfo)
        {
            InitializeComponent();

            this.applicationInfo = applicationInfo;
            this.updateInfo      = updateInfo;

            this.Text            = lang.updateAvailable;
            this.lblAppName.Text = this.applicationInfo.ApplicationName;

            if (this.applicationInfo.ApplicationIcon != null)
            {
                this.Icon = this.applicationInfo.ApplicationIcon;
            }

            this.lblUpdateAvailTitle.Text = lang.updateAvailable + ": " + this.updateInfo.Version.ToString();
            //this.lblUpdaVers.Text = string.Format(lang.updateVersion + ": {0}", this.updateInfo.Version.ToString());

            //this.lblCurrVers.Text = string.Format(lang.currentVersion + ": {0}", this.applicationInfo.ApplicationAssembly.GetName().Version.ToString());

            this.txtDetails.Text = makeNewLines(this.updateInfo.Description);
        }
Esempio n. 5
0
        /// <summary>
        /// When bgWorker finished parsing dats from update.xml
        /// </summary>
        private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!e.Cancelled && e.Error == null)               // If no errors were reported
            {
                MUpdateXml update = (MUpdateXml)e.Result;      // Gets the result sent as argument

                bool updated = CompareVersions(update, false); // Compare and finish

                MUpdateEventBridge.RaiseAsyncUpdateFinished(updated, (!updated && CheckedAlreadyUpToDate) ? new Exception(lang.latestVersionInstalled) : null);
            }
            else // If an error was reported
            {
                if (e.Error == null)
                {
                    MUpdateEventBridge.RaiseAsyncUpdateFinished(false, new Exception(lang.checkError));
                }
                else
                {
                    MUpdateEventBridge.RaiseAsyncUpdateFinished(false, e.Error);
                }
            }
        }
Esempio n. 6
0
        private void DownloadUpdate(MUpdateXml update)
        {
            MUpdateDownloadForm form = new MUpdateDownloadForm(update.Uri, update.MD5, this.applicationInfo.ApplicationIcon, this.applicationInfo.ApplicationName); // Initialze a new Download form
            DialogResult        res  = form.ShowDialog(this.applicationInfo.Context);                                                                               //Show it by getting the dialog result

            if (res == DialogResult.OK)
            {
                string currentPath = this.applicationInfo.ApplicationAssembly.Location; // Get current path
                string newPath     = Path.GetDirectoryName(currentPath) + "\\" + update.FileName;

                if (!update.IsInstaller)
                {
                    UpdateStandalone(form.TempFilePath, currentPath, newPath, update.LaunchArgs); // Launch cmd
                }
                else
                {
                    LaunchInstaller(form.TempFilePath, update.LaunchArgs);
                }

                Application.Exit();
            }
            else if (res == DialogResult.Abort)
            {
                MessageBox.Show(lang.downloadCancelled,
                                lang.downloadCancelledTitle,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }
            else
            {
                MessageBox.Show(lang.downloadError,
                                lang.downloadErrorTitle,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }