Ejemplo n.º 1
0
 private void OnError(string errorMessage)
 {
     if (SettingsManager.Instance.UseGUI)
     {
         // Disable proceed button.
         _differences.SetStateNext(false);
         // Show error message in gui.
         _differences.Status = errorMessage;
     }
     else if (SettingsManager.Instance.ShowProgress)
     {
         _progressScreenViewModel.ShowError(errorMessage);
     }
     else
     {
         // Write erro message to log.
         WriteLog(errorMessage);
     }
 }
Ejemplo n.º 2
0
        private void StartUpdate()
        {
            WriteLog(Strings.MESSAGE_START_UPDATE);

            // Instantiate gui.
            _differences = new Diff();
            _progress    = new Progress();

            // Continue update.
            SettingsManager.Instance.ContinueUpdate = false;

            // If used, set gui to initial state and register events.
            if (SettingsManager.Instance.UseGUI)
            {
                _differences.Next          += DifferencesNext;
                _differences.Finish        += DifferencesFinish;
                _differences.Cancel        += DifferencesCancel;
                _differences.ProductName    = Strings.LOADING;
                _differences.CurrentVersion = Strings.LOADING;
                _differences.NewVersion     = Strings.LOADING;
                _differences.ChangedFiles   = Strings.LOADING;
                _differences.Show();

                _progress.Cancel += ProgressCancel;
                _progress.Finish += ProgressFinish;
            }
            if (SettingsManager.Instance.ShowProgress)
            {
                _progressScreenViewModel = new ProgressScreenViewModel();
                _progressScreenViewModel.AcknowledgeError += ProgressScreenViewModelAcknowledgeError;
                _progressScreen             = new ProgressScreen();
                _progressScreen.DataContext = _progressScreenViewModel;
                _progressScreenViewModel.ShowProgress();
                _progressScreen.Show();
            }

            // Get VersionManger instance.
            _verManager = VersionsManager.Instance;

            /**
             * Get local information.
             */

            WriteLog(Strings.MESSAGE_AQUIRE_LOCAL_INFORMATION);
            // Get local version information.
            _verManager.GetLocalData();

            // If an error occours during local information gathering discontinue update
            if (!SettingsManager.Instance.ContinueUpdate && SettingsManager.Instance.ErrorPosition == ErrorPosition.Localinformation)
            {
                OnError(Strings.ERROR_GET_LOCAL);
            }

            // If update continues and gui is in use set current version and product name.
            if (SettingsManager.Instance.ContinueUpdate)
            {
                if (SettingsManager.Instance.UseGUI)
                {
                    _differences.CurrentVersion = _verManager.LocalInformation.CurrentVersion.ToString();
                    _differences.ProductName    = _verManager.LocalInformation.ProductName;
                }
            }

            /**
             * Get remote overview.
             */

            // If update continues get overview.
            if (SettingsManager.Instance.ContinueUpdate)
            {
                WriteLog(Strings.MESSAGE_AQUIRE_REMOTE_OVERIEW);
                _verManager.GetOverview();
            }

            // If fetching remote overview failed cancel information gathering and discontinue.
            if (!SettingsManager.Instance.ContinueUpdate && SettingsManager.Instance.ErrorPosition == ErrorPosition.Overview)
            {
                OnError(Strings.ERROR_GET_OVERVIEW);
            }

            // If update continues and gu is in use, set newest avaiable version number.
            if (SettingsManager.Instance.ContinueUpdate)
            {
                if (SettingsManager.Instance.UseGUI)
                {
                    _differences.NewVersion = _verManager.Overview.Versions[_verManager.Overview.Versions.Count - 1].ToString();
                }
            }

            /**
             * Get remote version information.
             */

            // If update continues get all remote versions from newest down to current local version.
            if (SettingsManager.Instance.ContinueUpdate)
            {
                if (VersionsManager.Instance.LocalInformation.CurrentVersion.ToString()
                    != VersionsManager.Instance.Overview.Versions[VersionsManager.Instance.Overview.Versions.Count - 1].ToString())
                {
                    WriteLog(Strings.MESSAGE_AQUIRE_REMOTE_INFORMATION);
                    _verManager.GetVersions(_verManager.Overview.Versions[_verManager.Overview.Versions.Count - 1].ToString());
                }
                else
                {
                    SettingsManager.Instance.NoNewVersions = true;
                    WriteLog(Strings.MESSAGE_NO_NEW_VERSION);
                }
            }

            // If error occours during version fetching cancel information gathering and discontinue.
            if (!SettingsManager.Instance.ContinueUpdate && SettingsManager.Instance.ErrorPosition == ErrorPosition.Remoteinformation)
            {
                OnError(Strings.ERROR_GET_VERSIONS);
            }

            // If update continues and gui is in use set number of files that will be changed during update or inform about no new version.
            if (SettingsManager.Instance.ContinueUpdate)
            {
                if (SettingsManager.Instance.UseGUI)
                {
                    if (SettingsManager.Instance.NoNewVersions)
                    {
                        _differences.ChangedFiles = Strings.NO_NEW_VERSION;
                    }
                    else
                    {
                        _differences.ChangedFiles = _verManager.RemoteVersions[0].Files.Count.ToString();
                    }
                }
            }

            /**
             * Enable next step in update process
             */
            if ((!SettingsManager.Instance.UseGUI && !SettingsManager.Instance.ShowProgress) && SettingsManager.Instance.ContinueUpdate &&
                !SettingsManager.Instance.NoNewVersions)
            {
                _updateResult = _userv.StartUpdate();
                EndUpdate();
            }
            else if (SettingsManager.Instance.ContinueUpdate && !SettingsManager.Instance.NoNewVersions &&
                     SettingsManager.Instance.ShowProgress)
            {
                _updateResult = _userv.StartUpdate();
                EndUpdate();
            }
            else if (SettingsManager.Instance.ContinueUpdate && !SettingsManager.Instance.NoNewVersions &&
                     SettingsManager.Instance.UseGUI)
            {
                _differences.SetStateNext(true);
            }
            else if (SettingsManager.Instance.NoNewVersions)
            {
                _userv.DeleteLocalInformations();
                EndUpdate();
            }
        }