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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22