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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 246 - (hide annotations) (download)
Tue Aug 5 06:33:52 2014 UTC (5 years, 6 months ago) by william
Original Path: trunk/EmuXPortal/Form1.cs
File size: 33378 byte(s)
flowlayoutpanels: call SuspendLayout(); and ResumeLayout(false); as needed

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

  ViewVC Help
Powered by ViewVC 1.1.22