1 |
//#define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden |
2 |
//#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar |
3 |
using System; |
4 |
using System.Collections.Generic; |
5 |
using System.ComponentModel; |
6 |
using System.Data; |
7 |
using System.Drawing; |
8 |
using System.Linq; |
9 |
using System.Text; |
10 |
using System.Windows.Forms; |
11 |
using EmuXPortal.Api; |
12 |
using EmuXPortal.Logging; |
13 |
using System.Diagnostics; |
14 |
using System.Reflection; |
15 |
using System.Threading; |
16 |
using Utilities.TransparentControls; |
17 |
|
18 |
namespace EmuXPortal |
19 |
{ |
20 |
public partial class Form1 : Form |
21 |
{ |
22 |
const float PROGRESS_BAR_FONT_SIZE = 24; |
23 |
private delegate Font Delegate_GetFormFont(); |
24 |
private delegate Font Delegate_ResizeFont(Font font, float size); |
25 |
IEmuConfig CurrentSelectedRom = null; |
26 |
PlatformControl CurrentPlatformControl = null; |
27 |
GameControl CurrentGameControl = null; |
28 |
logger log = new logger(); |
29 |
public Form1() |
30 |
{ |
31 |
InitializeComponent(); |
32 |
platform_flow.Dock = DockStyle.Fill; |
33 |
rom_flow.Dock = DockStyle.Fill; |
34 |
|
35 |
log.OpenLog(); |
36 |
} |
37 |
|
38 |
private void Form1_Load(object sender, EventArgs e) |
39 |
{ |
40 |
Config.LoadConfig(log); |
41 |
Config.InitializePresentationForm(log,this); |
42 |
} |
43 |
private void Form1_Shown(object sender, EventArgs e) |
44 |
{ |
45 |
platform_flow.Visible = true; |
46 |
#if !DISABLE_CURSOR_HIDE |
47 |
Cursor.Hide(); |
48 |
#else |
49 |
Cursor.Show(); |
50 |
#endif |
51 |
} |
52 |
void platform_ctrl_LostFocus(object sender, EventArgs e) |
53 |
{ |
54 |
PlatformControl c = sender as PlatformControl; |
55 |
c.BorderStyle = BorderStyle.None; |
56 |
} |
57 |
|
58 |
void platform_ctrl_GotFocus(object sender, EventArgs e) |
59 |
{ |
60 |
PlatformControl c = sender as PlatformControl; |
61 |
c.BorderStyle = BorderStyle.FixedSingle; |
62 |
CurrentPlatformControl = c; |
63 |
} |
64 |
void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
65 |
{ |
66 |
GameControl c = sender as GameControl; |
67 |
|
68 |
int changeAmount = 0; |
69 |
int currentPosition = 0; |
70 |
if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control) |
71 |
{ |
72 |
IRomConfig config = c.Tag as IRomConfig; |
73 |
if (config == null) |
74 |
{ |
75 |
log.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile); |
76 |
} |
77 |
else |
78 |
{ |
79 |
var isFavorite = RomFavorite.IsFavorite(log, config); |
80 |
if (isFavorite) |
81 |
{ |
82 |
// add to favorites |
83 |
log.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
84 |
if (!RomFavorite.RemoveFavorite(log, config)) |
85 |
{ |
86 |
log.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
87 |
} |
88 |
else |
89 |
{ |
90 |
log.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
91 |
if (config.Config.PlatformNameShort == "Favorites") |
92 |
{ |
93 |
var parent = c.Parent; |
94 |
if (parent != null) |
95 |
{ |
96 |
parent.Controls.Remove(c); |
97 |
if (parent.Controls.Count > 0) |
98 |
{ |
99 |
var next_ctrl = parent.Controls[0]; |
100 |
if (next_ctrl != null) |
101 |
{ |
102 |
next_ctrl.Select(); |
103 |
} |
104 |
} |
105 |
} |
106 |
} |
107 |
} |
108 |
} |
109 |
else |
110 |
{ |
111 |
// add to favorites |
112 |
log.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
113 |
if (!RomFavorite.AddFavorite(log,config)) |
114 |
{ |
115 |
log.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
116 |
} |
117 |
else |
118 |
{ |
119 |
log.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
120 |
} |
121 |
} |
122 |
log.WriteLine("Updateing favorites"); |
123 |
if (!RomFavorite.UpdateFavorites(log)) |
124 |
{ |
125 |
log.WriteLine("Failed to update favorites"); |
126 |
} |
127 |
else |
128 |
{ |
129 |
log.WriteLine("Updated favorites"); |
130 |
} |
131 |
} |
132 |
return; // stop processing other keys |
133 |
|
134 |
} |
135 |
if (e.KeyCode == Keys.Home) |
136 |
{ |
137 |
rom_flow.Controls[0].Select(); |
138 |
rom_flow.ScrollControlIntoView(rom_flow.Controls[0]); |
139 |
} |
140 |
if (e.KeyCode == Keys.End) |
141 |
{ |
142 |
rom_flow.Controls[rom_flow.Controls.Count - 1].Select(); |
143 |
rom_flow.ScrollControlIntoView(rom_flow.Controls[rom_flow.Controls.Count - 1]); |
144 |
} |
145 |
if (e.KeyCode == Keys.PageUp) |
146 |
{ |
147 |
changeAmount = rom_flow.VerticalScroll.LargeChange; |
148 |
currentPosition = rom_flow.VerticalScroll.Value; |
149 |
if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum) |
150 |
{ |
151 |
try |
152 |
{ |
153 |
rom_flow.VerticalScroll.Value -= changeAmount; |
154 |
} |
155 |
catch |
156 |
{ |
157 |
rom_flow.Controls[0].Select(); |
158 |
rom_flow.ScrollControlIntoView(rom_flow.Controls[0]); |
159 |
rom_flow.PerformLayout(); |
160 |
return; |
161 |
} |
162 |
} |
163 |
else |
164 |
{ |
165 |
rom_flow.Controls[0].Select(); |
166 |
rom_flow.ScrollControlIntoView(rom_flow.Controls[0]); |
167 |
} |
168 |
GameControl s = game_ctrl_get_last_visible(); |
169 |
s.Select(); |
170 |
rom_flow.ScrollControlIntoView(s); |
171 |
rom_flow.PerformLayout(); |
172 |
} |
173 |
if (e.KeyCode == Keys.PageDown) |
174 |
{ |
175 |
changeAmount = rom_flow.VerticalScroll.LargeChange; |
176 |
currentPosition = rom_flow.VerticalScroll.Value; |
177 |
if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum) |
178 |
{ |
179 |
rom_flow.VerticalScroll.Value += changeAmount; |
180 |
} |
181 |
else |
182 |
{ |
183 |
rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum; |
184 |
} |
185 |
GameControl s = game_ctrl_get_last_visible(); |
186 |
s.Select(); |
187 |
rom_flow.ScrollControlIntoView(s); |
188 |
rom_flow.PerformLayout(); |
189 |
} |
190 |
|
191 |
if (e.KeyCode == Keys.Enter) |
192 |
{ |
193 |
IRomConfig config = c.Tag as IRomConfig; |
194 |
|
195 |
Process p = new Process(); |
196 |
|
197 |
p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe; |
198 |
p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(log, config) : config.Config.GameExeArgs; |
199 |
p.Start(); |
200 |
|
201 |
// minimize EmuXPortal |
202 |
this.WindowState = FormWindowState.Minimized; |
203 |
// wait for exit of game |
204 |
p.WaitForExit(); |
205 |
// maximize EmuXPortal |
206 |
this.WindowState = FormWindowState.Maximized; |
207 |
} |
208 |
if (e.KeyCode == Keys.Back) |
209 |
{ |
210 |
rom_flow.Visible = false; |
211 |
platform_flow.Visible = true; |
212 |
} |
213 |
|
214 |
if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || |
215 |
(e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) |
216 |
{ |
217 |
char t = (char)e.KeyCode; |
218 |
GameControl ctrl = (rom_flow.GetNextControl(CurrentGameControl, true) as GameControl); |
219 |
if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); } |
220 |
bool found = false; |
221 |
GameControl pc = CurrentGameControl; |
222 |
bool wrapped = false; |
223 |
bool not_found = true; |
224 |
while (!found) |
225 |
{ |
226 |
if (wrapped) |
227 |
{ |
228 |
foreach (Control ctl in rom_flow.Controls) |
229 |
{ |
230 |
GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; } |
231 |
} |
232 |
if (not_found) { found = true; } |
233 |
} |
234 |
ctrl = (rom_flow.GetNextControl(pc, true) as GameControl); |
235 |
if (ctrl == null) |
236 |
{ |
237 |
ctrl = rom_flow.Controls[0] as GameControl; |
238 |
wrapped = true; |
239 |
} |
240 |
if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower())) |
241 |
{ |
242 |
rom_flow.ScrollControlIntoView(ctrl); |
243 |
ctrl.Select(); |
244 |
found = true; |
245 |
} |
246 |
pc = ctrl; |
247 |
} |
248 |
} |
249 |
} |
250 |
void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
251 |
{ |
252 |
PlatformControl c = sender as PlatformControl; |
253 |
int changeAmount = 0; |
254 |
int currentPosition = 0; |
255 |
if (e.KeyCode == Keys.Home) |
256 |
{ |
257 |
platform_flow.Controls[0].Select(); |
258 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
259 |
} |
260 |
if (e.KeyCode == Keys.End) |
261 |
{ |
262 |
platform_flow.Controls[platform_flow.Controls.Count -1].Select(); |
263 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[platform_flow.Controls.Count - 1]); |
264 |
} |
265 |
if (e.KeyCode == Keys.PageUp) |
266 |
{ |
267 |
changeAmount = platform_flow.VerticalScroll.LargeChange; |
268 |
currentPosition = platform_flow.VerticalScroll.Value; |
269 |
if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum) |
270 |
{ |
271 |
platform_flow.VerticalScroll.Value -= changeAmount; |
272 |
} |
273 |
else |
274 |
{ |
275 |
platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum; |
276 |
} |
277 |
PlatformControl s = platform_ctrl_get_last_visible(); |
278 |
s.Select(); |
279 |
platform_flow.ScrollControlIntoView(s); |
280 |
platform_flow.PerformLayout(); |
281 |
} |
282 |
if (e.KeyCode == Keys.PageDown) |
283 |
{ |
284 |
changeAmount = platform_flow.VerticalScroll.LargeChange; |
285 |
currentPosition = platform_flow.VerticalScroll.Value; |
286 |
if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum) |
287 |
{ |
288 |
try |
289 |
{ |
290 |
platform_flow.VerticalScroll.Value += changeAmount; |
291 |
} |
292 |
catch |
293 |
{ |
294 |
platform_flow.Controls[0].Select(); |
295 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
296 |
rom_flow.PerformLayout(); |
297 |
return; |
298 |
} |
299 |
} |
300 |
else |
301 |
{ |
302 |
platform_flow.Controls[0].Select(); |
303 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
304 |
} |
305 |
PlatformControl s = platform_ctrl_get_last_visible(); |
306 |
s.Select(); |
307 |
platform_flow.ScrollControlIntoView(s); |
308 |
platform_flow.PerformLayout(); |
309 |
} |
310 |
if (e.KeyCode == Keys.Enter) |
311 |
{ |
312 |
// load this platform |
313 |
platform_flow.Visible = false; |
314 |
CurrentSelectedRom = c.Tag as IEmuConfig; |
315 |
rom_flow.Visible = true; |
316 |
rom_flow.BringToFront(); |
317 |
} |
318 |
if (e.KeyCode == Keys.Back) |
319 |
{ |
320 |
this.Close(); |
321 |
} |
322 |
if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || |
323 |
(e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) |
324 |
{ |
325 |
char t = (char)e.KeyCode; |
326 |
PlatformControl ctrl = (platform_flow.GetNextControl(CurrentPlatformControl, true) as PlatformControl); |
327 |
if (ctrl == null) { ctrl = (platform_flow.GetNextControl(platform_flow.Controls[0], true) as PlatformControl); } |
328 |
bool found = false; |
329 |
PlatformControl pc = CurrentPlatformControl; |
330 |
bool wrapped = false; |
331 |
bool not_found = true; |
332 |
while (!found) |
333 |
{ |
334 |
if (wrapped) |
335 |
{ |
336 |
foreach (Control ctl in platform_flow.Controls) |
337 |
{ |
338 |
PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; } |
339 |
} |
340 |
if (not_found) { found = true; } |
341 |
} |
342 |
ctrl = (platform_flow.GetNextControl(pc, true) as PlatformControl); |
343 |
if (ctrl == null) |
344 |
{ |
345 |
ctrl = platform_flow.Controls[0] as PlatformControl; |
346 |
wrapped = true; |
347 |
} |
348 |
if (ctrl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) |
349 |
{ |
350 |
platform_flow.ScrollControlIntoView(ctrl); |
351 |
ctrl.Select(); |
352 |
found = true; |
353 |
} |
354 |
pc = ctrl; |
355 |
} |
356 |
} |
357 |
} |
358 |
|
359 |
private void platform_flow_VisibleChanged(object sender, EventArgs e) |
360 |
{ |
361 |
if (!platform_flow.Visible) return; |
362 |
platform_flow.Controls.Clear(); |
363 |
platform_flow.BringToFront(); |
364 |
Stopwatch t = new Stopwatch(); |
365 |
t.Start(); |
366 |
platformWorker.RunWorkerAsync(t); |
367 |
} |
368 |
|
369 |
private void rom_flow_VisibleChanged(object sender, EventArgs e) |
370 |
{ |
371 |
if (!rom_flow.Visible) return; |
372 |
rom_flow.Controls.Clear(); |
373 |
rom_flow.BringToFront(); |
374 |
Stopwatch t = new Stopwatch(); |
375 |
t.Start(); |
376 |
gameWorker.RunWorkerAsync(t); |
377 |
} |
378 |
|
379 |
void game_ctrl_LostFocus(object sender, EventArgs e) |
380 |
{ |
381 |
GameControl c = sender as GameControl; |
382 |
c.BorderStyle = BorderStyle.None; |
383 |
} |
384 |
|
385 |
void game_ctrl_GotFocus(object sender, EventArgs e) |
386 |
{ |
387 |
GameControl c = sender as GameControl; |
388 |
c.BorderStyle = BorderStyle.FixedSingle; |
389 |
CurrentGameControl = c; |
390 |
} |
391 |
|
392 |
private GameControl game_ctrl_get_last_visible() |
393 |
{ |
394 |
GameControl s = new GameControl(); |
395 |
foreach (GameControl c in rom_flow.Controls) |
396 |
{ |
397 |
if (c.Bounds.IntersectsWith(rom_flow.Bounds)) |
398 |
s = c; |
399 |
} |
400 |
return s; |
401 |
} |
402 |
private PlatformControl platform_ctrl_get_last_visible() |
403 |
{ |
404 |
PlatformControl s = new PlatformControl(); |
405 |
foreach (PlatformControl c in platform_flow.Controls) |
406 |
{ |
407 |
if (c.Bounds.IntersectsWith(platform_flow.Bounds)) |
408 |
s = c; |
409 |
} |
410 |
return s; |
411 |
} |
412 |
|
413 |
|
414 |
#region Background Workers |
415 |
|
416 |
private int GetFormWidth() |
417 |
{ |
418 |
if (this.InvokeRequired) |
419 |
{ |
420 |
return Convert.ToInt32(this.Invoke((MethodInvoker)delegate() { GetFormWidth(); })); |
421 |
} |
422 |
else |
423 |
{ |
424 |
return this.Width; |
425 |
} |
426 |
} |
427 |
private Font GetFormFont() |
428 |
{ |
429 |
if (this.InvokeRequired) |
430 |
{ |
431 |
return (this.Invoke(new Delegate_GetFormFont(GetFormFont)) as Font); |
432 |
} |
433 |
else |
434 |
{ |
435 |
return this.Font; |
436 |
} |
437 |
} |
438 |
|
439 |
private Font ResizeFont(Font font, float size) |
440 |
{ |
441 |
if (this.InvokeRequired) |
442 |
{ |
443 |
return (this.Invoke(new Delegate_ResizeFont(ResizeFont), new object[] { font, size })as Font); |
444 |
} |
445 |
else |
446 |
{ |
447 |
return new Font(font.FontFamily, size); |
448 |
} |
449 |
} |
450 |
|
451 |
//private void AddPlatformControl(Control c) |
452 |
//{ |
453 |
// if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); } |
454 |
// else |
455 |
// { |
456 |
// platform_flow.Controls.Add(c); |
457 |
// } |
458 |
//} |
459 |
//private void UpdatePlatformControls() |
460 |
//{ |
461 |
// //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); } |
462 |
// //else { this.Update(); } |
463 |
//} |
464 |
//private void AddGameControl(Control c) |
465 |
//{ |
466 |
// if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); } |
467 |
// else |
468 |
// { |
469 |
// rom_flow.Controls.Add(c); |
470 |
// } |
471 |
//} |
472 |
//private void UpdateGameControls() |
473 |
//{ |
474 |
// //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); } |
475 |
// //else { this.Update(); } |
476 |
//} |
477 |
#region gameWorker |
478 |
private static Image DefaultGameImage = Properties.Resources.DefaultGameImage; |
479 |
private object gameimage_lock = new object(); |
480 |
private void gameWorker_DoWork(object sender, DoWorkEventArgs e) |
481 |
{ |
482 |
Stopwatch t = e.Argument as Stopwatch; |
483 |
RomParser parser = new RomParser(log, CurrentSelectedRom); |
484 |
|
485 |
CustomProgressBar bar = new CustomProgressBar(); |
486 |
bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE); |
487 |
#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE |
488 |
bar.ShowPercentageLabel = false; |
489 |
#endif |
490 |
bar.ProgressColor = Color.LimeGreen; |
491 |
bar.Dock = DockStyle.Top; |
492 |
|
493 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); } |
494 |
else { this.Controls.Add(bar); } |
495 |
bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); })); |
496 |
|
497 |
double count = 0; |
498 |
double total_count = parser.Roms.Count; |
499 |
foreach (IRomConfig config in parser.Roms) |
500 |
{ |
501 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); })); |
502 |
GameControl game_ctrl = new GameControl(); |
503 |
game_ctrl.Font = GetFormFont(); |
504 |
game_ctrl.Dock = DockStyle.Top; |
505 |
game_ctrl.Width = this.Width - 10; |
506 |
game_ctrl.Tag = config; |
507 |
try |
508 |
{ |
509 |
lock (gameimage_lock) |
510 |
{ |
511 |
game_ctrl.GameImage = config.RomImage == null ? (Image)DefaultGameImage.Clone() : (Image)config.RomImage.Clone(); |
512 |
config.ReleaseRomImageResource(); |
513 |
} |
514 |
} |
515 |
catch (Exception ex) |
516 |
{ |
517 |
throw ex; |
518 |
} |
519 |
if (CurrentSelectedRom.PlatformNameShort == "Favorites") |
520 |
{ |
521 |
//game_ctrl.GameName = config.RomTitle; |
522 |
game_ctrl.GameName = RomFavorite.GetRomTitleFromConfig(config); |
523 |
} |
524 |
else |
525 |
{ |
526 |
game_ctrl.GameName = config.RomTitle; |
527 |
} |
528 |
game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown); |
529 |
game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus); |
530 |
game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus); |
531 |
if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); } |
532 |
else { rom_flow.Controls.Add(game_ctrl); } |
533 |
count++; |
534 |
} |
535 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); })); |
536 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); } |
537 |
e.Result = t; |
538 |
parser.Dispose(); |
539 |
} |
540 |
private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { } |
541 |
private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
542 |
{ |
543 |
Stopwatch t = e.Result as Stopwatch; |
544 |
if (rom_flow.Controls.Count == 0) |
545 |
{ |
546 |
GameControl game_ctrl = new GameControl(); |
547 |
game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown); |
548 |
game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus); |
549 |
game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus); |
550 |
game_ctrl.Font = GetFormFont(); |
551 |
game_ctrl.Dock = DockStyle.Top; |
552 |
game_ctrl.Width = this.Width - 10; |
553 |
game_ctrl.GameName = "You haven't favorited any games, select a game and then press CTRL+F to favorite it"; |
554 |
rom_flow.Controls.Add(game_ctrl); |
555 |
} |
556 |
rom_flow.Controls[0].Select(); |
557 |
t.Stop(); |
558 |
log.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds); |
559 |
} |
560 |
#endregion |
561 |
#region platformWorker |
562 |
private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage; |
563 |
private object platformimage_lock = new object(); |
564 |
private void platformWorker_DoWork(object sender, DoWorkEventArgs e) |
565 |
{ |
566 |
Stopwatch t = e.Argument as Stopwatch; |
567 |
PlatformParser parser = new PlatformParser(log, Config.RomPath); |
568 |
double count = 0; |
569 |
double total_count = parser.Platforms.Count; |
570 |
CustomProgressBar bar = new CustomProgressBar(); |
571 |
bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE); |
572 |
#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE |
573 |
bar.ShowPercentageLabel = false; |
574 |
#endif |
575 |
bar.ProgressColor = Color.LimeGreen; |
576 |
bar.Dock = DockStyle.Top; |
577 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); } |
578 |
else { this.Controls.Add(bar); } |
579 |
bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); })); |
580 |
foreach (IEmuConfig config in parser.Platforms) |
581 |
{ |
582 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); })); |
583 |
|
584 |
PlatformControl platform_ctrl = new PlatformControl(); |
585 |
platform_ctrl.Font = GetFormFont(); |
586 |
platform_ctrl.Dock = DockStyle.Top; |
587 |
platform_ctrl.Width = this.Width - 10; |
588 |
platform_ctrl.Tag = config; |
589 |
try |
590 |
{ |
591 |
lock (platformimage_lock) |
592 |
{ |
593 |
platform_ctrl.PlatformImage = config.PlatformImage == null ? (Image)DefaultPlatformImage.Clone() : (Image)config.PlatformImage.Clone(); |
594 |
config.ReleasePlatformImageResource(); |
595 |
} |
596 |
} |
597 |
catch (Exception ex) |
598 |
{ |
599 |
throw ex; |
600 |
} |
601 |
platform_ctrl.PlatformName = config.ToString(); |
602 |
platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown); |
603 |
platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus); |
604 |
platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus); |
605 |
if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); } |
606 |
else { platform_flow.Controls.Add(platform_ctrl); } |
607 |
count++; |
608 |
} |
609 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); })); |
610 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); } |
611 |
e.Result = t; |
612 |
parser.Dispose(); |
613 |
} |
614 |
private void platformWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { } |
615 |
private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
616 |
{ |
617 |
Stopwatch t = e.Result as Stopwatch; |
618 |
if (platform_flow.Controls.Count == 0) |
619 |
{ |
620 |
PlatformControl platform_ctrl = new PlatformControl(); |
621 |
platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown); |
622 |
platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus); |
623 |
platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus); |
624 |
platform_ctrl.Font = GetFormFont(); |
625 |
platform_ctrl.Dock = DockStyle.Top; |
626 |
platform_ctrl.Width = this.Width - 10; |
627 |
platform_ctrl.PlatformName = string.Format("You don't have any roms in your rompath: '{0}'",Config.RomPath); |
628 |
platform_flow.Controls.Add(platform_ctrl); |
629 |
} |
630 |
platform_flow.Controls[0].Select(); |
631 |
log.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds); |
632 |
} |
633 |
#endregion |
634 |
|
635 |
private void Form1_FormClosed(object sender, FormClosedEventArgs e) |
636 |
{ |
637 |
Cursor.Show(); |
638 |
log.CloseLog(); |
639 |
} |
640 |
#endregion |
641 |
} |
642 |
} |