From c56b95e78a4db3963eb58c1bc77808e7e132b14e Mon Sep 17 00:00:00 2001 From: jesse Date: Tue, 3 Sep 2019 13:46:57 -0700 Subject: [PATCH] Added log message event. Added silent mode to prevent dialogs that require user interaction. --- AutoUpdater.NET/AutoUpdater.NET.csproj | 13 +- AutoUpdater.NET/AutoUpdater.cs | 499 +++++++++++++----- AutoUpdater.NET/DownloadUpdateDialog.cs | 59 ++- .../Properties/Resources.Designer.cs | 2 +- ZipExtractor/ZipExtractor.csproj | 296 +++++------ 5 files changed, 560 insertions(+), 309 deletions(-) diff --git a/AutoUpdater.NET/AutoUpdater.NET.csproj b/AutoUpdater.NET/AutoUpdater.NET.csproj index 08b89ad0..b3a2df1d 100644 --- a/AutoUpdater.NET/AutoUpdater.NET.csproj +++ b/AutoUpdater.NET/AutoUpdater.NET.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -36,34 +36,41 @@ v2.0 bin\Debug\net20 bin\Debug\net20\AutoUpdater.NET.XML + TRACE;DEBUG + false v2.0 build\lib\net20 build\lib\net20\AutoUpdater.NET.XML + false v3.5 bin\Debug\net35 bin\Debug\net35\AutoUpdater.NET.XML + false v3.5 build\lib\net35 build\lib\net35\AutoUpdater.NET.XML + false v4.0 bin\Debug\net40 bin\Debug\net40\AutoUpdater.NET.XML + false - v4.0 + v4.7.2 build\lib\net40 build\lib\net40\AutoUpdater.NET.XML + false - true + false AutoUpdater.NET.snk diff --git a/AutoUpdater.NET/AutoUpdater.cs b/AutoUpdater.NET/AutoUpdater.cs index 8ac4ba2a..d88f540a 100644 --- a/AutoUpdater.NET/AutoUpdater.cs +++ b/AutoUpdater.NET/AutoUpdater.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Cache; using System.Reflection; +using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Windows.Forms; @@ -100,6 +101,12 @@ public static class AutoUpdater /// public static String AppCastURL; + /// + /// Xml file contents that contains information about latest version of the application. + /// When set, AppCastURL will be ignored. + /// + public static String AppCastData; + /// /// Login/password/domain for FTP-request /// @@ -129,7 +136,7 @@ public static class AutoUpdater /// Set the User-Agent string to be used for HTTP web requests. /// public static string HttpUserAgent; - + /// /// If this is true users can see the skip button. /// @@ -218,6 +225,48 @@ public static class AutoUpdater /// public static Size? UpdateFormSize = null; + + /// + /// Set True to prevent any dialog/message boxes that require user interaction. + /// + public static bool IsSilentMode = false; + + + /// + /// Delegate type for hooking up logging. + /// + /// + public delegate void LogMessageHandler(LogMessageEventArgs args); + + /// + /// An event that clients can use to be notified of log messages. + /// + public static event LogMessageHandler LogMessageEvent; + + /// + /// Fires a log message event + /// + /// + /// + /// + public static void LogMessage(string source, string action, Exception ex) + { + LogMessageEvent(new LogMessageEventArgs(source, action, ex)); + } + + /// + /// Fires a log message event + /// + /// + /// + /// + /// + /// + public static void LogMessage(LogMessageEventArgs.Type logType, string source, string action, string message, string desc = "") + { + LogMessageEvent(new LogMessageEventArgs(logType, source, action, message, desc)); + } + /// /// Start checking for new version of application and display dialog to the user if update is available. /// @@ -242,16 +291,17 @@ public static void Start(String appCast, NetworkCredential ftpCredentials, Assem /// /// Start checking for new version of application and display dialog to the user if update is available. /// - /// URL of the xml file that contains information about latest version of the application. + /// URL of the xml file that contains information about latest version of the application or the actual data itself. /// Assembly to use for version checking. - public static void Start(String appCast, Assembly myAssembly = null) + /// Flag to indicate whether is a URL or the actual appCast data. + public static void Start(String appCast, Assembly myAssembly = null, bool isAppCastData = false) { try { - ServicePointManager.SecurityProtocol |= (SecurityProtocolType) 192 | - (SecurityProtocolType) 768 | (SecurityProtocolType) 3072; + ServicePointManager.SecurityProtocol |= (SecurityProtocolType)192 | + (SecurityProtocolType)768 | (SecurityProtocolType)3072; } - catch (NotSupportedException) {} + catch (NotSupportedException) { } if (Mandatory && _remindLaterTimer != null) { @@ -264,7 +314,10 @@ public static void Start(String appCast, Assembly myAssembly = null) { Running = true; - AppCastURL = appCast; + if (!isAppCastData) + AppCastURL = appCast; + else + AppCastData = appCast; IsWinFormsApplication = Application.MessageLoop; @@ -285,7 +338,7 @@ private static void BackgroundWorkerOnRunWorkerCompleted(object sender, { if (runWorkerCompletedEventArgs.Result is DateTime) { - SetTimer((DateTime) runWorkerCompletedEventArgs.Result); + SetTimer((DateTime)runWorkerCompletedEventArgs.Result); } else { @@ -307,8 +360,10 @@ private static void BackgroundWorkerOnRunWorkerCompleted(object sender, if (Mandatory && UpdateMode == Mode.ForcedDownload) { - DownloadUpdate(); - Exit(); + if (DownloadUpdate()) + { + Exit(); + } } else { @@ -371,185 +426,232 @@ public static void ShowUpdateForm() } } - private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) + /// + /// Gets update info. + /// + /// UpdateInfoEventArgs + private static UpdateInfoEventArgs GetUpdateInfo() { - e.Cancel = true; - Assembly mainAssembly = e.Argument as Assembly; + UpdateInfoEventArgs ParseAppCast(string appCast) => ParseUpdateInfoEvent != null + ? ParseAppCastCustom(appCast) + : ParseAppCastXml(appCast); - var companyAttribute = - (AssemblyCompanyAttribute) GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); - if (string.IsNullOrEmpty(AppTitle)) - { - var titleAttribute = - (AssemblyTitleAttribute) GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute)); - AppTitle = titleAttribute != null ? titleAttribute.Title : mainAssembly.GetName().Name; - } + UpdateInfoEventArgs ParseAppCastStream(Stream appCast) => ParseUpdateInfoEvent != null + ? ParseAppCastCustom(appCast) + : ParseAppCastXml(appCast); - string appCompany = companyAttribute != null ? companyAttribute.Company : ""; - RegistryLocation = !string.IsNullOrEmpty(appCompany) - ? $@"Software\{appCompany}\{AppTitle}\AutoUpdater" - : $@"Software\{AppTitle}\AutoUpdater"; + UpdateInfoEventArgs args = null; + if (!String.IsNullOrEmpty(AppCastData)) + { + args = ParseAppCast(AppCastData); + } + else + { + var webRequest = GetAppCastWebRequest(); + if (webRequest != null) + { + try + { + using (var webResponse = webRequest.GetResponse()) + using (var stream = webResponse.GetResponseStream()) + { + args = ParseAppCastStream(stream); + } + } + catch (Exception ex) + { + Debug.WriteLine(ex.ToString()); + return null; + } + } - InstalledVersion = mainAssembly.GetName().Version; + } + return args; + } - WebRequest webRequest = WebRequest.Create(AppCastURL); - webRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); + /// + /// Parse custom AppCast data + /// + /// Custom format of AppCast data + /// UpdateInfoEventArgs + private static UpdateInfoEventArgs ParseAppCastCustom(String appCastData) + { + var parseArgs = new ParseUpdateInfoEventArgs(appCastData); + ParseUpdateInfoEvent(parseArgs); + var args = parseArgs.UpdateInfo; + return args; + } - if (Proxy != null) + /// + /// Parses custom AppCast data + /// + /// Custom format of AppCast data + /// UpdateInfoEventArgs + private static UpdateInfoEventArgs ParseAppCastCustom(Stream appCastStream) + { + UpdateInfoEventArgs args = null; + using (var stream = new StreamReader(appCastStream)) { - webRequest.Proxy = Proxy; + string appCastData = stream.ReadToEnd(); + var parseArgs = new ParseUpdateInfoEventArgs(appCastData); + ParseUpdateInfoEvent(parseArgs); + args = parseArgs.UpdateInfo; } + return args; + } - var uri = new Uri(AppCastURL); - - WebResponse webResponse; - + /// + /// Parses known xml formatted AppCast data. + /// + /// AppCast data + /// UpdateInfoEventArgs + private static UpdateInfoEventArgs ParseAppCastXml(Stream appCastStream) + { + UpdateInfoEventArgs args = null; try { - if (uri.Scheme.Equals(Uri.UriSchemeFtp)) - { - var ftpWebRequest = (FtpWebRequest) webRequest; - ftpWebRequest.Credentials = FtpCredentials; - ftpWebRequest.UseBinary = true; - ftpWebRequest.UsePassive = true; - ftpWebRequest.KeepAlive = true; - ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile; - - webResponse = ftpWebRequest.GetResponse(); - } - else if(uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps)) - { - HttpWebRequest httpWebRequest = (HttpWebRequest) webRequest; - - httpWebRequest.UserAgent = GetUserAgent(); + XmlDocument receivedAppCastDocument = new XmlDocument(); + receivedAppCastDocument.Load(appCastStream); + args = ParseAppCastXml(receivedAppCastDocument); + } + catch (Exception) + { + return null; + } + return args; + } - if (BasicAuthXML != null) - { - httpWebRequest.Headers[HttpRequestHeader.Authorization] = BasicAuthXML.ToString(); - } - webResponse = httpWebRequest.GetResponse(); - } - else - { - webResponse = webRequest.GetResponse(); - } + /// + /// Parses known xml formatted AppCast data. + /// + /// AppCast data + /// UpdateInfoEventArgs + private static UpdateInfoEventArgs ParseAppCastXml(String appCastData) + { + UpdateInfoEventArgs args = null; + try + { + XmlDocument receivedAppCastDocument = new XmlDocument(); + receivedAppCastDocument.Load(appCastData); + args = ParseAppCastXml(receivedAppCastDocument); } - catch (Exception exception) + catch (Exception) { - Debug.WriteLine(exception); - e.Cancel = false; - return; + return null; } + return args; + } - UpdateInfoEventArgs args; + /// + /// Parses known xml formatted AppCast data. + /// + /// AppCast data xml document + /// UpdateInfoEventArgs + private static UpdateInfoEventArgs ParseAppCastXml(XmlDocument appCastXmlDoc) + { + XmlNodeList appCastItems = appCastXmlDoc.SelectNodes("item"); - using (Stream appCastStream = webResponse.GetResponseStream()) + var args = new UpdateInfoEventArgs(); + + if (appCastItems != null) { - if (appCastStream != null) + foreach (XmlNode item in appCastItems) { - if (ParseUpdateInfoEvent != null) + XmlNode appCastVersion = item.SelectSingleNode("version"); + + try { - using (StreamReader streamReader = new StreamReader(appCastStream)) - { - string data = streamReader.ReadToEnd(); - ParseUpdateInfoEventArgs parseArgs = new ParseUpdateInfoEventArgs(data); - ParseUpdateInfoEvent(parseArgs); - args = parseArgs.UpdateInfo; - } + CurrentVersion = new Version(appCastVersion?.InnerText); } - else + catch (Exception) { - XmlDocument receivedAppCastDocument = new XmlDocument(); + CurrentVersion = null; + } - try - { - receivedAppCastDocument.Load(appCastStream); + args.CurrentVersion = CurrentVersion; + + XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); + + args.ChangelogURL = appCastChangeLog?.InnerText; + + XmlNode appCastUrl = item.SelectSingleNode("url"); - XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item"); + args.DownloadURL = appCastUrl?.InnerText; - args = new UpdateInfoEventArgs(); + if (Mandatory.Equals(false)) + { + XmlNode mandatory = item.SelectSingleNode("mandatory"); + + Boolean.TryParse(mandatory?.InnerText, out Mandatory); - if (appCastItems != null) + string mode = mandatory?.Attributes["mode"]?.InnerText; + + if (!string.IsNullOrEmpty(mode)) + { + UpdateMode = (Mode)Enum.Parse(typeof(Mode), mode); + if (ReportErrors && !Enum.IsDefined(typeof(Mode), UpdateMode)) { - foreach (XmlNode item in appCastItems) - { - XmlNode appCastVersion = item.SelectSingleNode("version"); + throw new InvalidDataException( + $"{UpdateMode} is not an underlying value of the Mode enumeration."); + } + } + } - try - { - CurrentVersion = new Version(appCastVersion?.InnerText); - } - catch (Exception) - { - CurrentVersion = null; - } + args.Mandatory = Mandatory; + args.UpdateMode = UpdateMode; - args.CurrentVersion = CurrentVersion; + XmlNode appArgs = item.SelectSingleNode("args"); - XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); + args.InstallerArgs = appArgs?.InnerText; - args.ChangelogURL = appCastChangeLog?.InnerText; + XmlNode checksum = item.SelectSingleNode("checksum"); - XmlNode appCastUrl = item.SelectSingleNode("url"); + args.HashingAlgorithm = checksum?.Attributes["algorithm"]?.InnerText; - args.DownloadURL = appCastUrl?.InnerText; + args.Checksum = checksum?.InnerText; + } + } - if (Mandatory.Equals(false)) - { - XmlNode mandatory = item.SelectSingleNode("mandatory"); - Boolean.TryParse(mandatory?.InnerText, out Mandatory); + return args; + } - string mode = mandatory?.Attributes["mode"]?.InnerText; - if (!string.IsNullOrEmpty(mode)) - { - UpdateMode = (Mode) Enum.Parse(typeof(Mode), mode); - if (ReportErrors && !Enum.IsDefined(typeof(Mode), UpdateMode)) - { - throw new InvalidDataException( - $"{UpdateMode} is not an underlying value of the Mode enumeration."); - } - } - } + private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) + { + e.Cancel = true; + Assembly mainAssembly = e.Argument as Assembly; - args.Mandatory = Mandatory; - args.UpdateMode = UpdateMode; + var companyAttribute = + (AssemblyCompanyAttribute)GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); + if (string.IsNullOrEmpty(AppTitle)) + { + var titleAttribute = + (AssemblyTitleAttribute)GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute)); + AppTitle = titleAttribute != null ? titleAttribute.Title : mainAssembly.GetName().Name; + } - XmlNode appArgs = item.SelectSingleNode("args"); + string appCompany = companyAttribute != null ? companyAttribute.Company : ""; - args.InstallerArgs = appArgs?.InnerText; + RegistryLocation = !string.IsNullOrEmpty(appCompany) + ? $@"Software\{appCompany}\{AppTitle}\AutoUpdater" + : $@"Software\{AppTitle}\AutoUpdater"; - XmlNode checksum = item.SelectSingleNode("checksum"); + InstalledVersion = mainAssembly.GetName().Version; - args.HashingAlgorithm = checksum?.Attributes["algorithm"]?.InnerText; + var args = GetUpdateInfo(); - args.Checksum = checksum?.InnerText; - } - } - } - catch (Exception) - { - e.Cancel = false; - webResponse.Close(); - return; - } - } - } - else - { - e.Cancel = false; - webResponse.Close(); - return; - } + if (args == null) + { + e.Result = false; + return; } if (args.CurrentVersion == null || string.IsNullOrEmpty(args.DownloadURL)) { - webResponse.Close(); if (ReportErrors) { throw new InvalidDataException(); @@ -558,14 +660,17 @@ private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) return; } + bool IsAppCastFromWeb() => String.IsNullOrEmpty(AppCastData); + + Uri GetBaseUri() => IsAppCastFromWeb() ? new Uri(AppCastURL) : null; + CurrentVersion = args.CurrentVersion; - ChangelogURL = args.ChangelogURL = GetURL(webResponse.ResponseUri, args.ChangelogURL); - DownloadURL = args.DownloadURL = GetURL(webResponse.ResponseUri, args.DownloadURL); + ChangelogURL = args.ChangelogURL = GetURL(GetBaseUri(), args.ChangelogURL); + DownloadURL = args.DownloadURL = GetURL(GetBaseUri(), args.DownloadURL); InstallerArgs = args.InstallerArgs ?? String.Empty; HashingAlgorithm = args.HashingAlgorithm ?? "MD5"; Checksum = args.Checksum ?? String.Empty; - webResponse.Close(); if (Mandatory) { @@ -626,9 +731,64 @@ private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) e.Result = args; } + + + + private static WebRequest GetAppCastWebRequest() + { + WebRequest webRequest = WebRequest.Create(AppCastURL); + + webRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); + + if (Proxy != null) + { + webRequest.Proxy = Proxy; + } + + var uri = new Uri(AppCastURL); + + try + { + if (uri.Scheme.Equals(Uri.UriSchemeFtp)) + { + var ftpWebRequest = (FtpWebRequest)webRequest; + ftpWebRequest.Credentials = FtpCredentials; + ftpWebRequest.UseBinary = true; + ftpWebRequest.UsePassive = true; + ftpWebRequest.KeepAlive = true; + ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile; + + return ftpWebRequest; + + } + else if (uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps)) + { + HttpWebRequest httpWebRequest = (HttpWebRequest)webRequest; + + httpWebRequest.UserAgent = GetUserAgent(); + + if (BasicAuthXML != null) + { + httpWebRequest.Headers[HttpRequestHeader.Authorization] = BasicAuthXML.ToString(); + } + + return httpWebRequest; + } + else + { + return webRequest; + } + } + catch (Exception exception) + { + Debug.WriteLine(exception); + return null; + } + } + private static string GetURL(Uri baseUri, String url) { - if (!string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Relative)) + if (baseUri != null && !string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Relative)) { Uri uri = new Uri(baseUri, url); @@ -641,6 +801,8 @@ private static string GetURL(Uri baseUri, String url) return url; } + + /// /// Detects and exits all instances of running assembly, including current. /// @@ -673,7 +835,7 @@ private static void Exit() { if (process.CloseMainWindow()) { - process.WaitForExit((int) TimeSpan.FromSeconds(10) + process.WaitForExit((int)TimeSpan.FromSeconds(10) .TotalMilliseconds); //give some time to process message } @@ -711,7 +873,7 @@ private static Attribute GetAttribute(Assembly assembly, Type attributeType) return null; } - return (Attribute) attributes[0]; + return (Attribute)attributes[0]; } internal static string GetUserAgent() @@ -727,7 +889,7 @@ internal static void SetTimer(DateTime remindLater) _remindLaterTimer = new System.Timers.Timer { - Interval = (int) timeSpan.TotalMilliseconds, + Interval = (int)timeSpan.TotalMilliseconds, AutoReset = false }; @@ -854,6 +1016,48 @@ public ParseUpdateInfoEventArgs(string remoteData) } } + + public class LogMessageEventArgs : EventArgs + { + public enum Type + { + Info, + Warning, + Error + } + + public Type LogType { get; } + + public string Message { get; } + + public string Description { get; } + + public string Source { get; } + + public string Action { get; } + + public Exception Error { get; } + + public LogMessageEventArgs(string source, string action, Exception ex) + { + Error = ex; + Message = ex.Message; + Description = ex.ToString(); + Source = source; + Action = action; + LogType = Type.Error; + } + + public LogMessageEventArgs(Type logType, string source, string action, string message, string description = "") + { + LogType = logType; + Message = message; + Description = description; + Source = source; + Action = action; + } + } + /// /// Provides Basic Authentication header for web request. /// @@ -881,4 +1085,7 @@ public override string ToString() return $"Basic {token}"; } } + + + } \ No newline at end of file diff --git a/AutoUpdater.NET/DownloadUpdateDialog.cs b/AutoUpdater.NET/DownloadUpdateDialog.cs index 90017d73..7b324036 100644 --- a/AutoUpdater.NET/DownloadUpdateDialog.cs +++ b/AutoUpdater.NET/DownloadUpdateDialog.cs @@ -10,6 +10,7 @@ using System.Text; using System.Windows.Forms; using AutoUpdaterDotNET.Properties; +using static AutoUpdaterDotNET.AutoUpdater; namespace AutoUpdaterDotNET { @@ -23,17 +24,20 @@ internal partial class DownloadUpdateDialog : Form private DateTime _startedAt; + public DownloadUpdateDialog(string downloadURL) { InitializeComponent(); _downloadURL = downloadURL; + if (AutoUpdater.Mandatory && AutoUpdater.UpdateMode == Mode.ForcedDownload) { ControlBox = false; } } + private void DownloadUpdateDialogLoad(object sender, EventArgs e) { @@ -116,11 +120,18 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent if (asyncCompletedEventArgs.Error != null) { - MessageBox.Show(asyncCompletedEventArgs.Error.Message, - asyncCompletedEventArgs.Error.GetType().ToString(), MessageBoxButtons.OK, - MessageBoxIcon.Error); - _webClient = null; + if (!AutoUpdater.IsSilentMode) + { + MessageBox.Show(asyncCompletedEventArgs.Error.Message, + asyncCompletedEventArgs.Error.GetType().ToString(), MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + AutoUpdater.LogMessage($"{this.GetType()}", "WebClientOnDownloadFileCompleted", + asyncCompletedEventArgs.Error); + + _webClient = null; Close(); + return; } @@ -160,7 +171,11 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent } catch (Exception e) { - MessageBox.Show(e.Message, e.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); + if (!AutoUpdater.IsSilentMode) + { + MessageBox.Show(e.Message, e.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); + } + AutoUpdater.LogMessage($"{this.GetType()}", "WebClientOnDownloadFileCompleted", e); _webClient = null; Close(); return; @@ -187,7 +202,11 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent } catch (Exception e) { - MessageBox.Show(e.Message, e.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); + if (!AutoUpdater.IsSilentMode) + { + MessageBox.Show(e.Message, e.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); + } + AutoUpdater.LogMessage($"{this.GetType()}", "WebClientOnDownloadFileCompleted", e); _webClient = null; Close(); return; @@ -239,6 +258,7 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent catch (Win32Exception exception) { _webClient = null; + AutoUpdater.LogMessage($"{this.GetType()}", "WebClientOnDownloadFileCompleted", exception); if (exception.NativeErrorCode != 1223) throw; } @@ -269,16 +289,25 @@ private static bool CompareChecksum(string fileName, string checksum) var fileChecksum = BitConverter.ToString(hash).Replace("-", String.Empty).ToLowerInvariant(); if (fileChecksum == checksum.ToLower()) return true; - - MessageBox.Show(Resources.FileIntegrityCheckFailedMessage, + if (!AutoUpdater.IsSilentMode) + { + MessageBox.Show(Resources.FileIntegrityCheckFailedMessage, Resources.FileIntegrityCheckFailedCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + AutoUpdater.LogMessage(LogMessageEventArgs.Type.Error, $"DownloadUpdateDialog", "CompareChecksum", + Resources.FileIntegrityCheckFailedMessage); } else { if (AutoUpdater.ReportErrors) { - MessageBox.Show(Resources.HashAlgorithmNotSupportedMessage, + if (!AutoUpdater.IsSilentMode) + { + MessageBox.Show(Resources.HashAlgorithmNotSupportedMessage, Resources.HashAlgorithmNotSupportedCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + AutoUpdater.LogMessage(LogMessageEventArgs.Type.Error, $"DownloadUpdateDialog", "CompareChecksum", + Resources.HashAlgorithmNotSupportedMessage); } } @@ -316,8 +345,16 @@ public class MyWebClient : WebClient /// protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result) { - WebResponse webResponse = base.GetWebResponse(request, result); - ResponseUri = webResponse.ResponseUri; + WebResponse webResponse = default(WebResponse); + + webResponse = base.GetWebResponse(request, result); + ResponseUri = webResponse.ResponseUri; + //} catch (Exception ex) + //{ + // Debug.WriteLine(ex.ToString()); + //} + + return webResponse; } } diff --git a/AutoUpdater.NET/Properties/Resources.Designer.cs b/AutoUpdater.NET/Properties/Resources.Designer.cs index 6dbf3f9d..c1888fef 100644 --- a/AutoUpdater.NET/Properties/Resources.Designer.cs +++ b/AutoUpdater.NET/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace AutoUpdaterDotNET.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/ZipExtractor/ZipExtractor.csproj b/ZipExtractor/ZipExtractor.csproj index 93fc4a0e..afb34110 100644 --- a/ZipExtractor/ZipExtractor.csproj +++ b/ZipExtractor/ZipExtractor.csproj @@ -1,149 +1,149 @@ - - - - - Debug - AnyCPU - {91DE558C-6DB8-429B-A069-C0491DCFF15B} - WinExe - ZipExtractor - ZipExtractor - v4.0 - 512 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - - - AnyCPU - true - full - false - DEBUG;TRACE - prompt - 4 - - - AnyCPU - none - true - ..\AutoUpdater.NET\Resources\ - TRACE - prompt - 4 - - - v2.0 - bin\Debug\net20 - - - v2.0 - - - v3.5 - bin\Debug\net35 - - - v3.5 - - - v4.0 - bin\Debug\net40 - - - v4.0 - - - true - - - ZipExtractor.snk - - - - ZipExtractor.ico - - - app.manifest - - - - - - - - - - ..\packages\ZipStorer.3.6.0\lib\net20\ZipStorer.dll - - - - - Form - - - FormMain.cs - - - - - FormMain.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - Designer - - - - Designer - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + + + Debug + AnyCPU + {91DE558C-6DB8-429B-A069-C0491DCFF15B} + WinExe + ZipExtractor + ZipExtractor + v4.0 + 512 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + + + AnyCPU + true + full + false + DEBUG;TRACE + prompt + 4 + + + AnyCPU + none + true + ..\AutoUpdater.NET\Resources\ + TRACE + prompt + 4 + + + v2.0 + bin\Debug\net20 + + + v2.0 + + + v3.5 + bin\Debug\net35 + + + v3.5 + + + v4.0 + bin\Debug\net40 + + + v4.0 + + + false + + + ZipExtractor.snk + + + + ZipExtractor.ico + + + app.manifest + + + + + + + + + + ..\packages\ZipStorer.3.6.0\lib\net20\ZipStorer.dll + + + + + Form + + + FormMain.cs + + + + + FormMain.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + Designer + + + + Designer + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file