Skip to content

Commit 3ba9831

Browse files
committed
Code style fixes to {FFmpeg,RAIntegration}DownloaderForm
1 parent 6e63322 commit 3ba9831

File tree

2 files changed

+46
-53
lines changed

2 files changed

+46
-53
lines changed

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Diagnostics;
12
using System.IO;
23
using System.Linq;
4+
using System.Net;
35
using System.Threading;
46
using System.Windows.Forms;
57

@@ -44,24 +46,16 @@ private void Download()
4446
using var fs = File.Create(FFmpegService.FFmpegPath); // check writable before bothering with the download
4547
using (var evt = new ManualResetEvent(false))
4648
{
47-
using (var client = new System.Net.WebClient())
49+
using (var client = new WebClient())
4850
{
49-
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
51+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
5052
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-
};
53+
client.DownloadProgressChanged += (_, progressArgs) => pct = progressArgs.ProgressPercentage;
54+
client.DownloadFileCompleted += (_, _) => evt.Set(); // we don't really need a status, we'll just try to unzip it when it's done
6055

61-
for (; ; )
56+
while (true)
6257
{
63-
if (evt.WaitOne(10))
64-
break;
58+
if (evt.WaitOne(10)) break;
6559

6660
//if the gui thread ordered an exit, cancel the download and wait for it to acknowledge
6761
if (exiting)
@@ -73,21 +67,19 @@ private void Download()
7367
}
7468
}
7569
}
76-
77-
//throw new Exception("test of download failure");
70+
71+
// throw new Exception("test of download failure");
7872

7973
//if we were ordered to exit, bail without wasting any more time
80-
if (exiting)
81-
return;
74+
if (exiting) return;
8275

8376
//try acquiring file
8477
using (var hf = new HawkFile(fn))
8578
{
8679
using (var exe = OSTailoredCode.IsUnixHost ? hf.BindArchiveMember("ffmpeg") : hf.BindFirstOf(".exe"))
8780
{
8881
//last chance. exiting, don't dump the new ffmpeg file
89-
if (exiting)
90-
return;
82+
if (exiting) return;
9183
exe!.GetStream().CopyTo(fs);
9284
fs.Dispose();
9385
if (OSTailoredCode.IsUnixHost)
@@ -110,8 +102,14 @@ private void Download()
110102
}
111103
finally
112104
{
113-
try { File.Delete(fn); }
114-
catch { }
105+
try
106+
{
107+
File.Delete(fn);
108+
}
109+
catch
110+
{
111+
// ignore
112+
}
115113
}
116114
}
117115

@@ -141,8 +139,7 @@ protected override void OnClosed(EventArgs e)
141139
private void timer1_Tick(object sender, EventArgs e)
142140
{
143141
//if it's done, close the window. the user will be smart enough to reopen it
144-
if (succeeded)
145-
Close();
142+
if (succeeded) Close();
146143
if (failed)
147144
{
148145
failed = false;
@@ -155,8 +152,7 @@ private void timer1_Tick(object sender, EventArgs e)
155152

156153
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
157154
{
158-
System.Diagnostics.Process.Start(FFmpegService.Url);
155+
Process.Start(FFmpegService.Url);
159156
}
160157
}
161158
}
162-

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

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System.Diagnostics;
12
using System.IO;
3+
using System.Net;
24
using System.Threading;
35
using System.Windows.Forms;
46

@@ -30,12 +32,13 @@ public RAIntegrationDownloaderForm(string url)
3032
private bool _exiting = false;
3133
private bool _succeeded = false;
3234
private bool _failed = false;
33-
private Thread _thread;
35+
36+
private Thread/*?*/ _thread = null;
3437

3538
public bool DownloadSucceeded()
3639
{
3740
// block until the thread dies
38-
while (_thread?.IsAlive ?? false)
41+
while (_thread is { IsAlive: true })
3942
{
4043
Thread.Sleep(1);
4144
}
@@ -57,23 +60,15 @@ private void Download()
5760
{
5861
using (var evt = new ManualResetEvent(false))
5962
{
60-
using var client = new System.Net.WebClient();
61-
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
63+
using var client = new WebClient();
64+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
6265
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-
};
66+
client.DownloadProgressChanged += (_, progressArgs) => _pct = progressArgs.ProgressPercentage;
67+
client.DownloadFileCompleted += (_, _) => evt.Set(); // we don't really need a status, we'll just try to unzip it when it's done
7268

73-
for (; ; )
69+
while (true)
7470
{
75-
if (evt.WaitOne(10))
76-
break;
71+
if (evt.WaitOne(10)) break;
7772

7873
//if the gui thread ordered an exit, cancel the download and wait for it to acknowledge
7974
if (_exiting)
@@ -85,20 +80,18 @@ private void Download()
8580
}
8681
}
8782

88-
//throw new Exception("test of download failure");
83+
// throw new Exception("test of download failure");
8984

9085
//if we were ordered to exit, bail without wasting any more time
91-
if (_exiting)
92-
return;
86+
if (_exiting) return;
9387

9488
//try acquiring file
9589
using (var dll = new HawkFile(fn))
9690
{
9791
var data = dll!.ReadAllBytes();
9892

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

10396
DirectoryInfo parentDir = new(Path.GetDirectoryName(_path)!);
10497
if (!parentDir.Exists) parentDir.Create();
@@ -114,8 +107,14 @@ private void Download()
114107
}
115108
finally
116109
{
117-
try { File.Delete(fn); }
118-
catch { }
110+
try
111+
{
112+
File.Delete(fn);
113+
}
114+
catch
115+
{
116+
// ignore
117+
}
119118
}
120119
}
121120

@@ -145,8 +144,7 @@ protected override void OnClosed(EventArgs e)
145144
private void timer1_Tick(object sender, EventArgs e)
146145
{
147146
//if it's done, close the window. the user will be smart enough to reopen it
148-
if (_succeeded)
149-
Close();
147+
if (_succeeded) Close();
150148
if (_failed)
151149
{
152150
_failed = false;
@@ -159,8 +157,7 @@ private void timer1_Tick(object sender, EventArgs e)
159157

160158
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
161159
{
162-
System.Diagnostics.Process.Start(_url);
160+
Process.Start(_url);
163161
}
164162
}
165163
}
166-

0 commit comments

Comments
 (0)