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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 251 - (hide annotations) (download)
Tue Aug 5 12:32:13 2014 UTC (5 years, 6 months ago) by william
Original Path: trunk/EmuXPortal/Form1.cs
File size: 34943 byte(s)

1 william 251 #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 william 249
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 william 243 #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 william 4 public Form1()
71     {
72 william 243 InitializeComponent();
73    
74    
75 william 238 #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 william 243 #region unhandled exception support
104     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
105     Application.ThreadException += Application_Unhandled_ThreadException;
106     #endregion
107    
108 william 17 platform_flow.Dock = DockStyle.Fill;
109     rom_flow.Dock = DockStyle.Fill;
110 william 248
111     platform_flow.MaxiumControlsToRender = 5;
112     rom_flow.MaxiumControlsToRender = 5;
113 william 238 }
114 william 243
115    
116    
117    
118 william 238 #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 william 184
130 william 17 private void Form1_Load(object sender, EventArgs e)
131     {
132 william 238 Config.LoadConfig();
133     Config.InitializePresentationForm(this);
134 william 17 }
135 william 181 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 william 249 //void platform_ctrl_LostFocus(object sender, EventArgs e)
145     //{
146     // PlatformControl c = sender as PlatformControl;
147     // c.BorderStyle = BorderStyle.None;
148     //}
149 william 13
150 william 249 //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 william 17
160 william 249 //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 william 168
226 william 249 //}
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 william 168
299 william 249 //if (e.KeyCode == Keys.Enter)
300     //{
301     // IRomConfig config = c.Tag as IRomConfig;
302 william 168
303 william 249 // Process p = new Process();
304 william 168
305 william 249 // 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 william 168
309 william 249 // // 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 william 168
322 william 249 //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 william 17
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 william 37 Stopwatch t = new Stopwatch();
483     t.Start();
484 william 60 platformWorker.RunWorkerAsync(t);
485 william 17 }
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 william 37 Stopwatch t = new Stopwatch();
493     t.Start();
494 william 60 gameWorker.RunWorkerAsync(t);
495 william 17 }
496    
497 william 249 //void game_ctrl_LostFocus(object sender, EventArgs e)
498     //{
499     // GameControl c = sender as GameControl;
500     // c.BorderStyle = BorderStyle.None;
501     //}
502 william 17
503 william 249 //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 william 17
510 william 249 //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 william 168
531 william 60
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 william 183 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 william 113 //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 william 60 #region gameWorker
596 william 110 private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
597 william 137 private object gameimage_lock = new object();
598 william 60 private void gameWorker_DoWork(object sender, DoWorkEventArgs e)
599     {
600     Stopwatch t = e.Argument as Stopwatch;
601 william 238 RomParser parser = new RomParser(CurrentSelectedRom);
602 william 60
603 william 183 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 william 246 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.SuspendLayout(); }); } else { rom_flow.SuspendLayout(); }
612    
613 william 183 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 william 60
617     double count = 0;
618     double total_count = parser.Roms.Count;
619     foreach (IRomConfig config in parser.Roms)
620     {
621 william 183 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
622 william 60 GameControl game_ctrl = new GameControl();
623 william 183 game_ctrl.Font = GetFormFont();
624 william 60 game_ctrl.Dock = DockStyle.Top;
625     game_ctrl.Width = this.Width - 10;
626     game_ctrl.Tag = config;
627 william 137 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 william 178 }
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 william 183 }
648 william 249 //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 william 113 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); }
652     else { rom_flow.Controls.Add(game_ctrl); }
653 william 60 count++;
654     }
655 william 183 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 william 60 e.Result = t;
658 william 246 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.ResumeLayout(false); }); } else { rom_flow.ResumeLayout(false); }
659 william 105 parser.Dispose();
660 william 60 }
661     private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
662     private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
663     {
664 william 197 Stopwatch t = e.Result as Stopwatch;
665 william 198 if (rom_flow.Controls.Count == 0)
666 william 197 {
667     GameControl game_ctrl = new GameControl();
668 william 249 //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 william 197 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 william 249 //rom_flow.Controls[0].Select();
678 william 250 rom_flow.Focus();
679 william 60 t.Stop();
680 william 238 gLog.Profiler.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
681 william 60 }
682     #endregion
683     #region platformWorker
684 william 110 private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
685 william 137 private object platformimage_lock = new object();
686 william 60 private void platformWorker_DoWork(object sender, DoWorkEventArgs e)
687     {
688     Stopwatch t = e.Argument as Stopwatch;
689 william 238 PlatformParser parser = new PlatformParser(Config.RomPath);
690 william 60 double count = 0;
691     double total_count = parser.Platforms.Count;
692 william 183 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 william 246
700     if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.SuspendLayout(); }); } else { platform_flow.SuspendLayout(); }
701    
702 william 183 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 william 60 foreach (IEmuConfig config in parser.Platforms)
706     {
707 william 183 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
708    
709 william 60 PlatformControl platform_ctrl = new PlatformControl();
710 william 183 platform_ctrl.Font = GetFormFont();
711 william 60 platform_ctrl.Dock = DockStyle.Top;
712     platform_ctrl.Width = this.Width - 10;
713     platform_ctrl.Tag = config;
714 william 137 try
715     {
716     lock (platformimage_lock)
717     {
718 william 138 platform_ctrl.PlatformImage = config.PlatformImage == null ? (Image)DefaultPlatformImage.Clone() : (Image)config.PlatformImage.Clone();
719 william 137 config.ReleasePlatformImageResource();
720     }
721     }
722     catch (Exception ex)
723     {
724     throw ex;
725     }
726 william 60 platform_ctrl.PlatformName = config.ToString();
727 william 249 //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 william 113 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); }
731 william 183 else { platform_flow.Controls.Add(platform_ctrl); }
732 william 60 count++;
733     }
734 william 183 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 william 60 e.Result = t;
737 william 246 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.ResumeLayout(false); }); } else { platform_flow.ResumeLayout(false); }
738 william 105 parser.Dispose();
739 william 60 }
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 william 198 if (platform_flow.Controls.Count == 0)
745 william 197 {
746     PlatformControl platform_ctrl = new PlatformControl();
747 william 249 //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 william 197 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 william 249 //platform_flow.Controls[0].Select();
757 william 251 platform_flow.Dock = DockStyle.Fill;
758 william 250 platform_flow.Focus();
759 william 238 gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
760 william 60 }
761     #endregion
762    
763     private void Form1_FormClosed(object sender, FormClosedEventArgs e)
764     {
765     Cursor.Show();
766     }
767     #endregion
768 william 251
769     private void platform_flow_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
770     {
771    
772     }
773    
774     private void rom_flow_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
775     {
776    
777     }
778    
779    
780 william 4 }
781     }

  ViewVC Help
Powered by ViewVC 1.1.22