ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/EmuXPortal/trunk/EmuXPortal/Api/EmuConfig.cs
(Generate patch)

Comparing trunk/EmuXPortal/Api/EmuConfig.cs (file contents):
Revision 237 by william, Mon Aug 4 12:39:13 2014 UTC vs.
Revision 238 by william, Tue Aug 5 04:50:39 2014 UTC

# Line 4 | Line 4 | using System.Linq;
4   using System.Text;
5   using System.Drawing;
6   using System.IO;
7 using EmuXPortal.Logging;
7   using System.Xml;
8   using System.Diagnostics;
9 + using Enterprise.Logging;
10  
11   namespace EmuXPortal.Api
12   {
# Line 33 | Line 33 | namespace EmuXPortal.Api
33          string GameExeArgs { get; }
34  
35  
36 <        void RefreshConfig(logger log);
36 >        void RefreshConfig();
37          void ReleasePlatformImageResource();
38      }    
39  
# Line 42 | Line 42 | namespace EmuXPortal.Api
42          public static readonly IEmuConfig Empty = new EmuConfig();
43          private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration
44          #region load
45 <        public static IEmuConfig Load(logger log,string rom_path) { return new EmuConfig().Create(log, rom_path); }
46 <        public static IEmuConfig Load(logger log,string config_path, string rom_path) { return new EmuConfig().Create(log, config_path, rom_path); }
45 >        public static IEmuConfig Load(string rom_path) { return new EmuConfig().Create(rom_path); }
46 >        public static IEmuConfig Load(string config_path, string rom_path) { return new EmuConfig().Create(config_path, rom_path); }
47          #endregion
48          #region parse emu options
49 <        public static string GetEMUOptions(logger log, IRomConfig config)
49 >        public static string GetEMUOptions(IRomConfig config)
50          {
51 <            EMUOptions EMUOptions = new EMUOptions(log, config);
51 >            EMUOptions EMUOptions = new EMUOptions(config);
52              return EMUOptions.Options;
53          }
54          #endregion
# Line 60 | Line 60 | namespace EmuXPortal.Api
60              private const string ROM_PATH = "%ROM_PATH%";
61              #endregion
62              private Dictionary<string, string> options_dict = new Dictionary<string, string>();
63 <            public EMUOptions(logger log, IRomConfig config)
63 >            public EMUOptions(IRomConfig config)
64              {
65                  init_dict(config);
66 <                config.Config.RefreshConfig(log);
66 >                config.Config.RefreshConfig();
67                  string options = config.Config.EmuOptions;
68                  string real_options = options;
69                  foreach (KeyValuePair<string, string> pair in options_dict) { if (options.ToLower().Contains(pair.Key.ToLower())) { real_options = real_options.ToLower().Replace(pair.Key.ToLower(), pair.Value); } }
# Line 81 | Line 81 | namespace EmuXPortal.Api
81          #region private class EmuConfig : IEmuConfig
82          internal class EmuConfig : IEmuConfig, IComparable<IEmuConfig>, IDisposable
83          {
84 <            public IEmuConfig Create(logger log, string rom_path) { return this.Create(log, string.Empty, rom_path); }
85 <            public IEmuConfig Create(logger log, string config_path, string rom_path)
84 >            public IEmuConfig Create(string rom_path) { return this.Create(string.Empty, rom_path); }
85 >            public IEmuConfig Create(string config_path, string rom_path)
86              {
87                  IEmuConfig parent_rom = null;
88                  if (rom_path == "")
# Line 125 | Line 125 | namespace EmuXPortal.Api
125                      {
126                          EmuRomPath = emu_config.Directory.FullName;
127                          // load the rom config
128 <                        parent_rom = EmuConfigLoader.Load(log, emu_config.FullName, EmuRomPath);
128 >                        parent_rom = EmuConfigLoader.Load(emu_config.FullName, EmuRomPath);
129                      }
130  
131                      
# Line 135 | Line 135 | namespace EmuXPortal.Api
135                  FileInfo fi = new FileInfo(config_path);
136                  if (fi.Exists)
137                  {
138 <                    log.WriteLine("Found EMU Config File: {0}", config_path);
139 <                    log.WriteLine("\tLoading Config: {0}", config_path);
138 >                    gLog.Debug.WriteLine("Found EMU Config File: {0}", config_path);
139 >                    gLog.Debug.WriteLine("\tLoading Config: {0}", config_path);
140                      this.ConfigPath = config_path;
141                      //bool loaded = false;
142                      try
# Line 158 | Line 158 | namespace EmuXPortal.Api
158                                              {
159                                                  value = reader.ReadElementContentAsString();
160                                                  PlatformNameShort = (value == "") ? PlatformNameShort : value;
161 <                                                log.WriteLine("\t\tPLATFORMNAMESHORT={0}", PlatformNameShort);
161 >                                                gLog.Debug.WriteLine("\t\tPLATFORMNAMESHORT={0}", PlatformNameShort);
162                                              }
163                                              break;
164                                          case "PLATFORMNAMELONG":
# Line 166 | Line 166 | namespace EmuXPortal.Api
166                                              {
167                                                  value = reader.ReadElementContentAsString();
168                                                  PlatformNameLong = (value == "") ? PlatformNameLong : value;
169 <                                                log.WriteLine("\t\tPLATFORMNAMELONG={0}", PlatformNameLong);
169 >                                                gLog.Debug.WriteLine("\t\tPLATFORMNAMELONG={0}", PlatformNameLong);
170                                              }
171                                              break;
172                                          case "PLATFORMIMAGE":
# Line 175 | Line 175 | namespace EmuXPortal.Api
175                                                  string platform_image = reader.ReadElementContentAsString();
176                                                  PlatformImage = (platform_image == "") ? null : Image.FromFile(string.Format(@"{0}\{1}", EmuRomPath, platform_image));
177                                                  string str_platform_image = (platform_image == "") ? "DefaultPlatformImage" : platform_image;
178 <                                                log.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image);
178 >                                                gLog.Debug.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image);
179                                              }
180                                              break;
181                                          case "EXTENSIONS":
# Line 183 | Line 183 | namespace EmuXPortal.Api
183                                              {
184                                                  value = reader.ReadElementContentAsString();
185                                                  Extenstions = (value == "") ? Extenstions : value;
186 <                                                log.WriteLine("\t\tEXTENSIONS={0}", Extenstions);
186 >                                                gLog.Debug.WriteLine("\t\tEXTENSIONS={0}", Extenstions);
187                                              }
188                                              break;
189                                          case "EMULATORPATH":
# Line 191 | Line 191 | namespace EmuXPortal.Api
191                                              {
192                                                  value = reader.ReadElementContentAsString();
193                                                  EmuPath = (value == "") ? EmuPath : value;
194 <                                                log.WriteLine("\t\tEMULATORPATH={0}", EmuPath);
194 >                                                gLog.Debug.WriteLine("\t\tEMULATORPATH={0}", EmuPath);
195                                              }
196                                              break;
197                                          case "EMULATOROPTIONS":
# Line 199 | Line 199 | namespace EmuXPortal.Api
199                                              {
200                                                  value = reader.ReadElementContentAsString();
201                                                  EmuOptions = (value == "") ? EmuOptions : value;
202 <                                                log.WriteLine("\tEMULATOROPTIONS={0}", EmuOptions);
202 >                                                gLog.Debug.WriteLine("\tEMULATOROPTIONS={0}", EmuOptions);
203                                              }
204                                              break;
205                                          #region External Non-Emulator Rom Support
# Line 209 | Line 209 | namespace EmuXPortal.Api
209                                                  value = reader.ReadElementContentAsString();
210                                                  string gametitle = (value == "") ? GameTitle : value;
211                                                  GameTitle = gametitle;
212 <                                                log.WriteLine("\tGAMETITLE={0}", GameTitle);
212 >                                                gLog.Debug.WriteLine("\tGAMETITLE={0}", GameTitle);
213                                              }
214                                              break;
215                                          case "GAMEIMAGE":
# Line 218 | Line 218 | namespace EmuXPortal.Api
218                                                  value = reader.ReadElementContentAsString();
219                                                  string gameimage = (value == "") ? GameImage : value;
220                                                  GameImage = gameimage;
221 <                                                log.WriteLine("\tGAMEIMAGE={0}", GameImage);
221 >                                                gLog.Debug.WriteLine("\tGAMEIMAGE={0}", GameImage);
222                                              }
223                                              break;
224                                          case "GAMEEXE":
# Line 227 | Line 227 | namespace EmuXPortal.Api
227                                                  value = reader.ReadElementContentAsString();
228                                                  string gameexe = (value == "") ? GameExe : value;
229                                                  GameExe = gameexe;
230 <                                                log.WriteLine("\tGAMEEXE={0}", GameExe);
230 >                                                gLog.Debug.WriteLine("\tGAMEEXE={0}", GameExe);
231                                              }
232                                              break;
233                                          case "GAMEEXEARGS":
# Line 236 | Line 236 | namespace EmuXPortal.Api
236                                                  value = reader.ReadElementContentAsString();
237                                                  string gameexeargs = (value == "") ? GameExeArgs : value;
238                                                  GameExeArgs = gameexeargs;
239 <                                                log.WriteLine("\tGAMEEXEARGS={0}", GameExeArgs);
239 >                                                gLog.Debug.WriteLine("\tGAMEEXEARGS={0}", GameExeArgs);
240                                              }
241                                              break;
242                                          case "EXTERNALCONFIGSPATH":
# Line 245 | Line 245 | namespace EmuXPortal.Api
245                                                  string searchPattern = "*.config";
246                                                  string external_configs_path = reader.ReadElementContentAsString();
247                                                  //EmuOptions = (external_configs_path == "") ? EmuOptions : value;
248 <                                                log.WriteLine("\tEXTERNALCONFIGSPATH={0}", external_configs_path);
248 >                                                gLog.Debug.WriteLine("\tEXTERNALCONFIGSPATH={0}", external_configs_path);
249                                                  DirectoryInfo ext_path = new DirectoryInfo(external_configs_path);
250                                                  string ext_rom_path = string.Format(@"{0}\{1}", EmuRomPath, external_configs_path);
251                                                  // try the path in romroot
# Line 260 | Line 260 | namespace EmuXPortal.Api
260                                                          external_config_files.Sort(); // sort the files (they should already be sorted alphabetically by GetFiles())
261                                                      foreach (string file in external_config_files)
262                                                      {
263 <                                                        IEmuConfig config = EmuConfigLoader.Load(log, file, EmuRomPath);
263 >                                                        IEmuConfig config = EmuConfigLoader.Load(file, EmuRomPath);
264                                                          if (config != null)
265                                                              externalconfigs.Add(config);
266                                                      }
# Line 272 | Line 272 | namespace EmuXPortal.Api
272                                          #endregion
273                                          default:
274                                              if (InConfigSection && (reader.Name != string.Empty) && reader.IsStartElement())
275 <                                                log.WriteLine("Warning: Unknown or Unrecognized config option: {0} in {1}", reader.Name, config_path);
275 >                                                gLog.Debug.WriteLine("Warning: Unknown or Unrecognized config option: {0} in {1}", reader.Name, config_path);
276                                              break;
277                                      }
278                                      reader.Read();
279                                  }
280                              }
281                          }
282 <                        log.WriteLine("\tLoaded Config: {0}", config_path);
282 >                        gLog.Debug.WriteLine("\tLoaded Config: {0}", config_path);
283                          //loaded = true;
284                      }
285                      catch (Exception ex)
286                      {
287 <                        log.WriteLine("\tFailed to Load Config: {0}", config_path);
288 <                        Console.WriteLine(ex.ToString());
289 <                        log.WriteLine("Error: {0}", ex.ToString());
287 >                        gLog.Error.WriteLine("\tFailed to Load Config: {0}", config_path);
288 >                        //Console.WriteLine(ex.ToString());
289 >                        gLog.Verbose.Error.WriteLine("Error: {0}", ex.ToString());
290                          //loaded = false;
291                      }
292                  }
293 <                else { log.WriteLine("Could not find EMU Config File: {0}", config_path); }
293 >                else { gLog.Debug.WriteLine("Could not find EMU Config File: {0}", config_path); }
294  
295                  if (parent_rom != null)
296                  {
# Line 313 | Line 313 | namespace EmuXPortal.Api
313              }
314  
315              private const string Unknown_Platform = "Unknown Platform";
316            private logger log;
316              public EmuConfig() : this(null, "") { }
317 <            public EmuConfig(logger log) : this(log,"") { }
318 <            public EmuConfig(logger log, string PlatformNameShort) : this(log, PlatformNameShort, PlatformNameShort) { }
319 <            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong) : this(log, PlatformNameShort, PlatformNameLong, "") { }
320 <            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage) : this(log, PlatformNameShort, PlatformNameLong, PlatformImage, "") { }
321 <            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions) : this(log, PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, "") { }
322 <            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath) : this(log, PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, EmuPath, "") { }
324 <            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath, string EmuOptions)
317 >            public EmuConfig(string PlatformNameShort) : this(PlatformNameShort, PlatformNameShort) { }
318 >            public EmuConfig(string PlatformNameShort, string PlatformNameLong) : this(PlatformNameShort, PlatformNameLong, "") { }
319 >            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage) : this(PlatformNameShort, PlatformNameLong, PlatformImage, "") { }
320 >            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions) : this(PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, "") { }
321 >            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath) : this(PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, EmuPath, "") { }
322 >            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath, string EmuOptions)
323              {
326                
327                
328
324                  this.PlatformNameShort = PlatformNameShort;
325                  this.PlatformNameLong = PlatformNameLong;
326                  this.PlatformImage = (PlatformImage == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(PlatformImage);
# Line 337 | Line 332 | namespace EmuXPortal.Api
332                  this.GameImage = "";
333                  this.GameExe = "";
334                  this.GameExeArgs = "";
340                this.log = log;
335              }
336              #region IEmuConfig members
337              public bool IsFavorites { get { return false; } }
# Line 359 | Line 353 | namespace EmuXPortal.Api
353                      }
354                      catch (Exception ex)
355                      {
356 <                        log.WriteLine("PlatformNameShort.get() Error: {0}", ex.ToString());
356 >                        gLog.Verbose.Error.WriteLine("PlatformNameShort.get() Error: {0}", ex.ToString());
357                          return Unknown_Platform;
358                      }
359                  }
# Line 377 | Line 371 | namespace EmuXPortal.Api
371                      }
372                      catch (Exception ex)
373                      {
374 <                        log.WriteLine("PlatformNameLong.get() Error: {0}", ex.ToString());
374 >                        gLog.Verbose.Error.WriteLine("PlatformNameLong.get() Error: {0}", ex.ToString());
375                          return Unknown_Platform;
376                      }
377                  }
# Line 413 | Line 407 | namespace EmuXPortal.Api
407              {
408                  return this.PlatformNameLong.CompareTo(obj.PlatformNameLong);
409              }
410 <            public void RefreshConfig(logger log)
410 >            public void RefreshConfig()
411              {
412 <                log.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG));
413 <                this.Create(log,EmuRomPath);
412 >                gLog.Debug.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG));
413 >                this.Create(EmuRomPath);
414              }
415              #endregion
416  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines