Exemplo n.º 1
0
        /// <summary>
        /// Does a one-off check for updates
        /// </summary>
        /// <param name="isUserInterfaceShown"><c>true</c> if the user interface is to be shown.</param>
        public bool CheckForUpdates(bool isUserInterfaceShown)
        {
            KryptonSparkleConfiguration config = GetApplicationConfig();

            // update profile information is needed
            UpdateSystemProfileInformation(config);

            // check if update is required
            KryptonSparkleAppCastItem latestVersion;

            if (IsUpdateRequired(config, out latestVersion))
            {
                // show the update window
                ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + latestVersion.Version);

                // send notification if needed
                UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs {
                    NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = latestVersion
                };
                if (UpdateDetected != null)
                {
                    UpdateDetected(this, ev);
                }

                // check results
                if (isUserInterfaceShown)
                {
                    switch (ev.NextAction)
                    {
                    case NextUpdateAction.PerformUpdateUnattended:
                        EnableSilentMode = true;
                        Update(latestVersion);
                        break;

                    case NextUpdateAction.ProhibitUpdate:
                        break;

                    case NextUpdateAction.ShowStandardUserInterface:
                    default:
                        Update(latestVersion);
                        break;
                    }
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method will be executed as worker thread
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            // store the did run once feature
            bool goIntoLoop     = true;
            bool checkTSP       = true;
            bool doInitialCheck = _DoInitialCheck;
            bool isInitialCheck = true;

            // start our lifecycles
            do
            {
                // set state
                Boolean bUpdateRequired = false;

                // notify
                if (CheckLoopStarted != null)
                {
                    CheckLoopStarted(this);
                }

                // report status
                if (doInitialCheck == false)
                {
                    ReportDiagnosticMessage("Initial check prohibited, going to wait");
                    doInitialCheck = true;
                    goto WaitSection;
                }

                // report status
                ReportDiagnosticMessage("Starting update loop...");

                // read the config
                ReportDiagnosticMessage("Reading config...");
                KryptonSparkleConfiguration config = GetApplicationConfig();

                // calc CheckTasp
                Boolean checkTSPInternal = checkTSP;

                if (isInitialCheck && checkTSPInternal)
                {
                    checkTSPInternal = !_ForceInitialCheck;
                }

                // check if it's ok the recheck to software state
                if (checkTSPInternal)
                {
                    TimeSpan csp = DateTime.Now - config.LastCheckTime;
                    if (csp < _CheckFrequency)
                    {
                        ReportDiagnosticMessage(String.Format("Update check performed within the last {0} minutes!", _CheckFrequency.TotalMinutes));
                        goto WaitSection;
                    }
                }
                else
                {
                    checkTSP = true;
                }

                // when sparkle will be deactivated wait an other cycle
                if (config.CheckForUpdate == false)
                {
                    ReportDiagnosticMessage("Check for updates disabled");
                    goto WaitSection;
                }

                // update the runonce feature
                goIntoLoop = !config.DidRunOnce;

                // update profile information is needed
                UpdateSystemProfileInformation(config);

                // check if update is required
                KryptonSparkleAppCastItem latestVersion;
                bUpdateRequired = IsUpdateRequired(config, out latestVersion);
                if (!bUpdateRequired)
                {
                    goto WaitSection;
                }

                // show the update window
                ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + latestVersion.Version);

                // send notification if needed
                UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs {
                    NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = latestVersion
                };
                if (UpdateDetected != null)
                {
                    UpdateDetected(this, ev);
                }

                // check results
                switch (ev.NextAction)
                {
                case NextUpdateAction.PerformUpdateUnattended:
                {
                    ReportDiagnosticMessage("Unattended update whished from consumer");
                    EnableSilentMode = true;
                    _worker.ReportProgress(1, latestVersion);
                    break;
                }

                case NextUpdateAction.ProhibitUpdate:
                {
                    ReportDiagnosticMessage("Update prohibited from consumer");
                    break;
                }

                case NextUpdateAction.ShowStandardUserInterface:
                default:
                {
                    ReportDiagnosticMessage("Standard UI update whished from consumer");
                    _worker.ReportProgress(1, latestVersion);
                    break;
                }
                }

WaitSection:
                // reset initialcheck
                isInitialCheck = false;

                // notify
                if (CheckLoopFinished != null)
                {
                    CheckLoopFinished(this, bUpdateRequired);
                }

                // report wait statement
                ReportDiagnosticMessage(String.Format("Sleeping for an other {0} minutes, exit event or force update check event", _CheckFrequency.TotalMinutes));

                // wait for
                if (!goIntoLoop)
                {
                    break;
                }

                // build the event array
                WaitHandle[] handles = new WaitHandle[1];
                handles[0] = _exitHandle;

                // wait for any
                int i = WaitHandle.WaitAny(handles, _CheckFrequency);
                if (WaitHandle.WaitTimeout == i)
                {
                    ReportDiagnosticMessage(String.Format("{0} minutes are over", _CheckFrequency.TotalMinutes));
                    continue;
                }

                // check the exit hadnle
                if (i == 0)
                {
                    ReportDiagnosticMessage("Got exit signal");
                    break;
                }

                // check an other check needed
                if (i == 1)
                {
                    ReportDiagnosticMessage("Got force update check signal");
                    checkTSP = false;
                }
            } while (goIntoLoop);

            // reset the islooping handle
            _loopingHandle.Reset();
        }