From 0b1ee0c39e9ddc56f589c4bf2247eabbf0f7ba15 Mon Sep 17 00:00:00 2001 From: "GREGA-AW\\grega" Date: Wed, 18 Jul 2018 16:54:53 +0200 Subject: [PATCH] Fixed the unsigned dependency bug. --- .../BlueUpdate Updater.csproj | 5 +- .../CodeBits/ByteSizeFriendlyName.cs | 108 ++++++++++++++++++ .../Presentation/MainWindow.xaml.cs | 19 ++- .../Properties/AssemblyInfo.cs | 4 +- .../BlueUpdate Updater/packages.config | 2 +- src/BlueUpdate/BlueUpdate.sln | 8 +- src/BlueUpdate/BlueUpdate/BlueUpdate.nuspec | 2 +- .../BlueUpdate/Properties/AssemblyInfo.cs | 4 +- 8 files changed, 128 insertions(+), 24 deletions(-) create mode 100644 src/BlueUpdate/BlueUpdate Updater/CodeBits/ByteSizeFriendlyName.cs diff --git a/src/BlueUpdate/BlueUpdate Updater/BlueUpdate Updater.csproj b/src/BlueUpdate/BlueUpdate Updater/BlueUpdate Updater.csproj index 305175a..4a224b4 100644 --- a/src/BlueUpdate/BlueUpdate Updater/BlueUpdate Updater.csproj +++ b/src/BlueUpdate/BlueUpdate Updater/BlueUpdate Updater.csproj @@ -47,10 +47,6 @@ GM.StrongNameKey.snk - - ..\packages\ByteSize.1.3.0\lib\net45\ByteSize.dll - True - ..\packages\GM.Utility.1.2.6\lib\netstandard2.0\GM.Utility.dll @@ -82,6 +78,7 @@ App.xaml Code + MainWindow.xaml Code diff --git a/src/BlueUpdate/BlueUpdate Updater/CodeBits/ByteSizeFriendlyName.cs b/src/BlueUpdate/BlueUpdate Updater/CodeBits/ByteSizeFriendlyName.cs new file mode 100644 index 0000000..b65183a --- /dev/null +++ b/src/BlueUpdate/BlueUpdate Updater/CodeBits/ByteSizeFriendlyName.cs @@ -0,0 +1,108 @@ +/* Documentation: http://codebits.codeplex.com/wikipage?title=ByteSizeFriendlyName */ + +using System; +using System.Collections.Generic; + +namespace CodeBits +{ + public static partial class ByteSizeFriendlyName + { + public static string Build(long bytes, FriendlyNameOptions options = null) + { + if (bytes < 0) + throw new ArgumentOutOfRangeException("bytes", "bytes cannot be a negative value"); + + options = options ?? FriendlyNameOptions.Default; + + string units; + double friendlySize = GetFriendlySize(bytes, out units); + + string sizeFormat = (options.GroupDigits ? "#,0." : "0.") + new string('#', options.DecimalPlaces); + string size = friendlySize.ToString(sizeFormat); + + if (options.UnitDisplayMode == UnitDisplayMode.AlwaysDisplay) + return string.Format("{0} {1}", size, units); + if (options.UnitDisplayMode == UnitDisplayMode.AlwaysHide) + return size; + return bytes < 1024 ? size : string.Format("{0} {1}", size, units); + } + + private static double GetFriendlySize(long bytes, out string units) + { + foreach (KeyValuePair byteMapping in ByteMappings) + { + if (bytes >= byteMapping.Key) + { + units = byteMapping.Value; + return bytes / byteMapping.Key; + } + } + units = bytes == 1 ? "byte" : "bytes"; + return bytes; + } + + private static readonly Dictionary ByteMappings = new Dictionary { + { Math.Pow(1024, 5), "PB" }, + { Math.Pow(1024, 4), "TB" }, + { Math.Pow(1024, 3), "GB" }, + { Math.Pow(1024, 2), "MB" }, + { Math.Pow(1024, 1), "KB" }, + }; + } + + /// + /// Options for generating the friendly name of a byte size. + /// + public sealed class FriendlyNameOptions + { + /// + /// Creates an instance of the FriendlyNameOptions class. + /// + public FriendlyNameOptions() + { + DecimalPlaces = 2; + UnitDisplayMode = UnitDisplayMode.AlwaysDisplay; + } + + /// + /// The number of decimal places to calculate for the friendly name size value. + /// + public int DecimalPlaces { get; set; } + + /// + /// Specifies whether to group digits in the friendly name size value. + /// + public bool GroupDigits { get; set; } + + /// + /// Specifies how the size unit is displayed in the friendly name. + /// + public UnitDisplayMode UnitDisplayMode { get; set; } + + /// + /// Represents the default options value for generating a friendly name. + /// + public static readonly FriendlyNameOptions Default = new FriendlyNameOptions(); + } + + /// + /// Specifies how the size unit (KB, MB, etc) is displayed in the friendly name. + /// + public enum UnitDisplayMode + { + /// + /// Always display the size unit (the default). + /// + AlwaysDisplay, + + /// + /// Always hide the size unit. + /// + AlwaysHide, + + /// + /// Only display the size unit if the value is 1 KB or more. Never display for sizes less than that. + /// + HideOnlyForBytes + } +} \ No newline at end of file diff --git a/src/BlueUpdate/BlueUpdate Updater/Presentation/MainWindow.xaml.cs b/src/BlueUpdate/BlueUpdate Updater/Presentation/MainWindow.xaml.cs index 9ddd04f..ac7511a 100644 --- a/src/BlueUpdate/BlueUpdate Updater/Presentation/MainWindow.xaml.cs +++ b/src/BlueUpdate/BlueUpdate Updater/Presentation/MainWindow.xaml.cs @@ -44,7 +44,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using System.Windows.Navigation; using System.Windows.Shapes; using BlueUpdate; -using ByteSizeLib; +using CodeBits; namespace BlueUpdate_Updater.Presentation { @@ -84,28 +84,27 @@ private void Update() { string total = null; - Action updateProgressChanged = (e) => + void updateProgressChanged(DownloadProgressChangedEventArgs e) { - ByteSize received = ByteSize.FromBytes(e.BytesReceived); + string received = ByteSizeFriendlyName.Build(e.BytesReceived); if(total == null) { - ByteSize totalBS = ByteSize.FromBytes(e.TotalBytesToReceive); - total = totalBS.ToString(); + total = ByteSizeFriendlyName.Build(e.TotalBytesToReceive); } - _TextBlock_Status.Text = $"Downloading: {received.ToString()} / {total}"; + _TextBlock_Status.Text = $"Downloading: {received} / {total}"; _ProgressBar.IsIndeterminate = false; _ProgressBar.Value = e.ProgressPercentage; - }; + } - Action updateCompleted = (e) => + void updateCompleted(AsyncCompletedEventArgs e) { if(e.Error != null) { Error = e.Error; - }else if(e.Cancelled) { + } else if(e.Cancelled) { Error = new Exception("The download process was cancelled."); } isFinished = true; Close(); - }; + } try { UpdateUtility.Update(appToUpdate, credentials, updateCompleted, updateProgressChanged); diff --git a/src/BlueUpdate/BlueUpdate Updater/Properties/AssemblyInfo.cs b/src/BlueUpdate/BlueUpdate Updater/Properties/AssemblyInfo.cs index 4999137..c756074 100644 --- a/src/BlueUpdate/BlueUpdate Updater/Properties/AssemblyInfo.cs +++ b/src/BlueUpdate/BlueUpdate Updater/Properties/AssemblyInfo.cs @@ -79,5 +79,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.3.1")] -[assembly: AssemblyFileVersion("1.0.3.1")] +[assembly: AssemblyVersion("1.0.3.2")] +[assembly: AssemblyFileVersion("1.0.3.2")] diff --git a/src/BlueUpdate/BlueUpdate Updater/packages.config b/src/BlueUpdate/BlueUpdate Updater/packages.config index 901f1dd..a0d0424 100644 --- a/src/BlueUpdate/BlueUpdate Updater/packages.config +++ b/src/BlueUpdate/BlueUpdate Updater/packages.config @@ -27,6 +27,6 @@ Created: 2018-7-17 Author: GregaMohorko --> - + \ No newline at end of file diff --git a/src/BlueUpdate/BlueUpdate.sln b/src/BlueUpdate/BlueUpdate.sln index 6d3c9a9..03afa79 100644 --- a/src/BlueUpdate/BlueUpdate.sln +++ b/src/BlueUpdate/BlueUpdate.sln @@ -13,12 +13,12 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.Build.0 = Release|Any CPU + {D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {D9B2471C-9048-4795-BEAB-BC099A3518B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {D9B2471C-9048-4795-BEAB-BC099A3518B6}.Release|Any CPU.Build.0 = Release|Any CPU - {A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.Build.0 = Release|Any CPU + {A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.Build.0 = Debug|Any CPU {A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Release|Any CPU.ActiveCfg = Release|Any CPU {A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection diff --git a/src/BlueUpdate/BlueUpdate/BlueUpdate.nuspec b/src/BlueUpdate/BlueUpdate/BlueUpdate.nuspec index 0e00bd8..874a36a 100644 --- a/src/BlueUpdate/BlueUpdate/BlueUpdate.nuspec +++ b/src/BlueUpdate/BlueUpdate/BlueUpdate.nuspec @@ -14,7 +14,7 @@ $description$ $copyright$ Update Updater Version Check Checksum Deployment Install - Updated dependency libraries. Signed the assembly. + Fixed the unsigned dependency bug. diff --git a/src/BlueUpdate/BlueUpdate/Properties/AssemblyInfo.cs b/src/BlueUpdate/BlueUpdate/Properties/AssemblyInfo.cs index e95f08c..879d71b 100644 --- a/src/BlueUpdate/BlueUpdate/Properties/AssemblyInfo.cs +++ b/src/BlueUpdate/BlueUpdate/Properties/AssemblyInfo.cs @@ -60,5 +60,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.3.1")] -[assembly: AssemblyFileVersion("1.0.3.1")] +[assembly: AssemblyVersion("1.0.3.2")] +[assembly: AssemblyFileVersion("1.0.3.2")]