Skip to content

Commit 9cd1b09

Browse files
committed
Code style fixes to {FFmpeg,RAIntegration}DownloaderForm
1 parent 9792335 commit 9cd1b09

File tree

2 files changed

+41
-50
lines changed

2 files changed

+41
-50
lines changed

src/BizHawk.Client.EmuHawk/AVOut/FFmpegDownloaderForm.cs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.IO;
22
using System.Linq;
3+
using System.Net;
34
using System.Threading;
45
using System.Windows.Forms;
56

@@ -44,24 +45,16 @@ private void Download()
4445
using var fs = File.Create(FFmpegService.FFmpegPath); // check writable before bothering with the download
4546
using (var evt = new ManualResetEvent(false))
4647
{
47-
using (var client = new System.Net.WebClient())
48+
using (var client = new WebClient())
4849
{
49-
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
50+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
5051
client.DownloadFileAsync(new Uri(FFmpegService.Url), fn);
51-
client.DownloadProgressChanged += (object sender, System.Net.DownloadProgressChangedEventArgs e) =>
52-
{
53-
pct = e.ProgressPercentage;
54-
};
55-
client.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
56-
{
57-
//we don't really need a status. we'll just try to unzip it when it's done
58-
evt.Set();
59-
};
52+
client.DownloadProgressChanged += (_, progressArgs) => pct = progressArgs.ProgressPercentage;
53+
client.DownloadFileCompleted += (_, _) => evt.Set(); // we don't really need a status, we'll just try to unzip it when it's done
6054

61-
for (; ; )
55+
while (true)
6256
{
63-
if (evt.WaitOne(10))
64-
break;
57+
if (evt.WaitOne(10)) break;
6558

6659
//if the gui thread ordered an exit, cancel the download and wait for it to acknowledge
6760
if (exiting)
@@ -74,20 +67,18 @@ private void Download()
7467
}
7568
}
7669

77-
//throw new Exception("test of download failure");
70+
// throw new Exception("test of download failure");
7871

7972
//if we were ordered to exit, bail without wasting any more time
80-
if (exiting)
81-
return;
73+
if (exiting) return;
8274

8375
//try acquiring file
8476
using (var hf = new HawkFile(fn))
8577
{
8678
using (var exe = OSTailoredCode.IsUnixHost ? hf.BindArchiveMember("ffmpeg") : hf.BindFirstOf(".exe"))
8779
{
8880
//last chance. exiting, don't dump the new ffmpeg file
89-
if (exiting)
90-
return;
81+
if (exiting) return;
9182
exe!.GetStream().CopyTo(fs);
9283
fs.Dispose();
9384
if (OSTailoredCode.IsUnixHost)
@@ -110,8 +101,14 @@ private void Download()
110101
}
111102
finally
112103
{
113-
try { File.Delete(fn); }
114-
catch { }
104+
try
105+
{
106+
File.Delete(fn);
107+
}
108+
catch
109+
{
110+
// ignore
111+
}
115112
}
116113
}
117114

@@ -141,8 +138,7 @@ protected override void OnClosed(EventArgs e)
141138
private void timer1_Tick(object sender, EventArgs e)
142139
{
143140
//if it's done, close the window. the user will be smart enough to reopen it
144-
if (succeeded)
145-
Close();
141+
if (succeeded) Close();
146142
if (failed)
147143
{
148144
failed = false;
@@ -159,4 +155,3 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
159155
}
160156
}
161157
}
162-

src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegrationDownloaderForm.cs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using System.Net;
23
using System.Threading;
34
using System.Windows.Forms;
45

@@ -30,12 +31,13 @@ public RAIntegrationDownloaderForm(string url)
3031
private bool _exiting = false;
3132
private bool _succeeded = false;
3233
private bool _failed = false;
33-
private Thread _thread;
34+
35+
private Thread/*?*/ _thread = null;
3436

3537
public bool DownloadSucceeded()
3638
{
3739
// block until the thread dies
38-
while (_thread?.IsAlive ?? false)
40+
while (_thread is { IsAlive: true })
3941
{
4042
Thread.Sleep(1);
4143
}
@@ -57,23 +59,15 @@ private void Download()
5759
{
5860
using (var evt = new ManualResetEvent(false))
5961
{
60-
using var client = new System.Net.WebClient();
61-
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
62+
using var client = new WebClient();
63+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
6264
client.DownloadFileAsync(new Uri(_url), fn);
63-
client.DownloadProgressChanged += (object sender, System.Net.DownloadProgressChangedEventArgs e) =>
64-
{
65-
_pct = e.ProgressPercentage;
66-
};
67-
client.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
68-
{
69-
//we don't really need a status. we'll just try to unzip it when it's done
70-
evt.Set();
71-
};
65+
client.DownloadProgressChanged += (_, progressArgs) => _pct = progressArgs.ProgressPercentage;
66+
client.DownloadFileCompleted += (_, _) => evt.Set(); // we don't really need a status, we'll just try to unzip it when it's done
7267

73-
for (; ; )
68+
while (true)
7469
{
75-
if (evt.WaitOne(10))
76-
break;
70+
if (evt.WaitOne(10)) break;
7771

7872
//if the gui thread ordered an exit, cancel the download and wait for it to acknowledge
7973
if (_exiting)
@@ -85,20 +79,18 @@ private void Download()
8579
}
8680
}
8781

88-
//throw new Exception("test of download failure");
82+
// throw new Exception("test of download failure");
8983

9084
//if we were ordered to exit, bail without wasting any more time
91-
if (_exiting)
92-
return;
85+
if (_exiting) return;
9386

9487
//try acquiring file
9588
using (var dll = new HawkFile(fn))
9689
{
9790
var data = dll!.ReadAllBytes();
9891

9992
//last chance. exiting, don't dump the new RAIntegration file
100-
if (_exiting)
101-
return;
93+
if (_exiting) return;
10294

10395
DirectoryInfo parentDir = new(Path.GetDirectoryName(_path)!);
10496
if (!parentDir.Exists) parentDir.Create();
@@ -114,8 +106,14 @@ private void Download()
114106
}
115107
finally
116108
{
117-
try { File.Delete(fn); }
118-
catch { }
109+
try
110+
{
111+
File.Delete(fn);
112+
}
113+
catch
114+
{
115+
// ignore
116+
}
119117
}
120118
}
121119

@@ -145,8 +143,7 @@ protected override void OnClosed(EventArgs e)
145143
private void timer1_Tick(object sender, EventArgs e)
146144
{
147145
//if it's done, close the window. the user will be smart enough to reopen it
148-
if (_succeeded)
149-
Close();
146+
if (_succeeded) Close();
150147
if (_failed)
151148
{
152149
_failed = false;
@@ -163,4 +160,3 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
163160
}
164161
}
165162
}
166-

0 commit comments

Comments
 (0)