Skip to content

Commit 09552e3

Browse files
committed
Use WebClient instead of Downloader package
1 parent 06abcb1 commit 09552e3

8 files changed

Lines changed: 70 additions & 71 deletions

File tree

FlashpointInstaller/FlashpointInstaller.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@
9494
<Reference Include="Costura, Version=5.7.0.0, Culture=neutral, processorArchitecture=MSIL">
9595
<HintPath>packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll</HintPath>
9696
</Reference>
97-
<Reference Include="Downloader, Version=3.0.4.0, Culture=neutral, PublicKeyToken=844973e732f6cdf4, processorArchitecture=MSIL">
98-
<HintPath>packages\Downloader.3.0.4\lib\net452\Downloader.dll</HintPath>
99-
</Reference>
10097
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
10198
<HintPath>packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
10299
<Private>True</Private>
@@ -112,8 +109,8 @@
112109
<HintPath>packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
113110
</Reference>
114111
<Reference Include="PresentationFramework" />
115-
<Reference Include="SharpCompress, Version=0.32.2.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
116-
<HintPath>packages\SharpCompress.0.32.2\lib\net461\SharpCompress.dll</HintPath>
112+
<Reference Include="SharpCompress, Version=0.33.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
113+
<HintPath>packages\SharpCompress.0.33.0\lib\net462\SharpCompress.dll</HintPath>
117114
</Reference>
118115
<Reference Include="System" />
119116
<Reference Include="System.AppContext, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -358,10 +355,10 @@
358355
</PropertyGroup>
359356
<Error Condition="!Exists('packages\Costura.Fody.5.7.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.5.7.0\build\Costura.Fody.props'))" />
360357
<Error Condition="!Exists('packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.5.7.0\build\Costura.Fody.targets'))" />
361-
<Error Condition="!Exists('packages\Fody.6.6.4\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.6.6.4\build\Fody.targets'))" />
362358
<Error Condition="!Exists('packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets'))" />
359+
<Error Condition="!Exists('packages\Fody.6.7.0\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.6.7.0\build\Fody.targets'))" />
363360
</Target>
364361
<Import Project="packages\Costura.Fody.5.7.0\build\Costura.Fody.targets" Condition="Exists('packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')" />
365-
<Import Project="packages\Fody.6.6.4\build\Fody.targets" Condition="Exists('packages\Fody.6.6.4\build\Fody.targets')" />
366362
<Import Project="packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
363+
<Import Project="packages\Fody.6.7.0\build\Fody.targets" Condition="Exists('packages\Fody.6.7.0\build\Fody.targets')" />
367364
</Project>

FlashpointInstaller/packages.config

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Costura.Fody" version="5.7.0" targetFramework="net472" developmentDependency="true" />
4-
<package id="Downloader" version="3.0.4" targetFramework="net472" />
5-
<package id="Fody" version="6.6.4" targetFramework="net472" developmentDependency="true" />
6-
<package id="Microsoft.NETCore.Platforms" version="7.0.1" targetFramework="net472" />
4+
<package id="Fody" version="6.7.0" targetFramework="net472" developmentDependency="true" />
5+
<package id="Microsoft.NETCore.Platforms" version="7.0.2" targetFramework="net472" />
76
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net472" />
87
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.2" targetFramework="net472" />
98
<package id="Microsoft.WindowsAPICodePack-Shell" version="1.1.0.0" targetFramework="net472" />
109
<package id="NETStandard.Library" version="2.0.3" targetFramework="net472" />
11-
<package id="SharpCompress" version="0.32.2" targetFramework="net472" />
10+
<package id="SharpCompress" version="0.33.0" targetFramework="net472" />
1211
<package id="System.AppContext" version="4.3.0" targetFramework="net472" />
1312
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
1413
<package id="System.Collections" version="4.3.0" targetFramework="net472" />

FlashpointInstaller/src/Forms/Operate.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
using System.Net;
67
using System.Threading.Tasks;
78
using System.Windows.Forms;
89

9-
using Downloader;
1010
using FlashpointInstaller.Common;
1111
using Microsoft.WindowsAPICodePack.Taskbar;
1212
using SharpCompress.Archives.Zip;
@@ -21,7 +21,7 @@ public partial class Operate : Form
2121

2222
List<Component> markedComponents = new List<Component>();
2323

24-
DownloadService downloader = new DownloadService();
24+
WebClient client = new WebClient();
2525

2626
Stream stream;
2727
ZipArchive archive;
@@ -38,8 +38,7 @@ private async void Operation_Load(object sender, EventArgs e)
3838
{
3939
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal, FPM.Main.Handle);
4040

41-
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
42-
downloader.DownloadFileCompleted += OnDownloadFileCompleted;
41+
client.DownloadProgressChanged += OnDownloadProgressChanged;
4342

4443
FPM.IterateList(FPM.Main.ComponentList.Nodes, node =>
4544
{
@@ -55,9 +54,20 @@ private async void Operation_Load(object sender, EventArgs e)
5554
foreach (var component in markedComponents)
5655
{
5756
workingComponent = component;
58-
if (component.Size > 0) stream = await downloader.DownloadFileTaskAsync(component.URL);
5957

60-
if (cancelStatus != 0) return;
58+
if (component.Size > 0)
59+
{
60+
try
61+
{
62+
stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(component.URL)));
63+
}
64+
catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled)
65+
{
66+
client.Dispose();
67+
cancelStatus = 2;
68+
return;
69+
}
70+
}
6171

6272
await Task.Run(ExtractComponents);
6373

@@ -75,7 +85,8 @@ private async void Operation_Load(object sender, EventArgs e)
7585

7686
if (!File.Exists(redistPath))
7787
{
78-
await new DownloadService().DownloadFileTaskAsync("https://aka.ms/vs/17/release/vc_redist.x86.exe", redistPath);
88+
client.DownloadProgressChanged -= OnDownloadProgressChanged;
89+
await client.DownloadFileTaskAsync("https://aka.ms/vs/17/release/vc_redist.x86.exe", redistPath);
7990
}
8091

8192
await Task.Run(() =>
@@ -102,11 +113,11 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
102113
{
103114
if (cancelStatus != 0)
104115
{
105-
downloader.CancelAsync();
116+
client.CancelAsync();
106117
return;
107118
}
108119

109-
double currentProgress = (double)e.ReceivedBytesSize / e.TotalBytesToReceive;
120+
double currentProgress = (double)e.BytesReceived / e.TotalBytesToReceive;
110121
long currentSize = workingComponent.Size;
111122
double totalProgress = (byteProgress + (currentProgress / 2 * currentSize)) / byteTotal;
112123

@@ -119,7 +130,7 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
119130
{
120131
ProgressLabel.Text =
121132
$"[{(int)((double)totalProgress * 100)}%] Downloading component \"{workingComponent.Title}\"... " +
122-
$"{FPM.GetFormattedBytes(e.ReceivedBytesSize)} of {FPM.GetFormattedBytes(e.TotalBytesToReceive)}";
133+
$"{FPM.GetFormattedBytes(e.BytesReceived)} of {FPM.GetFormattedBytes(e.TotalBytesToReceive)}";
123134
});
124135

125136
FPM.Main.Invoke((MethodInvoker)delegate
@@ -130,11 +141,6 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
130141
});
131142
}
132143

133-
private void OnDownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
134-
{
135-
if (e.Cancelled) cancelStatus = 2;
136-
}
137-
138144
private void ExtractComponents()
139145
{
140146
string rootPath = FPM.Main.DestinationPath.Text;

FlashpointInstaller/src/Program.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System;
22
using System.IO;
3-
using System.Threading.Tasks;
3+
using System.Net;
44
using System.Windows.Forms;
55
using System.Xml;
66

7-
using Downloader;
87
using FlashpointInstaller.Common;
98

109
namespace FlashpointInstaller
@@ -20,10 +19,14 @@ static void Main(string[] args)
2019
Application.EnableVisualStyles();
2120
Application.SetCompatibleTextRenderingDefault(false);
2221

23-
Stream listStream = null;
24-
Task.Run(async () => { listStream = await new DownloadService().DownloadFileTaskAsync(FPM.ListURL); }).Wait();
22+
try
23+
{
24+
var listStream = new MemoryStream(new WebClient().DownloadData(FPM.ListURL)) { Position = 0 };
2525

26-
if (listStream == null)
26+
FPM.XmlTree = new XmlDocument();
27+
FPM.XmlTree.Load(listStream);
28+
}
29+
catch
2730
{
2831
MessageBox.Show(
2932
"The component list could not be downloaded! Do you have an internet connection?",
@@ -32,11 +35,6 @@ static void Main(string[] args)
3235

3336
Environment.Exit(1);
3437
}
35-
36-
listStream.Position = 0;
37-
38-
FPM.XmlTree = new XmlDocument();
39-
FPM.XmlTree.Load(listStream);
4038

4139
Application.Run(new Main());
4240
}

FlashpointManager/FlashpointManager.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@
9898
<Reference Include="Costura, Version=5.7.0.0, Culture=neutral, processorArchitecture=MSIL">
9999
<HintPath>packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll</HintPath>
100100
</Reference>
101-
<Reference Include="Downloader, Version=3.0.4.0, Culture=neutral, PublicKeyToken=844973e732f6cdf4, processorArchitecture=MSIL">
102-
<HintPath>packages\Downloader.3.0.4\lib\net452\Downloader.dll</HintPath>
103-
</Reference>
104101
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
105102
<HintPath>packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
106103
<Private>True</Private>
@@ -116,8 +113,8 @@
116113
<HintPath>packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
117114
</Reference>
118115
<Reference Include="PresentationFramework" />
119-
<Reference Include="SharpCompress, Version=0.32.2.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
120-
<HintPath>packages\SharpCompress.0.32.2\lib\net461\SharpCompress.dll</HintPath>
116+
<Reference Include="SharpCompress, Version=0.33.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
117+
<HintPath>packages\SharpCompress.0.33.0\lib\net462\SharpCompress.dll</HintPath>
121118
</Reference>
122119
<Reference Include="System" />
123120
<Reference Include="System.AppContext, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -354,10 +351,10 @@
354351
</PropertyGroup>
355352
<Error Condition="!Exists('packages\Costura.Fody.5.7.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.5.7.0\build\Costura.Fody.props'))" />
356353
<Error Condition="!Exists('packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.5.7.0\build\Costura.Fody.targets'))" />
357-
<Error Condition="!Exists('packages\Fody.6.6.4\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.6.6.4\build\Fody.targets'))" />
358354
<Error Condition="!Exists('packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets'))" />
355+
<Error Condition="!Exists('packages\Fody.6.7.0\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.6.7.0\build\Fody.targets'))" />
359356
</Target>
360357
<Import Project="packages\Costura.Fody.5.7.0\build\Costura.Fody.targets" Condition="Exists('packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')" />
361-
<Import Project="packages\Fody.6.6.4\build\Fody.targets" Condition="Exists('packages\Fody.6.6.4\build\Fody.targets')" />
362358
<Import Project="packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
359+
<Import Project="packages\Fody.6.7.0\build\Fody.targets" Condition="Exists('packages\Fody.6.7.0\build\Fody.targets')" />
363360
</Project>

FlashpointManager/packages.config

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Costura.Fody" version="5.7.0" targetFramework="net472" developmentDependency="true" />
4-
<package id="Downloader" version="3.0.4" targetFramework="net472" />
5-
<package id="Fody" version="6.6.4" targetFramework="net472" developmentDependency="true" />
6-
<package id="Microsoft.NETCore.Platforms" version="7.0.1" targetFramework="net472" />
4+
<package id="Fody" version="6.7.0" targetFramework="net472" developmentDependency="true" />
5+
<package id="Microsoft.NETCore.Platforms" version="7.0.2" targetFramework="net472" />
76
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net472" />
87
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.2" targetFramework="net472" />
98
<package id="Microsoft.WindowsAPICodePack-Shell" version="1.1.0.0" targetFramework="net472" />
109
<package id="NETStandard.Library" version="2.0.3" targetFramework="net472" />
11-
<package id="SharpCompress" version="0.32.2" targetFramework="net472" />
10+
<package id="SharpCompress" version="0.33.0" targetFramework="net472" />
1211
<package id="System.AppContext" version="4.3.0" targetFramework="net472" />
1312
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
1413
<package id="System.Collections" version="4.3.0" targetFramework="net472" />

FlashpointManager/src/Forms/Operate.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Net;
56
using System.Threading.Tasks;
67
using System.Windows.Forms;
78

8-
using Downloader;
99
using FlashpointInstaller.Common;
1010
using Microsoft.WindowsAPICodePack.Taskbar;
1111
using SharpCompress.Archives.Zip;
@@ -21,7 +21,7 @@ public partial class Operate : Form
2121
List<Component> addedComponents = new List<Component>();
2222
List<Component> removedComponents = new List<Component>();
2323

24-
DownloadService downloader = new DownloadService();
24+
WebClient client = new WebClient();
2525

2626
Stream stream;
2727
ZipArchive archive;
@@ -38,8 +38,7 @@ private async void Operation_Load(object sender, EventArgs e)
3838
{
3939
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal, FPM.Main.Handle);
4040

41-
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
42-
downloader.DownloadFileCompleted += OnDownloadFileCompleted;
41+
client.DownloadProgressChanged += OnDownloadProgressChanged;
4342

4443
if (!FPM.UpdateMode)
4544
{
@@ -80,9 +79,20 @@ private async void Operation_Load(object sender, EventArgs e)
8079
foreach (var component in addedComponents)
8180
{
8281
workingComponent = component;
83-
if (component.Size > 0) stream = await downloader.DownloadFileTaskAsync(component.URL);
8482

85-
if (cancelStatus != 0) return;
83+
if (component.Size > 0)
84+
{
85+
try
86+
{
87+
stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(component.URL)));
88+
}
89+
catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled)
90+
{
91+
client.Dispose();
92+
cancelStatus = 2;
93+
return;
94+
}
95+
}
8696

8797
await Task.Run(ExtractComponents);
8898

@@ -124,11 +134,11 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
124134
{
125135
if (cancelStatus != 0)
126136
{
127-
downloader.CancelAsync();
137+
client.CancelAsync();
128138
return;
129139
}
130140

131-
double currentProgress = (double)e.ReceivedBytesSize / e.TotalBytesToReceive;
141+
double currentProgress = (double)e.BytesReceived / e.TotalBytesToReceive;
132142
long currentSize = workingComponent.Size;
133143
double totalProgress = (byteProgress + (currentProgress / 2 * currentSize)) / byteTotal;
134144

@@ -141,7 +151,7 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
141151
{
142152
ProgressLabel.Text =
143153
$"[{(int)((double)totalProgress * 100)}%] Downloading component \"{workingComponent.Title}\"... " +
144-
$"{FPM.GetFormattedBytes(e.ReceivedBytesSize)} of {FPM.GetFormattedBytes(e.TotalBytesToReceive)}";
154+
$"{FPM.GetFormattedBytes(e.BytesReceived)} of {FPM.GetFormattedBytes(e.TotalBytesToReceive)}";
145155
});
146156

147157
FPM.Main.Invoke((MethodInvoker)delegate
@@ -152,11 +162,6 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
152162
});
153163
}
154164

155-
private void OnDownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
156-
{
157-
if (e.Cancelled) cancelStatus = 2;
158-
}
159-
160165
private void ExtractComponents()
161166
{
162167
string rootPath = Path.Combine(FPM.SourcePath, "Temp");

FlashpointManager/src/Program.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Linq;
5-
using System.Threading.Tasks;
5+
using System.Net;
66
using System.Windows.Forms;
77
using System.Xml;
88

9-
using Downloader;
109
using FlashpointInstaller.Common;
1110

1211
namespace FlashpointInstaller
@@ -65,10 +64,14 @@ static void Main(string[] args)
6564
}
6665

6766
// Download and parse component list
68-
Stream listStream = null;
69-
Task.Run(async () => { listStream = await new DownloadService().DownloadFileTaskAsync(FPM.ListURL); }).Wait();
67+
try
68+
{
69+
var listStream = new MemoryStream(new WebClient().DownloadData(FPM.ListURL)) { Position = 0 };
7070

71-
if (listStream == null)
71+
FPM.XmlTree = new XmlDocument();
72+
FPM.XmlTree.Load(listStream);
73+
}
74+
catch
7275
{
7376
MessageBox.Show(
7477
"The component list could not be downloaded! Do you have an internet connection?",
@@ -78,11 +81,6 @@ static void Main(string[] args)
7881
Environment.Exit(1);
7982
}
8083

81-
listStream.Position = 0;
82-
83-
FPM.XmlTree = new XmlDocument();
84-
FPM.XmlTree.Load(listStream);
85-
8684
// Verify that the configured Flashpoint path is valid
8785
FPM.VerifySourcePath();
8886

0 commit comments

Comments
 (0)