/[EmuXPortal]/trunk/EmuXPortal/Form1.cs
ViewVC logotype

Annotation of /trunk/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 248 - (hide annotations) (download)
Tue Aug 5 09:20:39 2014 UTC (5 years, 11 months ago) by william
File size: 34159 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22