Exemple #1
0
        void LoadClientServerFile()
        {
            // load the self server file if it doesn't already exist
            if (SelfServerFile == null)
            {
                SelfServerFile = ServerFile.Load(clientSFLoc, updatePathVar, customUrlArgs);
            }

            updateFrom = SelfServerFile.GetVersionChoice(VersionTools.FromExecutingAssembly());
        }
Exemple #2
0
        /// <summary>
        /// Called when the self-update server files has downloaded successfully.
        /// </summary>
        void DownloadClientSFSuccess()
        {
            // load the wyUpdate server file, and see if a new version is availiable
            ServerFile clientSF = ServerFile.Load(clientSFLoc, updatePathVar, customUrlArgs);

            // check if the wyUpdate is new enough.
            if (VersionTools.Compare(VersionTools.FromExecutingAssembly(), clientSF.NewVersion) < 0)
            {
                SelfUpdateState = SelfUpdateState.WillUpdate;

                // autoupdate will need this SF
                if (isAutoUpdateMode)
                {
                    SelfServerFile = clientSF;
                    LoadClientServerFile();
                }
            }

            // Show update info page (or just start downloading & installing)
            if (SkipUpdateInfo)
            {
                // check if elevation is needed
                needElevation = NeedElevationToUpdate();

                if (needElevation || SelfUpdateState == SelfUpdateState.WillUpdate)
                {
                    StartSelfElevated();
                }
                else
                {
                    ShowFrame(Frame.InstallUpdates);
                }
            }
            else
            {
                ShowFrame(Frame.UpdateInfo);
            }
        }
        void SelfUpdateProgress(int percentDone, int unweightedPercent, string extraStatus, ProgressStatus status, Object payload)
        {
            if (IsDisposed)
            {
                return;
            }

            //update progress bar
            if (percentDone > -1 && percentDone < 101)
            {
                panelDisplaying.Progress = percentDone;
            }

            //update bottom status
            if (!string.IsNullOrEmpty(extraStatus) && extraStatus != panelDisplaying.ProgressStatus)
            {
                panelDisplaying.ProgressStatus = extraStatus;
            }

            if (installUpdate != null && (status == ProgressStatus.Success || status == ProgressStatus.Failure))
            {
                installUpdate.ProgressChanged -= SelfUpdateProgress;
            }

            if (status == ProgressStatus.Success)
            {
                if (frameOn == Frame.Checking)
                {
                    clientSFLoc = downloader.DownloadingTo;

                    try
                    {
                        // client server file downloaded sucessfully
                        DownloadClientSFSuccess();
                    }
                    catch (Exception e)
                    {
                        //error occured, show error screen
                        status  = ProgressStatus.Failure;
                        payload = e;
                    }
                }
                else
                {
                    switch (update.CurrentlyUpdating)
                    {
                    case UpdateOn.DownloadingSelfUpdate:

                        //set the filename of the downloaded client update file
                        updateFilename = downloader.DownloadingTo;

                        if (isAutoUpdateMode)
                        {
                            SelfUpdateState = SelfUpdateState.Downloaded;

                            // save autoupdate file (new selfupdate state is saved)
                            SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable);

                            // begin extracting self
                            update.CurrentlyUpdating = UpdateOn.ExtractSelfUpdate;
                            InstallUpdates(update.CurrentlyUpdating);
                        }
                        else     // regular self update mode
                        {
                            panelDisplaying.UpdateItems[0].Status = UpdateItemStatus.Success;

                            //begin extracting and installing the update
                            update.CurrentlyUpdating = UpdateOn.FullSelfUpdate;
                            InstallUpdates(update.CurrentlyUpdating);
                        }

                        break;

                    case UpdateOn.FullSelfUpdate:

                        panelDisplaying.UpdateItems[1].Status = UpdateItemStatus.Success;

                        //start the newly installed client and resume "normal" downloading & updating
                        StartSelfElevated();
                        break;

                    case UpdateOn.ExtractSelfUpdate:

                        SelfUpdateState = SelfUpdateState.Extracted;

                        // oldSelfLocation already set in the InstallUpdates(ExtractSelfUpdate)
                        newSelfLocation = installUpdate.NewSelfLoc;

                        // save autoupdate file (new selfupdate state is saved)
                        SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable);

                        // start the new client
                        StartNewSelfAndClose();

                        return;

                    case UpdateOn.InstallSelfUpdate:

                        SelfUpdateState = SelfUpdateState.None;

                        // save autoupdate file (new selfupdate state is saved)
                        SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateReadyToInstall);

                        // we must set new self to false because it's used in StartSelfElevated()
                        // to set the /ns argument for the newly launched wyUpdate
                        IsNewSelf = false;

                        // relaunch newly installed self to do regular update
                        StartSelfElevated();

                        return;
                    }
                }
            }


            if (status == ProgressStatus.Failure)
            {
                bool selfUpdateRequired =
                    VersionTools.Compare(VersionTools.FromExecutingAssembly(), ServerFile.MinClientVersion) < 0;

                bool canTryCatchAllUpdate = frameOn != Frame.Checking

                                            // patch failed
                                            && payload.GetType() == typeof(PatchApplicationException)

                                            // if the catch-all update isn't the one that failed
                                            && updateFrom != SelfServerFile.VersionChoices[SelfServerFile.VersionChoices.Count - 1]

                                            // and there is a catch-all update
                                            && SelfServerFile.VersionChoices[SelfServerFile.VersionChoices.Count - 1].Version == SelfServerFile.NewVersion;


                // if a new client is *required* to install the update...
                if (selfUpdateRequired && !canTryCatchAllUpdate)
                {
                    //show an error and bail out
                    error        = clientLang.SelfUpdateInstallError;
                    errorDetails = ((Exception)payload).Message;

                    ShowFrame(Frame.Error);
                }
                else if (frameOn == Frame.Checking)
                {
                    // client server file failed to download, continue as usual:
                    SelfUpdateState = SelfUpdateState.None;

                    // Show update info page (or just start downloading & installing)
                    if (SkipUpdateInfo)
                    {
                        // check if elevation is needed
                        needElevation = NeedElevationToUpdate();

                        if (needElevation)
                        {
                            StartSelfElevated();
                        }
                        else
                        {
                            ShowFrame(Frame.InstallUpdates);
                        }
                    }
                    else
                    {
                        ShowFrame(Frame.UpdateInfo);
                    }
                }
                else
                {
                    if (canTryCatchAllUpdate)
                    {
                        // select the catch all update
                        updateFrom = SelfServerFile.VersionChoices[SelfServerFile.VersionChoices.Count - 1];

                        // clear errors
                        error        = null;
                        errorDetails = null;

                        panelDisplaying.UpdateItems[1].Status = UpdateItemStatus.Nothing;

                        if (isAutoUpdateMode)
                        {
                            // change update state from Downloaded to WillUpdate (just autoupdate)
                            SelfUpdateState = SelfUpdateState.WillUpdate;

                            // save the fact that there's no longer an update file
                            SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable);
                        }

                        // download the catch-all update
                        DownloadUpdate();

                        return;
                    }


                    if (isAutoUpdateMode)
                    {
                        SelfUpdateState = SelfUpdateState.None;

                        if (update.CurrentlyUpdating == UpdateOn.InstallSelfUpdate)
                        {
                            // update has already been downloaded & extracted
                            SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateReadyToInstall);

                            UpdateHelper_RequestReceived(this, UpdateAction.UpdateStep, UpdateStep.Install);
                        }
                        else
                        {
                            // update hasn't been downloaded yet
                            SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable);

                            UpdateHelper_RequestReceived(this, UpdateAction.UpdateStep, UpdateStep.DownloadUpdate);
                        }
                    }
                    else
                    {
                        //self-update failed to download or install
                        //just relaunch old client and continue with update
                        StartSelfElevated();
                    }
                }
            }
        }