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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 238 - (hide annotations) (download)
Tue Aug 5 04:50:39 2014 UTC (5 years, 6 months ago) by william
Original Path: trunk/EmuXPortal/Form1.cs
File size: 30109 byte(s)
+ use Enterprise.Logging instead of EmuXPortal.Logging

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

  ViewVC Help
Powered by ViewVC 1.1.22