/[EmuXPortal]/branches/mono/EmuXPortal/Form1.cs
ViewVC logotype

Contents of /branches/mono/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 241 - (show annotations) (download)
Tue Aug 5 05:19:39 2014 UTC (5 years, 6 months ago) by william
Original Path: trunk/EmuXPortal/Form1.cs
File size: 30354 byte(s)
+ update log state (using Info, Warn, Debug, and Error) as needed

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

  ViewVC Help
Powered by ViewVC 1.1.22