9 |
|
using System.Text; |
10 |
|
using System.Windows.Forms; |
11 |
|
using EmuXPortal.Api; |
12 |
– |
using EmuXPortal.Logging; |
12 |
|
using System.Diagnostics; |
13 |
|
using System.Reflection; |
14 |
|
using System.Threading; |
15 |
|
using Utilities.TransparentControls; |
16 |
+ |
using Enterprise.Logging; |
17 |
+ |
using System.IO; |
18 |
|
|
19 |
|
namespace EmuXPortal |
20 |
|
{ |
26 |
|
IEmuConfig CurrentSelectedRom = null; |
27 |
|
PlatformControl CurrentPlatformControl = null; |
28 |
|
GameControl CurrentGameControl = null; |
28 |
– |
logger log = new logger(); |
29 |
|
public Form1() |
30 |
|
{ |
31 |
< |
InitializeComponent(); |
31 |
> |
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 |
|
platform_flow.Dock = DockStyle.Fill; |
61 |
|
rom_flow.Dock = DockStyle.Fill; |
34 |
– |
|
35 |
– |
log.OpenLog(); |
62 |
|
} |
63 |
< |
|
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 |
> |
|
75 |
|
private void Form1_Load(object sender, EventArgs e) |
76 |
|
{ |
77 |
< |
Config.LoadConfig(log); |
78 |
< |
Config.InitializePresentationForm(log,this); |
77 |
> |
Config.LoadConfig(); |
78 |
> |
Config.InitializePresentationForm(this); |
79 |
|
} |
80 |
|
private void Form1_Shown(object sender, EventArgs e) |
81 |
|
{ |
109 |
|
IRomConfig config = c.Tag as IRomConfig; |
110 |
|
if (config == null) |
111 |
|
{ |
112 |
< |
log.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile); |
112 |
> |
gLog.Debug.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile); |
113 |
|
} |
114 |
|
else |
115 |
|
{ |
116 |
< |
var isFavorite = RomFavorite.IsFavorite(log, config); |
116 |
> |
var isFavorite = RomFavorite.IsFavorite(config); |
117 |
|
if (isFavorite) |
118 |
|
{ |
119 |
|
// add to favorites |
120 |
< |
log.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
121 |
< |
if (!RomFavorite.RemoveFavorite(log, config)) |
120 |
> |
gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
121 |
> |
if (!RomFavorite.RemoveFavorite(config)) |
122 |
|
{ |
123 |
< |
log.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
123 |
> |
gLog.Debug.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
124 |
|
} |
125 |
|
else |
126 |
|
{ |
127 |
< |
log.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
127 |
> |
gLog.Debug.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
128 |
|
if (config.Config.PlatformNameShort == "Favorites") |
129 |
|
{ |
130 |
|
var parent = c.Parent; |
146 |
|
else |
147 |
|
{ |
148 |
|
// add to favorites |
149 |
< |
log.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
150 |
< |
if (!RomFavorite.AddFavorite(log,config)) |
149 |
> |
gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
150 |
> |
if (!RomFavorite.AddFavorite(config)) |
151 |
|
{ |
152 |
< |
log.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
152 |
> |
gLog.Debug.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
153 |
|
} |
154 |
|
else |
155 |
|
{ |
156 |
< |
log.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
156 |
> |
gLog.Debug.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile); |
157 |
|
} |
158 |
|
} |
159 |
< |
log.WriteLine("Updateing favorites"); |
160 |
< |
if (!RomFavorite.UpdateFavorites(log)) |
159 |
> |
gLog.Debug.WriteLine("Updateing favorites"); |
160 |
> |
if (!RomFavorite.UpdateFavorites()) |
161 |
|
{ |
162 |
< |
log.WriteLine("Failed to update favorites"); |
162 |
> |
gLog.Debug.WriteLine("Failed to update favorites"); |
163 |
|
} |
164 |
|
else |
165 |
|
{ |
166 |
< |
log.WriteLine("Updated favorites"); |
166 |
> |
gLog.Debug.WriteLine("Updated favorites"); |
167 |
|
} |
168 |
|
} |
169 |
|
return; // stop processing other keys |
242 |
|
Process p = new Process(); |
243 |
|
|
244 |
|
p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe; |
245 |
< |
p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(log, config) : config.Config.GameExeArgs; |
245 |
> |
p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(config) : config.Config.GameExeArgs; |
246 |
|
p.Start(); |
247 |
|
|
248 |
|
// minimize EmuXPortal |
527 |
|
private void gameWorker_DoWork(object sender, DoWorkEventArgs e) |
528 |
|
{ |
529 |
|
Stopwatch t = e.Argument as Stopwatch; |
530 |
< |
RomParser parser = new RomParser(log, CurrentSelectedRom); |
530 |
> |
RomParser parser = new RomParser(CurrentSelectedRom); |
531 |
|
|
532 |
|
CustomProgressBar bar = new CustomProgressBar(); |
533 |
|
bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE); |
602 |
|
} |
603 |
|
rom_flow.Controls[0].Select(); |
604 |
|
t.Stop(); |
605 |
< |
log.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds); |
605 |
> |
gLog.Profiler.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds); |
606 |
|
} |
607 |
|
#endregion |
608 |
|
#region platformWorker |
611 |
|
private void platformWorker_DoWork(object sender, DoWorkEventArgs e) |
612 |
|
{ |
613 |
|
Stopwatch t = e.Argument as Stopwatch; |
614 |
< |
PlatformParser parser = new PlatformParser(log, Config.RomPath); |
614 |
> |
PlatformParser parser = new PlatformParser(Config.RomPath); |
615 |
|
double count = 0; |
616 |
|
double total_count = parser.Platforms.Count; |
617 |
|
CustomProgressBar bar = new CustomProgressBar(); |
675 |
|
platform_flow.Controls.Add(platform_ctrl); |
676 |
|
} |
677 |
|
platform_flow.Controls[0].Select(); |
678 |
< |
log.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds); |
678 |
> |
gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds); |
679 |
|
} |
680 |
|
#endregion |
681 |
|
|
682 |
|
private void Form1_FormClosed(object sender, FormClosedEventArgs e) |
683 |
|
{ |
684 |
|
Cursor.Show(); |
648 |
– |
log.CloseLog(); |
685 |
|
} |
686 |
|
#endregion |
687 |
|
} |