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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22