private void DoCheckForUpdate(bool skipIfPeriodNotElapsed, bool fireErrorEvent, bool fireNotFoundEvent) { OnUpdateCheckStarted(); UpdatesHistoryInfo updatesHistoryInfo = UpdatesHistoryInfo.LoadFromFile(Path.Combine(this.settings.ProductPathToStoreHistoryInfo, "SoftwareUpdateHistory.xml"), XmlSerializableFileCorruptedAction.LoadDefaultsSilently); try { if (skipIfPeriodNotElapsed && (updatesHistoryInfo.LastUpdateCheck + settings.UpdateCheckPeriod > DateTime.Now)) { return; } updatesHistoryInfo.LastUpdateCheck = DateTime.Now; string tmpPath = Path.Combine(Path.Combine(Path.GetTempPath(), "Scarfsail.SoftwareUpdates"), Guid.NewGuid().ToString()); if (!Directory.Exists(tmpPath)) { Directory.CreateDirectory(tmpPath); } //Download definition xml file string definitionXmlFileName = Path.Combine(tmpPath, "Definition.xml"); if (File.Exists(definitionXmlFileName)) { File.Delete(definitionXmlFileName); } using (WebClient webClient = new WebClient()) { webClient.DownloadFile(settings.RemoteDefinitionXmlUrl + String.Format("?Version={0}&ForceCheck={1}", settings.ProductVersion, !skipIfPeriodNotElapsed), definitionXmlFileName); } UpdateDefinitionXml updateDefinitionXml = UpdateDefinitionXml.LoadFromFile(definitionXmlFileName, XmlSerializableFileCorruptedAction.LoadDefaultsSilently); if (updateDefinitionXml.LatestVersion.Version > settings.ProductVersion) { updatesHistoryInfo.LastUpdateFound = DateTime.Now; OnUpdateFound(new UpdateFoundEventArgs(updateDefinitionXml, settings.ProductVersion, tmpPath)); } else { if (fireNotFoundEvent) { this.OnUpdateNotFound(skipIfPeriodNotElapsed); } } } catch (WebException ex) { UpdateErrorHandler(ex.InnerException != null ? ex.InnerException.Message : ex.Message, updatesHistoryInfo, fireErrorEvent, skipIfPeriodNotElapsed); } catch (Exception ex) { UpdateErrorHandler(ex.Message, updatesHistoryInfo, fireErrorEvent, skipIfPeriodNotElapsed); } finally { updatesHistoryInfo.Save(); OnUpdateCheckFinished(); } }
internal UpdateFoundEventArgs(UpdateDefinitionXml updateDefinitionXml, Version currentVersion, string tmpPath) { this.updateDefinition = updateDefinitionXml; this.CurrentVersion = currentVersion; this.tmpPath = tmpPath; }