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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 250 - (show annotations) (download)
Tue Aug 5 10:16:33 2014 UTC (5 years, 6 months ago) by william
Original Path: trunk/EmuXPortal/Form1.cs
File size: 34656 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22