diff --git a/FeedBuilder/FeedBuilder.csproj b/FeedBuilder/FeedBuilder.csproj index 235b7d20..85d03134 100644 --- a/FeedBuilder/FeedBuilder.csproj +++ b/FeedBuilder/FeedBuilder.csproj @@ -6,7 +6,7 @@ 2.0 {734FA44E-39AC-478E-A5AA-0F3D1F1974AA} - Exe + WinExe FeedBuilder.Program FeedBuilder FeedBuilder @@ -51,7 +51,8 @@ On - component.ico + + true diff --git a/src/NAppUpdate.Framework/NAppUpdate.Framework.csproj b/src/NAppUpdate.Framework/NAppUpdate.Framework.csproj index 2fb2acd1..36b38b33 100644 --- a/src/NAppUpdate.Framework/NAppUpdate.Framework.csproj +++ b/src/NAppUpdate.Framework/NAppUpdate.Framework.csproj @@ -34,6 +34,10 @@ false true + SAK + SAK + SAK + SAK true diff --git a/src/NAppUpdate.Framework/Resources.Designer.cs b/src/NAppUpdate.Framework/Resources.Designer.cs index 062e58c8..34685ab4 100644 --- a/src/NAppUpdate.Framework/Resources.Designer.cs +++ b/src/NAppUpdate.Framework/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17379 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -60,6 +60,9 @@ internal Resources() { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// internal static byte[] updater { get { object obj = ResourceManager.GetObject("updater", resourceCulture); diff --git a/src/NAppUpdate.Framework/Sources/IUpdateSource.cs b/src/NAppUpdate.Framework/Sources/IUpdateSource.cs index c32480f2..64ef3e54 100644 --- a/src/NAppUpdate.Framework/Sources/IUpdateSource.cs +++ b/src/NAppUpdate.Framework/Sources/IUpdateSource.cs @@ -6,6 +6,6 @@ namespace NAppUpdate.Framework.Sources public interface IUpdateSource { string GetUpdatesFeed(); // TODO: return a the feed as a stream - bool GetData(string filePath, string basePath, Action onProgress, ref string tempLocation); + void GetData(string filePath, string basePath, Action onProgress, ref string tempLocation); } } diff --git a/src/NAppUpdate.Framework/Sources/MemorySource.cs b/src/NAppUpdate.Framework/Sources/MemorySource.cs index 906b731f..67bcf68f 100644 --- a/src/NAppUpdate.Framework/Sources/MemorySource.cs +++ b/src/NAppUpdate.Framework/Sources/MemorySource.cs @@ -28,7 +28,7 @@ public string GetUpdatesFeed() return Feed; } - public bool GetData(string filePath, string basePath, Action onProgress, ref string tempFile) + public void GetData(string filePath, string basePath, Action onProgress, ref string tempFile) { Uri uriKey = null; @@ -37,12 +37,12 @@ public bool GetData(string filePath, string basePath, Action else if (Uri.IsWellFormedUriString(basePath, UriKind.Absolute)) uriKey = new Uri(new Uri(basePath, UriKind.Absolute), filePath); - if (uriKey == null || !tempFiles.ContainsKey(uriKey)) - return false; + if (uriKey == null) + throw new ApplicationException($"Unable to create Uri where filePath is '{filePath}' and basePath is '{basePath}'"); + if (!tempFiles.ContainsKey(uriKey)) + throw new ApplicationException($"Uri '${uriKey}' not found in tempFiles"); - tempFile = tempFiles[uriKey]; - - return true; + tempFile = tempFiles[uriKey]; } #endregion diff --git a/src/NAppUpdate.Framework/Sources/SimpleWebSource.cs b/src/NAppUpdate.Framework/Sources/SimpleWebSource.cs index 727e7a14..d458a051 100644 --- a/src/NAppUpdate.Framework/Sources/SimpleWebSource.cs +++ b/src/NAppUpdate.Framework/Sources/SimpleWebSource.cs @@ -64,7 +64,7 @@ public string GetUpdatesFeed() return data; } - public bool GetData(string url, string baseUrl, Action onProgress, ref string tempLocation) + public void GetData(string url, string baseUrl, Action onProgress, ref string tempLocation) { FileDownloader fd; // A baseUrl of http://testserver/somefolder with a file linklibrary.dll was resulting in a webrequest to http://testserver/linklibrary @@ -85,8 +85,15 @@ public bool GetData(string url, string baseUrl, Action onPro // files requiring pre-processing tempLocation = Path.GetTempFileName(); - return fd.DownloadToFile(tempLocation, onProgress); - } + try + { + fd.DownloadToFile(tempLocation, onProgress); + } + catch (Exception ex) + { + throw new ApplicationException($"An error occurred while downloading file '{(fd as FileDownloader).Uri.ToString()}'. {ex.Message}"); + } + } #endregion } diff --git a/src/NAppUpdate.Framework/Sources/UncSource.cs b/src/NAppUpdate.Framework/Sources/UncSource.cs index 54250b5f..cf6f44d7 100644 --- a/src/NAppUpdate.Framework/Sources/UncSource.cs +++ b/src/NAppUpdate.Framework/Sources/UncSource.cs @@ -50,7 +50,7 @@ public string GetUpdatesFeed() return data; } - public bool GetData(string filePath, string basePath, Action onProgress, ref string tempLocation) + public void GetData(string filePath, string basePath, Action onProgress, ref string tempLocation) { if (basePath == null) { @@ -62,7 +62,6 @@ public bool GetData(string filePath, string basePath, Action } File.Copy(basePath + filePath, tempLocation); - return true; } } } diff --git a/src/NAppUpdate.Framework/Tasks/FileUpdateTask.cs b/src/NAppUpdate.Framework/Tasks/FileUpdateTask.cs index 3830f2bf..5a217917 100644 --- a/src/NAppUpdate.Framework/Tasks/FileUpdateTask.cs +++ b/src/NAppUpdate.Framework/Tasks/FileUpdateTask.cs @@ -49,10 +49,16 @@ public override void Prepare(Sources.IUpdateSource source) UpdateManager.Instance.Logger.Log("FileUpdateTask: Downloading {0} with BaseUrl of {1} to {2}", fileName, baseUrl, tempFileLocal); - if (!source.GetData(fileName, baseUrl, OnProgress, ref tempFileLocal)) - throw new UpdateProcessFailedException("FileUpdateTask: Failed to get file from source"); - - _tempFile = tempFileLocal; + try + { + source.GetData(fileName, baseUrl, OnProgress, ref tempFileLocal); + } + catch (Exception ex) + { + throw new UpdateProcessFailedException($"FileUpdateTask: Failed to get file from source. {ex.Message}"); + } + + _tempFile = tempFileLocal; if (_tempFile == null) throw new UpdateProcessFailedException("FileUpdateTask: Failed to get file from source"); diff --git a/src/NAppUpdate.Framework/UpdateManager.cs b/src/NAppUpdate.Framework/UpdateManager.cs index 87295096..1b071b53 100644 --- a/src/NAppUpdate.Framework/UpdateManager.cs +++ b/src/NAppUpdate.Framework/UpdateManager.cs @@ -246,11 +246,11 @@ public void PrepareUpdates() catch (Exception ex) { task.ExecutionStatus = TaskExecutionStatus.FailedToPrepare; - Logger.Log(ex); - throw new UpdateProcessFailedException("Failed to prepare task: " + task.Description, ex); + Logger.Log(Logger.SeverityLevel.Warning, $"Error while preparing file with LocalPath '{(task as FileUpdateTask).LocalPath}'. {ex.Message}"); } + Logger.Dump(); - task.ExecutionStatus = TaskExecutionStatus.Prepared; + task.ExecutionStatus = TaskExecutionStatus.Prepared; } State = UpdateProcessState.Prepared; diff --git a/src/NAppUpdate.Framework/Updater/updater.exe b/src/NAppUpdate.Framework/Updater/updater.exe index 94c4caa2..36cf6216 100644 Binary files a/src/NAppUpdate.Framework/Updater/updater.exe and b/src/NAppUpdate.Framework/Updater/updater.exe differ diff --git a/src/NAppUpdate.Framework/Utils/FileDownloader.cs b/src/NAppUpdate.Framework/Utils/FileDownloader.cs index 4aba92f5..477dd609 100644 --- a/src/NAppUpdate.Framework/Utils/FileDownloader.cs +++ b/src/NAppUpdate.Framework/Utils/FileDownloader.cs @@ -12,6 +12,14 @@ public sealed class FileDownloader private const int _bufferSize = 1024; public IWebProxy Proxy { get; set; } + public Uri Uri + { + get + { + return _uri; + } + } + public FileDownloader() { Proxy = null; @@ -33,46 +41,59 @@ public byte[] Download() return client.DownloadData(_uri); } - public bool DownloadToFile(string tempLocation) - { - return DownloadToFile(tempLocation, null); - } + public void DownloadToFile(string tempLocation) + { + DownloadToFile(tempLocation, null); + } - public bool DownloadToFile(string tempLocation, Action onProgress) + public void DownloadToFile(string tempLocation, Action onProgress) { - var request = WebRequest.Create(_uri); - request.Proxy = Proxy; - - using (var response = request.GetResponse()) - using (var tempFile = File.Create(tempLocation)) - { - using (var responseStream = response.GetResponseStream()) - { - if (responseStream == null) - return false; - - long downloadSize = response.ContentLength; - long totalBytes = 0; - var buffer = new byte[_bufferSize]; - const int reportInterval = 1; - DateTime stamp = DateTime.Now.Subtract(new TimeSpan(0, 0, reportInterval)); - int bytesRead; - do - { - bytesRead = responseStream.Read(buffer, 0, buffer.Length); - totalBytes += bytesRead; - tempFile.Write(buffer, 0, bytesRead); - - if (onProgress == null || !(DateTime.Now.Subtract(stamp).TotalSeconds >= reportInterval)) continue; - ReportProgress(onProgress, totalBytes, downloadSize); - stamp = DateTime.Now; - } while (bytesRead > 0 && !UpdateManager.Instance.ShouldStop); - - ReportProgress(onProgress, totalBytes, downloadSize); - return totalBytes == downloadSize; - } - } - } + var request = WebRequest.Create(_uri); + request.Proxy = Proxy; + + try + { + using (var response = request.GetResponse()) + using (var tempFile = File.Create(tempLocation)) + { + using (var responseStream = response.GetResponseStream()) + { + if (responseStream == null) + throw new ApplicationException($"Unable to get response stream to file at uri '{_uri}'"); + + long downloadSize = response.ContentLength; + long totalBytes = 0; + var buffer = new byte[_bufferSize]; + const int reportInterval = 1; + DateTime stamp = DateTime.Now.Subtract(new TimeSpan(0, 0, reportInterval)); + int bytesRead; + do + { + bytesRead = responseStream.Read(buffer, 0, buffer.Length); + totalBytes += bytesRead; + tempFile.Write(buffer, 0, bytesRead); + + if (onProgress == null || !(DateTime.Now.Subtract(stamp).TotalSeconds >= reportInterval)) continue; + ReportProgress(onProgress, totalBytes, downloadSize); + stamp = DateTime.Now; + } while (bytesRead > 0 && !UpdateManager.Instance.ShouldStop); + + ReportProgress(onProgress, totalBytes, downloadSize); + + if (totalBytes != downloadSize) + throw new ApplicationException($"File at uri '{_uri}' did not fully download"); + } + } + } + catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) + { + throw new ApplicationException($"Unable to download file at '{_uri}'. {ex.Message}"); + } + catch (Exception ex) + { + throw new ApplicationException($"Unable to download file at '{_uri}'. {ex.Message}"); + } + } private void ReportProgress(Action onProgress, long totalBytes, long downloadSize) {