ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/EmuXPortal/trunk/EmuXPortal/Form1.cs
Revision: 238
Committed: Tue Aug 5 04:50:39 2014 UTC (9 years, 3 months ago) by william
File size: 30109 byte(s)
Log Message:
+ use Enterprise.Logging instead of EmuXPortal.Logging

File Contents

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