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 |
try |
180 |
{ |
181 |
rom_flow.VerticalScroll.Value += changeAmount; |
182 |
} |
183 |
catch |
184 |
{ |
185 |
rom_flow.Controls[0].Select(); |
186 |
rom_flow.ScrollControlIntoView(rom_flow.Controls[0]); |
187 |
rom_flow.PerformLayout(); |
188 |
return; |
189 |
} |
190 |
} |
191 |
else |
192 |
{ |
193 |
rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum; |
194 |
} |
195 |
GameControl s = game_ctrl_get_last_visible(); |
196 |
s.Select(); |
197 |
rom_flow.ScrollControlIntoView(s); |
198 |
rom_flow.PerformLayout(); |
199 |
} |
200 |
|
201 |
if (e.KeyCode == Keys.Enter) |
202 |
{ |
203 |
IRomConfig config = c.Tag as IRomConfig; |
204 |
|
205 |
Process p = new Process(); |
206 |
|
207 |
p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe; |
208 |
p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(log, config) : config.Config.GameExeArgs; |
209 |
p.Start(); |
210 |
|
211 |
// minimize EmuXPortal |
212 |
this.WindowState = FormWindowState.Minimized; |
213 |
// wait for exit of game |
214 |
p.WaitForExit(); |
215 |
// maximize EmuXPortal |
216 |
this.WindowState = FormWindowState.Maximized; |
217 |
} |
218 |
if (e.KeyCode == Keys.Back) |
219 |
{ |
220 |
rom_flow.Visible = false; |
221 |
platform_flow.Visible = true; |
222 |
} |
223 |
|
224 |
if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || |
225 |
(e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) |
226 |
{ |
227 |
char t = (char)e.KeyCode; |
228 |
GameControl ctrl = (rom_flow.GetNextControl(CurrentGameControl, true) as GameControl); |
229 |
if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); } |
230 |
bool found = false; |
231 |
GameControl pc = CurrentGameControl; |
232 |
bool wrapped = false; |
233 |
bool not_found = true; |
234 |
while (!found) |
235 |
{ |
236 |
if (wrapped) |
237 |
{ |
238 |
foreach (Control ctl in rom_flow.Controls) |
239 |
{ |
240 |
GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; } |
241 |
} |
242 |
if (not_found) { found = true; } |
243 |
} |
244 |
ctrl = (rom_flow.GetNextControl(pc, true) as GameControl); |
245 |
if (ctrl == null) |
246 |
{ |
247 |
ctrl = rom_flow.Controls[0] as GameControl; |
248 |
wrapped = true; |
249 |
} |
250 |
if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower())) |
251 |
{ |
252 |
rom_flow.ScrollControlIntoView(ctrl); |
253 |
ctrl.Select(); |
254 |
found = true; |
255 |
} |
256 |
pc = ctrl; |
257 |
} |
258 |
} |
259 |
} |
260 |
void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
261 |
{ |
262 |
PlatformControl c = sender as PlatformControl; |
263 |
int changeAmount = 0; |
264 |
int currentPosition = 0; |
265 |
if (e.KeyCode == Keys.Home) |
266 |
{ |
267 |
platform_flow.Controls[0].Select(); |
268 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
269 |
} |
270 |
if (e.KeyCode == Keys.End) |
271 |
{ |
272 |
platform_flow.Controls[platform_flow.Controls.Count -1].Select(); |
273 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[platform_flow.Controls.Count - 1]); |
274 |
} |
275 |
if (e.KeyCode == Keys.PageUp) |
276 |
{ |
277 |
changeAmount = platform_flow.VerticalScroll.LargeChange; |
278 |
currentPosition = platform_flow.VerticalScroll.Value; |
279 |
if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum) |
280 |
{ |
281 |
platform_flow.VerticalScroll.Value -= changeAmount; |
282 |
} |
283 |
else |
284 |
{ |
285 |
platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum; |
286 |
} |
287 |
PlatformControl s = platform_ctrl_get_last_visible(); |
288 |
s.Select(); |
289 |
platform_flow.ScrollControlIntoView(s); |
290 |
platform_flow.PerformLayout(); |
291 |
} |
292 |
if (e.KeyCode == Keys.PageDown) |
293 |
{ |
294 |
changeAmount = platform_flow.VerticalScroll.LargeChange; |
295 |
currentPosition = platform_flow.VerticalScroll.Value; |
296 |
if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum) |
297 |
{ |
298 |
try |
299 |
{ |
300 |
platform_flow.VerticalScroll.Value += changeAmount; |
301 |
} |
302 |
catch |
303 |
{ |
304 |
platform_flow.Controls[0].Select(); |
305 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
306 |
rom_flow.PerformLayout(); |
307 |
return; |
308 |
} |
309 |
} |
310 |
else |
311 |
{ |
312 |
platform_flow.Controls[0].Select(); |
313 |
platform_flow.ScrollControlIntoView(platform_flow.Controls[0]); |
314 |
} |
315 |
PlatformControl s = platform_ctrl_get_last_visible(); |
316 |
s.Select(); |
317 |
platform_flow.ScrollControlIntoView(s); |
318 |
platform_flow.PerformLayout(); |
319 |
} |
320 |
if (e.KeyCode == Keys.Enter) |
321 |
{ |
322 |
// load this platform |
323 |
platform_flow.Visible = false; |
324 |
CurrentSelectedRom = c.Tag as IEmuConfig; |
325 |
rom_flow.Visible = true; |
326 |
rom_flow.BringToFront(); |
327 |
} |
328 |
if (e.KeyCode == Keys.Back) |
329 |
{ |
330 |
this.Close(); |
331 |
} |
332 |
if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || |
333 |
(e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) |
334 |
{ |
335 |
char t = (char)e.KeyCode; |
336 |
PlatformControl ctrl = (platform_flow.GetNextControl(CurrentPlatformControl, true) as PlatformControl); |
337 |
if (ctrl == null) { ctrl = (platform_flow.GetNextControl(platform_flow.Controls[0], true) as PlatformControl); } |
338 |
bool found = false; |
339 |
PlatformControl pc = CurrentPlatformControl; |
340 |
bool wrapped = false; |
341 |
bool not_found = true; |
342 |
while (!found) |
343 |
{ |
344 |
if (wrapped) |
345 |
{ |
346 |
foreach (Control ctl in platform_flow.Controls) |
347 |
{ |
348 |
PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; } |
349 |
} |
350 |
if (not_found) { found = true; } |
351 |
} |
352 |
ctrl = (platform_flow.GetNextControl(pc, true) as PlatformControl); |
353 |
if (ctrl == null) |
354 |
{ |
355 |
ctrl = platform_flow.Controls[0] as PlatformControl; |
356 |
wrapped = true; |
357 |
} |
358 |
if (ctrl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) |
359 |
{ |
360 |
platform_flow.ScrollControlIntoView(ctrl); |
361 |
ctrl.Select(); |
362 |
found = true; |
363 |
} |
364 |
pc = ctrl; |
365 |
} |
366 |
} |
367 |
} |
368 |
|
369 |
private void platform_flow_VisibleChanged(object sender, EventArgs e) |
370 |
{ |
371 |
if (!platform_flow.Visible) return; |
372 |
platform_flow.Controls.Clear(); |
373 |
platform_flow.BringToFront(); |
374 |
Stopwatch t = new Stopwatch(); |
375 |
t.Start(); |
376 |
platformWorker.RunWorkerAsync(t); |
377 |
} |
378 |
|
379 |
private void rom_flow_VisibleChanged(object sender, EventArgs e) |
380 |
{ |
381 |
if (!rom_flow.Visible) return; |
382 |
rom_flow.Controls.Clear(); |
383 |
rom_flow.BringToFront(); |
384 |
Stopwatch t = new Stopwatch(); |
385 |
t.Start(); |
386 |
gameWorker.RunWorkerAsync(t); |
387 |
} |
388 |
|
389 |
void game_ctrl_LostFocus(object sender, EventArgs e) |
390 |
{ |
391 |
GameControl c = sender as GameControl; |
392 |
c.BorderStyle = BorderStyle.None; |
393 |
} |
394 |
|
395 |
void game_ctrl_GotFocus(object sender, EventArgs e) |
396 |
{ |
397 |
GameControl c = sender as GameControl; |
398 |
c.BorderStyle = BorderStyle.FixedSingle; |
399 |
CurrentGameControl = c; |
400 |
} |
401 |
|
402 |
private GameControl game_ctrl_get_last_visible() |
403 |
{ |
404 |
GameControl s = new GameControl(); |
405 |
foreach (GameControl c in rom_flow.Controls) |
406 |
{ |
407 |
if (c.Bounds.IntersectsWith(rom_flow.Bounds)) |
408 |
s = c; |
409 |
} |
410 |
return s; |
411 |
} |
412 |
private PlatformControl platform_ctrl_get_last_visible() |
413 |
{ |
414 |
PlatformControl s = new PlatformControl(); |
415 |
foreach (PlatformControl c in platform_flow.Controls) |
416 |
{ |
417 |
if (c.Bounds.IntersectsWith(platform_flow.Bounds)) |
418 |
s = c; |
419 |
} |
420 |
return s; |
421 |
} |
422 |
|
423 |
|
424 |
#region Background Workers |
425 |
|
426 |
private int GetFormWidth() |
427 |
{ |
428 |
if (this.InvokeRequired) |
429 |
{ |
430 |
return Convert.ToInt32(this.Invoke((MethodInvoker)delegate() { GetFormWidth(); })); |
431 |
} |
432 |
else |
433 |
{ |
434 |
return this.Width; |
435 |
} |
436 |
} |
437 |
private Font GetFormFont() |
438 |
{ |
439 |
if (this.InvokeRequired) |
440 |
{ |
441 |
return (this.Invoke(new Delegate_GetFormFont(GetFormFont)) as Font); |
442 |
} |
443 |
else |
444 |
{ |
445 |
return this.Font; |
446 |
} |
447 |
} |
448 |
|
449 |
private Font ResizeFont(Font font, float size) |
450 |
{ |
451 |
if (this.InvokeRequired) |
452 |
{ |
453 |
return (this.Invoke(new Delegate_ResizeFont(ResizeFont), new object[] { font, size })as Font); |
454 |
} |
455 |
else |
456 |
{ |
457 |
return new Font(font.FontFamily, size); |
458 |
} |
459 |
} |
460 |
|
461 |
//private void AddPlatformControl(Control c) |
462 |
//{ |
463 |
// if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); } |
464 |
// else |
465 |
// { |
466 |
// platform_flow.Controls.Add(c); |
467 |
// } |
468 |
//} |
469 |
//private void UpdatePlatformControls() |
470 |
//{ |
471 |
// //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); } |
472 |
// //else { this.Update(); } |
473 |
//} |
474 |
//private void AddGameControl(Control c) |
475 |
//{ |
476 |
// if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); } |
477 |
// else |
478 |
// { |
479 |
// rom_flow.Controls.Add(c); |
480 |
// } |
481 |
//} |
482 |
//private void UpdateGameControls() |
483 |
//{ |
484 |
// //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); } |
485 |
// //else { this.Update(); } |
486 |
//} |
487 |
#region gameWorker |
488 |
private static Image DefaultGameImage = Properties.Resources.DefaultGameImage; |
489 |
private object gameimage_lock = new object(); |
490 |
private void gameWorker_DoWork(object sender, DoWorkEventArgs e) |
491 |
{ |
492 |
Stopwatch t = e.Argument as Stopwatch; |
493 |
RomParser parser = new RomParser(log, CurrentSelectedRom); |
494 |
|
495 |
CustomProgressBar bar = new CustomProgressBar(); |
496 |
bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE); |
497 |
#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE |
498 |
bar.ShowPercentageLabel = false; |
499 |
#endif |
500 |
bar.ProgressColor = Color.LimeGreen; |
501 |
bar.Dock = DockStyle.Top; |
502 |
|
503 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); } |
504 |
else { this.Controls.Add(bar); } |
505 |
bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); })); |
506 |
|
507 |
double count = 0; |
508 |
double total_count = parser.Roms.Count; |
509 |
foreach (IRomConfig config in parser.Roms) |
510 |
{ |
511 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); })); |
512 |
GameControl game_ctrl = new GameControl(); |
513 |
game_ctrl.Font = GetFormFont(); |
514 |
game_ctrl.Dock = DockStyle.Top; |
515 |
game_ctrl.Width = this.Width - 10; |
516 |
game_ctrl.Tag = config; |
517 |
try |
518 |
{ |
519 |
lock (gameimage_lock) |
520 |
{ |
521 |
game_ctrl.GameImage = config.RomImage == null ? (Image)DefaultGameImage.Clone() : (Image)config.RomImage.Clone(); |
522 |
config.ReleaseRomImageResource(); |
523 |
} |
524 |
} |
525 |
catch (Exception ex) |
526 |
{ |
527 |
throw ex; |
528 |
} |
529 |
if (CurrentSelectedRom.PlatformNameShort == "Favorites") |
530 |
{ |
531 |
//game_ctrl.GameName = config.RomTitle; |
532 |
game_ctrl.GameName = RomFavorite.GetRomTitleFromConfig(config); |
533 |
} |
534 |
else |
535 |
{ |
536 |
game_ctrl.GameName = config.RomTitle; |
537 |
} |
538 |
game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown); |
539 |
game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus); |
540 |
game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus); |
541 |
if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); } |
542 |
else { rom_flow.Controls.Add(game_ctrl); } |
543 |
count++; |
544 |
} |
545 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); })); |
546 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); } |
547 |
e.Result = t; |
548 |
parser.Dispose(); |
549 |
} |
550 |
private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { } |
551 |
private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
552 |
{ |
553 |
Stopwatch t = e.Result as Stopwatch; |
554 |
if (rom_flow.Controls.Count == 0) |
555 |
{ |
556 |
GameControl game_ctrl = new GameControl(); |
557 |
game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown); |
558 |
game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus); |
559 |
game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus); |
560 |
game_ctrl.Font = GetFormFont(); |
561 |
game_ctrl.Dock = DockStyle.Top; |
562 |
game_ctrl.Width = this.Width - 10; |
563 |
game_ctrl.GameName = "You haven't favorited any games, select a game and then press CTRL+F to favorite it"; |
564 |
rom_flow.Controls.Add(game_ctrl); |
565 |
} |
566 |
rom_flow.Controls[0].Select(); |
567 |
t.Stop(); |
568 |
log.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds); |
569 |
} |
570 |
#endregion |
571 |
#region platformWorker |
572 |
private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage; |
573 |
private object platformimage_lock = new object(); |
574 |
private void platformWorker_DoWork(object sender, DoWorkEventArgs e) |
575 |
{ |
576 |
Stopwatch t = e.Argument as Stopwatch; |
577 |
PlatformParser parser = new PlatformParser(log, Config.RomPath); |
578 |
double count = 0; |
579 |
double total_count = parser.Platforms.Count; |
580 |
CustomProgressBar bar = new CustomProgressBar(); |
581 |
bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE); |
582 |
#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE |
583 |
bar.ShowPercentageLabel = false; |
584 |
#endif |
585 |
bar.ProgressColor = Color.LimeGreen; |
586 |
bar.Dock = DockStyle.Top; |
587 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); } |
588 |
else { this.Controls.Add(bar); } |
589 |
bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); })); |
590 |
foreach (IEmuConfig config in parser.Platforms) |
591 |
{ |
592 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); })); |
593 |
|
594 |
PlatformControl platform_ctrl = new PlatformControl(); |
595 |
platform_ctrl.Font = GetFormFont(); |
596 |
platform_ctrl.Dock = DockStyle.Top; |
597 |
platform_ctrl.Width = this.Width - 10; |
598 |
platform_ctrl.Tag = config; |
599 |
try |
600 |
{ |
601 |
lock (platformimage_lock) |
602 |
{ |
603 |
platform_ctrl.PlatformImage = config.PlatformImage == null ? (Image)DefaultPlatformImage.Clone() : (Image)config.PlatformImage.Clone(); |
604 |
config.ReleasePlatformImageResource(); |
605 |
} |
606 |
} |
607 |
catch (Exception ex) |
608 |
{ |
609 |
throw ex; |
610 |
} |
611 |
platform_ctrl.PlatformName = config.ToString(); |
612 |
platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown); |
613 |
platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus); |
614 |
platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus); |
615 |
if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); } |
616 |
else { platform_flow.Controls.Add(platform_ctrl); } |
617 |
count++; |
618 |
} |
619 |
bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); })); |
620 |
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); } |
621 |
e.Result = t; |
622 |
parser.Dispose(); |
623 |
} |
624 |
private void platformWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { } |
625 |
private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
626 |
{ |
627 |
Stopwatch t = e.Result as Stopwatch; |
628 |
if (platform_flow.Controls.Count == 0) |
629 |
{ |
630 |
PlatformControl platform_ctrl = new PlatformControl(); |
631 |
platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown); |
632 |
platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus); |
633 |
platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus); |
634 |
platform_ctrl.Font = GetFormFont(); |
635 |
platform_ctrl.Dock = DockStyle.Top; |
636 |
platform_ctrl.Width = this.Width - 10; |
637 |
platform_ctrl.PlatformName = string.Format("You don't have any roms in your rompath: '{0}'",Config.RomPath); |
638 |
platform_flow.Controls.Add(platform_ctrl); |
639 |
} |
640 |
platform_flow.Controls[0].Select(); |
641 |
log.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds); |
642 |
} |
643 |
#endregion |
644 |
|
645 |
private void Form1_FormClosed(object sender, FormClosedEventArgs e) |
646 |
{ |
647 |
Cursor.Show(); |
648 |
log.CloseLog(); |
649 |
} |
650 |
#endregion |
651 |
} |
652 |
} |