Skip to content

Commit 0b1ee0c

Browse files
committed
Fixed the unsigned dependency bug.
1 parent ad3a2e2 commit 0b1ee0c

8 files changed

Lines changed: 128 additions & 24 deletions

File tree

src/BlueUpdate/BlueUpdate Updater/BlueUpdate Updater.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@
4747
<AssemblyOriginatorKeyFile>GM.StrongNameKey.snk</AssemblyOriginatorKeyFile>
4848
</PropertyGroup>
4949
<ItemGroup>
50-
<Reference Include="ByteSize, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
51-
<HintPath>..\packages\ByteSize.1.3.0\lib\net45\ByteSize.dll</HintPath>
52-
<Private>True</Private>
53-
</Reference>
5450
<Reference Include="GM.Utility, Version=1.2.6.0, Culture=neutral, PublicKeyToken=a1ae152199607549, processorArchitecture=MSIL">
5551
<HintPath>..\packages\GM.Utility.1.2.6\lib\netstandard2.0\GM.Utility.dll</HintPath>
5652
</Reference>
@@ -82,6 +78,7 @@
8278
<DependentUpon>App.xaml</DependentUpon>
8379
<SubType>Code</SubType>
8480
</Compile>
81+
<Compile Include="CodeBits\ByteSizeFriendlyName.cs" />
8582
<Compile Include="Presentation\MainWindow.xaml.cs">
8683
<DependentUpon>MainWindow.xaml</DependentUpon>
8784
<SubType>Code</SubType>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* Documentation: http://codebits.codeplex.com/wikipage?title=ByteSizeFriendlyName */
2+
3+
using System;
4+
using System.Collections.Generic;
5+
6+
namespace CodeBits
7+
{
8+
public static partial class ByteSizeFriendlyName
9+
{
10+
public static string Build(long bytes, FriendlyNameOptions options = null)
11+
{
12+
if (bytes < 0)
13+
throw new ArgumentOutOfRangeException("bytes", "bytes cannot be a negative value");
14+
15+
options = options ?? FriendlyNameOptions.Default;
16+
17+
string units;
18+
double friendlySize = GetFriendlySize(bytes, out units);
19+
20+
string sizeFormat = (options.GroupDigits ? "#,0." : "0.") + new string('#', options.DecimalPlaces);
21+
string size = friendlySize.ToString(sizeFormat);
22+
23+
if (options.UnitDisplayMode == UnitDisplayMode.AlwaysDisplay)
24+
return string.Format("{0} {1}", size, units);
25+
if (options.UnitDisplayMode == UnitDisplayMode.AlwaysHide)
26+
return size;
27+
return bytes < 1024 ? size : string.Format("{0} {1}", size, units);
28+
}
29+
30+
private static double GetFriendlySize(long bytes, out string units)
31+
{
32+
foreach (KeyValuePair<double, string> byteMapping in ByteMappings)
33+
{
34+
if (bytes >= byteMapping.Key)
35+
{
36+
units = byteMapping.Value;
37+
return bytes / byteMapping.Key;
38+
}
39+
}
40+
units = bytes == 1 ? "byte" : "bytes";
41+
return bytes;
42+
}
43+
44+
private static readonly Dictionary<double, string> ByteMappings = new Dictionary<double, string> {
45+
{ Math.Pow(1024, 5), "PB" },
46+
{ Math.Pow(1024, 4), "TB" },
47+
{ Math.Pow(1024, 3), "GB" },
48+
{ Math.Pow(1024, 2), "MB" },
49+
{ Math.Pow(1024, 1), "KB" },
50+
};
51+
}
52+
53+
/// <summary>
54+
/// Options for generating the friendly name of a byte size.
55+
/// </summary>
56+
public sealed class FriendlyNameOptions
57+
{
58+
/// <summary>
59+
/// Creates an instance of the FriendlyNameOptions class.
60+
/// </summary>
61+
public FriendlyNameOptions()
62+
{
63+
DecimalPlaces = 2;
64+
UnitDisplayMode = UnitDisplayMode.AlwaysDisplay;
65+
}
66+
67+
/// <summary>
68+
/// The number of decimal places to calculate for the friendly name size value.
69+
/// </summary>
70+
public int DecimalPlaces { get; set; }
71+
72+
/// <summary>
73+
/// Specifies whether to group digits in the friendly name size value.
74+
/// </summary>
75+
public bool GroupDigits { get; set; }
76+
77+
/// <summary>
78+
/// Specifies how the size unit is displayed in the friendly name.
79+
/// </summary>
80+
public UnitDisplayMode UnitDisplayMode { get; set; }
81+
82+
/// <summary>
83+
/// Represents the default options value for generating a friendly name.
84+
/// </summary>
85+
public static readonly FriendlyNameOptions Default = new FriendlyNameOptions();
86+
}
87+
88+
/// <summary>
89+
/// Specifies how the size unit (KB, MB, etc) is displayed in the friendly name.
90+
/// </summary>
91+
public enum UnitDisplayMode
92+
{
93+
/// <summary>
94+
/// Always display the size unit (the default).
95+
/// </summary>
96+
AlwaysDisplay,
97+
98+
/// <summary>
99+
/// Always hide the size unit.
100+
/// </summary>
101+
AlwaysHide,
102+
103+
/// <summary>
104+
/// Only display the size unit if the value is 1 KB or more. Never display for sizes less than that.
105+
/// </summary>
106+
HideOnlyForBytes
107+
}
108+
}

src/BlueUpdate/BlueUpdate Updater/Presentation/MainWindow.xaml.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4444
using System.Windows.Navigation;
4545
using System.Windows.Shapes;
4646
using BlueUpdate;
47-
using ByteSizeLib;
47+
using CodeBits;
4848

4949
namespace BlueUpdate_Updater.Presentation
5050
{
@@ -84,28 +84,27 @@ private void Update()
8484
{
8585
string total = null;
8686

87-
Action<DownloadProgressChangedEventArgs> updateProgressChanged = (e) =>
87+
void updateProgressChanged(DownloadProgressChangedEventArgs e)
8888
{
89-
ByteSize received = ByteSize.FromBytes(e.BytesReceived);
89+
string received = ByteSizeFriendlyName.Build(e.BytesReceived);
9090
if(total == null) {
91-
ByteSize totalBS = ByteSize.FromBytes(e.TotalBytesToReceive);
92-
total = totalBS.ToString();
91+
total = ByteSizeFriendlyName.Build(e.TotalBytesToReceive);
9392
}
94-
_TextBlock_Status.Text = $"Downloading: {received.ToString()} / {total}";
93+
_TextBlock_Status.Text = $"Downloading: {received} / {total}";
9594
_ProgressBar.IsIndeterminate = false;
9695
_ProgressBar.Value = e.ProgressPercentage;
97-
};
96+
}
9897

99-
Action<AsyncCompletedEventArgs> updateCompleted = (e) =>
98+
void updateCompleted(AsyncCompletedEventArgs e)
10099
{
101100
if(e.Error != null) {
102101
Error = e.Error;
103-
}else if(e.Cancelled) {
102+
} else if(e.Cancelled) {
104103
Error = new Exception("The download process was cancelled.");
105104
}
106105
isFinished = true;
107106
Close();
108-
};
107+
}
109108

110109
try {
111110
UpdateUtility.Update(appToUpdate, credentials, updateCompleted, updateProgressChanged);

src/BlueUpdate/BlueUpdate Updater/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
7979
// You can specify all the values or you can default the Build and Revision Numbers
8080
// by using the '*' as shown below:
8181
// [assembly: AssemblyVersion("1.0.*")]
82-
[assembly: AssemblyVersion("1.0.3.1")]
83-
[assembly: AssemblyFileVersion("1.0.3.1")]
82+
[assembly: AssemblyVersion("1.0.3.2")]
83+
[assembly: AssemblyFileVersion("1.0.3.2")]

src/BlueUpdate/BlueUpdate Updater/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ Created: 2018-7-17
2727
Author: GregaMohorko
2828
-->
2929
<packages>
30-
<package id="ByteSize" version="1.3.0" targetFramework="net461" />
30+
<package id="CodeBits.ByteSizeFriendlyName" version="1.1.0" targetFramework="net461" />
3131
<package id="GM.Utility" version="1.2.6" targetFramework="net461" />
3232
</packages>

src/BlueUpdate/BlueUpdate.sln

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Global
1313
Release|Any CPU = Release|Any CPU
1414
EndGlobalSection
1515
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.ActiveCfg = Release|Any CPU
17-
{D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.Build.0 = Release|Any CPU
16+
{D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{D9B2471C-9048-4795-BEAB-BC099A3518B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
1818
{D9B2471C-9048-4795-BEAB-BC099A3518B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
1919
{D9B2471C-9048-4795-BEAB-BC099A3518B6}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.ActiveCfg = Release|Any CPU
21-
{A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.Build.0 = Release|Any CPU
20+
{A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Debug|Any CPU.Build.0 = Debug|Any CPU
2222
{A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Release|Any CPU.ActiveCfg = Release|Any CPU
2323
{A7F835C7-9F74-4C26-8A8C-07E5A2E7DEED}.Release|Any CPU.Build.0 = Release|Any CPU
2424
EndGlobalSection

src/BlueUpdate/BlueUpdate/BlueUpdate.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<summary>$description$</summary>
1515
<copyright>$copyright$</copyright>
1616
<tags>Update Updater Version Check Checksum Deployment Install</tags>
17-
<releaseNotes>Updated dependency libraries. Signed the assembly.</releaseNotes>
17+
<releaseNotes>Fixed the unsigned dependency bug.</releaseNotes>
1818
</metadata>
1919
<files>
2020
<file src="readme.txt" target="" />

src/BlueUpdate/BlueUpdate/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6060
// You can specify all the values or you can default the Build and Revision Numbers
6161
// by using the '*' as shown below:
6262
// [assembly: AssemblyVersion("1.0.*")]
63-
[assembly: AssemblyVersion("1.0.3.1")]
64-
[assembly: AssemblyFileVersion("1.0.3.1")]
63+
[assembly: AssemblyVersion("1.0.3.2")]
64+
[assembly: AssemblyFileVersion("1.0.3.2")]

0 commit comments

Comments
 (0)