void _sparkle_updateDetected(object sender, UpdateDetectedEventArgs e) { DialogResult res = MessageBox.Show("Update detected, perform unattended", "Update", MessageBoxButtons.YesNoCancel); if (res == System.Windows.Forms.DialogResult.Yes) e.NextAction = nNextUpdateAction.performUpdateUnattended; else if (res == System.Windows.Forms.DialogResult.Cancel) e.NextAction = nNextUpdateAction.prohibitUpdate; else e.NextAction = nNextUpdateAction.showStandardUserInterface; }
/// <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) { NetSparkleConfiguration config = GetApplicationConfig(); // update profile information is needed UpdateSystemProfileInformation(config); // check if update is required NetSparkleAppCastItem latestVersion = null; 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); }
static void _sparkle_updateDetected(object sender, UpdateDetectedEventArgs e) { DialogResult res = MessageBox.Show("Update detected, perform unattended", "Update", MessageBoxButtons.YesNoCancel); switch (res) { case DialogResult.Yes: e.NextAction = NextUpdateAction.PerformUpdateUnattended; break; case DialogResult.Cancel: e.NextAction = NextUpdateAction.ProhibitUpdate; break; default: e.NextAction = NextUpdateAction.ShowStandardUserInterface; break; } }
/// <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..."); NetSparkleConfiguration 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 NetSparkleAppCastItem latestVersion = null; 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; else { // 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; continue; } } } while (goIntoLoop); // reset the islooping handle _loopingHandle.Reset(); }
/// <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) { NetSparkleConfiguration config = GetApplicationConfig(); // update profile information is needed UpdateSystemProfileInformation(config); // check if update is required NetSparkleAppCastItem latestVersion = null; 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; }
/// <summary> /// This method will be executed as worker thread /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _worker_DoWork(object sender, DoWorkEventArgs e) { // store the did run once feature Boolean goIntoLoop = true; Boolean checkTSP = true; Boolean doInitialCheck = _DoInitialCheck; Boolean 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..."); NetSparkleConfiguration 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 NetSparkleAppCastItem latestVersion = null; 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 = nNextUpdateAction.showStandardUserInterface, ApplicationConfig = config, LatestVersion = latestVersion }; if (updateDetected != null) { updateDetected(this, ev); } // check results switch (ev.NextAction) { case nNextUpdateAction.performUpdateUnattended: { ReportDiagnosticMessage("Unattended update whished from consumer"); EnableSilentMode = true; ReportProgress(1, latestVersion); break; } case nNextUpdateAction.prohibitUpdate: { ReportDiagnosticMessage("Update prohibited from consumer"); break; } case nNextUpdateAction.showStandardUserInterface: default: { ReportDiagnosticMessage("Standard UI update whished from consumer"); 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; } else { // 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; continue; } } } while (goIntoLoop); // reset the islooping handle _loopingHandle.Reset(); }