Skip to content

Commit

Permalink
Fixed the unsigned dependency bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
GregaMohorko committed Jul 18, 2018
1 parent ad3a2e2 commit 0b1ee0c
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 24 deletions.
5 changes: 1 addition & 4 deletions src/BlueUpdate/BlueUpdate Updater/BlueUpdate Updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
<AssemblyOriginatorKeyFile>GM.StrongNameKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="ByteSize, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ByteSize.1.3.0\lib\net45\ByteSize.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="GM.Utility, Version=1.2.6.0, Culture=neutral, PublicKeyToken=a1ae152199607549, processorArchitecture=MSIL">
<HintPath>..\packages\GM.Utility.1.2.6\lib\netstandard2.0\GM.Utility.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -82,6 +78,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="CodeBits\ByteSizeFriendlyName.cs" />
<Compile Include="Presentation\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
108 changes: 108 additions & 0 deletions src/BlueUpdate/BlueUpdate Updater/CodeBits/ByteSizeFriendlyName.cs
Original file line number Diff line number Diff line change
@@ -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<double, string> 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<double, string> ByteMappings = new Dictionary<double, string> {
{ 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" },
};
}

/// <summary>
/// Options for generating the friendly name of a byte size.
/// </summary>
public sealed class FriendlyNameOptions
{
/// <summary>
/// Creates an instance of the FriendlyNameOptions class.
/// </summary>
public FriendlyNameOptions()
{
DecimalPlaces = 2;
UnitDisplayMode = UnitDisplayMode.AlwaysDisplay;
}

/// <summary>
/// The number of decimal places to calculate for the friendly name size value.
/// </summary>
public int DecimalPlaces { get; set; }

/// <summary>
/// Specifies whether to group digits in the friendly name size value.
/// </summary>
public bool GroupDigits { get; set; }

/// <summary>
/// Specifies how the size unit is displayed in the friendly name.
/// </summary>
public UnitDisplayMode UnitDisplayMode { get; set; }

/// <summary>
/// Represents the default options value for generating a friendly name.
/// </summary>
public static readonly FriendlyNameOptions Default = new FriendlyNameOptions();
}

/// <summary>
/// Specifies how the size unit (KB, MB, etc) is displayed in the friendly name.
/// </summary>
public enum UnitDisplayMode
{
/// <summary>
/// Always display the size unit (the default).
/// </summary>
AlwaysDisplay,

/// <summary>
/// Always hide the size unit.
/// </summary>
AlwaysHide,

/// <summary>
/// Only display the size unit if the value is 1 KB or more. Never display for sizes less than that.
/// </summary>
HideOnlyForBytes
}
}
19 changes: 9 additions & 10 deletions src/BlueUpdate/BlueUpdate Updater/Presentation/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -84,28 +84,27 @@ private void Update()
{
string total = null;

Action<DownloadProgressChangedEventArgs> 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<AsyncCompletedEventArgs> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/BlueUpdate/BlueUpdate Updater/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion src/BlueUpdate/BlueUpdate Updater/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Created: 2018-7-17
Author: GregaMohorko
-->
<packages>
<package id="ByteSize" version="1.3.0" targetFramework="net461" />
<package id="CodeBits.ByteSizeFriendlyName" version="1.1.0" targetFramework="net461" />
<package id="GM.Utility" version="1.2.6" targetFramework="net461" />
</packages>
8 changes: 4 additions & 4 deletions src/BlueUpdate/BlueUpdate.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/BlueUpdate/BlueUpdate/BlueUpdate.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<summary>$description$</summary>
<copyright>$copyright$</copyright>
<tags>Update Updater Version Check Checksum Deployment Install</tags>
<releaseNotes>Updated dependency libraries. Signed the assembly.</releaseNotes>
<releaseNotes>Fixed the unsigned dependency bug.</releaseNotes>
</metadata>
<files>
<file src="readme.txt" target="" />
Expand Down
4 changes: 2 additions & 2 deletions src/BlueUpdate/BlueUpdate/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit 0b1ee0c

Please sign in to comment.