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 = NextUpdateAction.PerformUpdateUnattended; else if (res == System.Windows.Forms.DialogResult.Cancel) e.NextAction = NextUpdateAction.ProhibitUpdate; else e.NextAction = NextUpdateAction.ShowStandardUserInterface; }
#pragma warning restore 1591 /// <summary> /// Does a one-off check for updates /// </summary> /// <param name="useNotificationToast">set false if you want the big dialog to open up, without the user having the chance to ignore the popup toast notification</param> private UpdateStatus CheckForUpdates(bool useNotificationToast) { NetSparkleConfiguration config = GetApplicationConfig(); // update profile information is needed UpdateSystemProfileInformation(config); // check if update is required NetSparkleAppCastItem[] updates; var updateStatus = GetUpdateStatus(config, out updates); if (updateStatus == UpdateStatus.UpdateAvailable) { // show the update window ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + updates[0].Version); UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs { NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = updates[0] }; // if the client wants to intercept, send an event if (UpdateDetected != null) { UpdateDetected(this, ev); } //otherwise just go forward with the UI notficiation else { ShowUpdateNeededUI(updates, useNotificationToast); } } return(updateStatus); }
/// <summary> /// This method will be executed as worker thread /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private 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[] updates; bUpdateRequired = GetUpdateStatus(config, out updates) == UpdateStatus.UpdateAvailable; if (!bUpdateRequired) { goto WaitSection; } // show the update window ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + updates[0].Version); // send notification if needed UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs { NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = updates[0] }; 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, updates); break; } case NextUpdateAction.ProhibitUpdate: { ReportDiagnosticMessage("Update prohibited from consumer"); break; } default: { ReportDiagnosticMessage("Showing Standard Update UI"); _worker.ReportProgress(1, updates); 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(); }
/// <summary> /// This method will be executed as worker thread /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private 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[] updates; bUpdateRequired = GetUpdateStatus(config, out updates) == UpdateStatus.UpdateAvailable; if (!bUpdateRequired) goto WaitSection; // show the update window ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + updates[0].Version); // send notification if needed UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs { NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = updates[0] }; 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, updates); break; } case NextUpdateAction.ProhibitUpdate: { ReportDiagnosticMessage("Update prohibited from consumer"); break; } default: { ReportDiagnosticMessage("Showing Standard Update UI"); _worker.ReportProgress(1, updates); 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(); }
#pragma warning restore 1591 /// <summary> /// Does a one-off check for updates /// </summary> /// <param name="useNotificationToast">set false if you want the big dialog to open up, without the user having the chance to ignore the popup toast notification</param> private UpdateStatus CheckForUpdates(bool useNotificationToast) { NetSparkleConfiguration config = GetApplicationConfig(); // update profile information is needed UpdateSystemProfileInformation(config); // check if update is required NetSparkleAppCastItem[] updates; var updateStatus = GetUpdateStatus(config, out updates); if (updateStatus == UpdateStatus.UpdateAvailable) { // show the update window ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + updates[0].Version); UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs { NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = updates[0] }; // if the client wants to intercept, send an event if (UpdateDetected != null) { UpdateDetected(this, ev); } //otherwise just go forward with the UI notficiation else { ShowUpdateNeededUI(updates); } } return updateStatus; }
private static void OnSparkleOnUpdateDetectedShowWithToast(object sender, UpdateDetectedEventArgs args) { Startup.UpdateDetected = true; _sparkle.ShowUpdateNeededUI(args.LatestVersion, true); }
/// <summary> /// Does a one-off check for updates /// </summary> /// <param name="useNotificationToast">set false if you want the big dialog to open up, without the user having the chance to ignore the popup toast notification</param> private async Task<SparkleUpdateInfo> CheckForUpdates(bool useNotificationToast) { if (UpdateCheckStarted != null) UpdateCheckStarted(this); NetSparkleConfiguration config = GetApplicationConfig(); // update profile information is needed UpdateSystemProfileInformation(config); // check if update is required SparkleUpdateInfo updateStatus = await GetUpdateStatus(config); NetSparkleAppCastItem[] updates = updateStatus.Updates; if (updateStatus.Status == UpdateStatus.UpdateAvailable) { // show the update window ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + updates[0].Version); UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs { NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = updates[0] }; // if the client wants to intercept, send an event if (UpdateDetected != null) { UpdateDetected(this, ev); // if the client wants the default UI then show them switch (ev.NextAction) { case NextUpdateAction.ShowStandardUserInterface: ReportDiagnosticMessage("Showing Standard Update UI"); OnWorkerProgressChanged(_taskWorker, new ProgressChangedEventArgs(1, updates)); break; } } else { // otherwise just go forward with the UI notification ShowUpdateNeededUI(updates); } } UpdateCheckFinished?.Invoke(this, updateStatus.Status); return updateStatus; }