/[EmuXPortal]/trunk/EmuXPortal/Api/EmuConfig.cs
ViewVC logotype

Diff of /trunk/EmuXPortal/Api/EmuConfig.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/EmuXPortal/Api/EmuConfig.cs	2014/08/05 04:13:36	237
+++ trunk/EmuXPortal/Api/EmuConfig.cs	2014/08/05 04:50:39	238
@@ -4,9 +4,9 @@
 using System.Text;
 using System.Drawing;
 using System.IO;
-using EmuXPortal.Logging;
 using System.Xml;
 using System.Diagnostics;
+using Enterprise.Logging;
 
 namespace EmuXPortal.Api
 {
@@ -33,7 +33,7 @@
         string GameExeArgs { get; }
 
 
-        void RefreshConfig(logger log);
+        void RefreshConfig();
         void ReleasePlatformImageResource();
     }    
 
@@ -42,13 +42,13 @@
         public static readonly IEmuConfig Empty = new EmuConfig();
         private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration
         #region load
-        public static IEmuConfig Load(logger log,string rom_path) { return new EmuConfig().Create(log, rom_path); }
-        public static IEmuConfig Load(logger log,string config_path, string rom_path) { return new EmuConfig().Create(log, config_path, rom_path); }
+        public static IEmuConfig Load(string rom_path) { return new EmuConfig().Create(rom_path); }
+        public static IEmuConfig Load(string config_path, string rom_path) { return new EmuConfig().Create(config_path, rom_path); }
         #endregion
         #region parse emu options
-        public static string GetEMUOptions(logger log, IRomConfig config)
+        public static string GetEMUOptions(IRomConfig config)
         {
-            EMUOptions EMUOptions = new EMUOptions(log, config);
+            EMUOptions EMUOptions = new EMUOptions(config);
             return EMUOptions.Options;
         }
         #endregion
@@ -60,10 +60,10 @@
             private const string ROM_PATH = "%ROM_PATH%";
             #endregion
             private Dictionary<string, string> options_dict = new Dictionary<string, string>();
-            public EMUOptions(logger log, IRomConfig config)
+            public EMUOptions(IRomConfig config)
             {
                 init_dict(config);
-                config.Config.RefreshConfig(log);
+                config.Config.RefreshConfig();
                 string options = config.Config.EmuOptions;
                 string real_options = options;
                 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); } }
@@ -81,8 +81,8 @@
         #region private class EmuConfig : IEmuConfig
         internal class EmuConfig : IEmuConfig, IComparable<IEmuConfig>, IDisposable
         {
-            public IEmuConfig Create(logger log, string rom_path) { return this.Create(log, string.Empty, rom_path); }
-            public IEmuConfig Create(logger log, string config_path, string rom_path)
+            public IEmuConfig Create(string rom_path) { return this.Create(string.Empty, rom_path); }
+            public IEmuConfig Create(string config_path, string rom_path)
             {
                 IEmuConfig parent_rom = null;
                 if (rom_path == "")
@@ -125,7 +125,7 @@
                     {
                         EmuRomPath = emu_config.Directory.FullName;
                         // load the rom config
-                        parent_rom = EmuConfigLoader.Load(log, emu_config.FullName, EmuRomPath);
+                        parent_rom = EmuConfigLoader.Load(emu_config.FullName, EmuRomPath);
                     }
 
                     
@@ -135,8 +135,8 @@
                 FileInfo fi = new FileInfo(config_path);
                 if (fi.Exists)
                 {
-                    log.WriteLine("Found EMU Config File: {0}", config_path);
-                    log.WriteLine("\tLoading Config: {0}", config_path);
+                    gLog.Debug.WriteLine("Found EMU Config File: {0}", config_path);
+                    gLog.Debug.WriteLine("\tLoading Config: {0}", config_path);
                     this.ConfigPath = config_path;
                     //bool loaded = false;
                     try
@@ -158,7 +158,7 @@
                                             {
                                                 value = reader.ReadElementContentAsString();
                                                 PlatformNameShort = (value == "") ? PlatformNameShort : value;
-                                                log.WriteLine("\t\tPLATFORMNAMESHORT={0}", PlatformNameShort);
+                                                gLog.Debug.WriteLine("\t\tPLATFORMNAMESHORT={0}", PlatformNameShort);
                                             }
                                             break;
                                         case "PLATFORMNAMELONG":
@@ -166,7 +166,7 @@
                                             {
                                                 value = reader.ReadElementContentAsString();
                                                 PlatformNameLong = (value == "") ? PlatformNameLong : value;
-                                                log.WriteLine("\t\tPLATFORMNAMELONG={0}", PlatformNameLong);
+                                                gLog.Debug.WriteLine("\t\tPLATFORMNAMELONG={0}", PlatformNameLong);
                                             }
                                             break;
                                         case "PLATFORMIMAGE":
@@ -175,7 +175,7 @@
                                                 string platform_image = reader.ReadElementContentAsString();
                                                 PlatformImage = (platform_image == "") ? null : Image.FromFile(string.Format(@"{0}\{1}", EmuRomPath, platform_image));
                                                 string str_platform_image = (platform_image == "") ? "DefaultPlatformImage" : platform_image;
-                                                log.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image);
+                                                gLog.Debug.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image);
                                             }
                                             break;
                                         case "EXTENSIONS":
@@ -183,7 +183,7 @@
                                             {
                                                 value = reader.ReadElementContentAsString();
                                                 Extenstions = (value == "") ? Extenstions : value;
-                                                log.WriteLine("\t\tEXTENSIONS={0}", Extenstions);
+                                                gLog.Debug.WriteLine("\t\tEXTENSIONS={0}", Extenstions);
                                             }
                                             break;
                                         case "EMULATORPATH":
@@ -191,7 +191,7 @@
                                             {
                                                 value = reader.ReadElementContentAsString();
                                                 EmuPath = (value == "") ? EmuPath : value;
-                                                log.WriteLine("\t\tEMULATORPATH={0}", EmuPath);
+                                                gLog.Debug.WriteLine("\t\tEMULATORPATH={0}", EmuPath);
                                             }
                                             break;
                                         case "EMULATOROPTIONS":
@@ -199,7 +199,7 @@
                                             {
                                                 value = reader.ReadElementContentAsString();
                                                 EmuOptions = (value == "") ? EmuOptions : value;
-                                                log.WriteLine("\tEMULATOROPTIONS={0}", EmuOptions);
+                                                gLog.Debug.WriteLine("\tEMULATOROPTIONS={0}", EmuOptions);
                                             }
                                             break;
                                         #region External Non-Emulator Rom Support
@@ -209,7 +209,7 @@
                                                 value = reader.ReadElementContentAsString();
                                                 string gametitle = (value == "") ? GameTitle : value;
                                                 GameTitle = gametitle;
-                                                log.WriteLine("\tGAMETITLE={0}", GameTitle);
+                                                gLog.Debug.WriteLine("\tGAMETITLE={0}", GameTitle);
                                             }
                                             break;
                                         case "GAMEIMAGE":
@@ -218,7 +218,7 @@
                                                 value = reader.ReadElementContentAsString();
                                                 string gameimage = (value == "") ? GameImage : value;
                                                 GameImage = gameimage;
-                                                log.WriteLine("\tGAMEIMAGE={0}", GameImage);
+                                                gLog.Debug.WriteLine("\tGAMEIMAGE={0}", GameImage);
                                             }
                                             break;
                                         case "GAMEEXE":
@@ -227,7 +227,7 @@
                                                 value = reader.ReadElementContentAsString();
                                                 string gameexe = (value == "") ? GameExe : value;
                                                 GameExe = gameexe;
-                                                log.WriteLine("\tGAMEEXE={0}", GameExe);
+                                                gLog.Debug.WriteLine("\tGAMEEXE={0}", GameExe);
                                             }
                                             break;
                                         case "GAMEEXEARGS":
@@ -236,7 +236,7 @@
                                                 value = reader.ReadElementContentAsString();
                                                 string gameexeargs = (value == "") ? GameExeArgs : value;
                                                 GameExeArgs = gameexeargs;
-                                                log.WriteLine("\tGAMEEXEARGS={0}", GameExeArgs);
+                                                gLog.Debug.WriteLine("\tGAMEEXEARGS={0}", GameExeArgs);
                                             }
                                             break;
                                         case "EXTERNALCONFIGSPATH":
@@ -245,7 +245,7 @@
                                                 string searchPattern = "*.config";
                                                 string external_configs_path = reader.ReadElementContentAsString();
                                                 //EmuOptions = (external_configs_path == "") ? EmuOptions : value;
-                                                log.WriteLine("\tEXTERNALCONFIGSPATH={0}", external_configs_path);
+                                                gLog.Debug.WriteLine("\tEXTERNALCONFIGSPATH={0}", external_configs_path);
                                                 DirectoryInfo ext_path = new DirectoryInfo(external_configs_path);
                                                 string ext_rom_path = string.Format(@"{0}\{1}", EmuRomPath, external_configs_path);
                                                 // try the path in romroot
@@ -260,7 +260,7 @@
                                                         external_config_files.Sort(); // sort the files (they should already be sorted alphabetically by GetFiles())
                                                     foreach (string file in external_config_files)
                                                     {
-                                                        IEmuConfig config = EmuConfigLoader.Load(log, file, EmuRomPath);
+                                                        IEmuConfig config = EmuConfigLoader.Load(file, EmuRomPath);
                                                         if (config != null)
                                                             externalconfigs.Add(config);
                                                     }
@@ -272,25 +272,25 @@
                                         #endregion
                                         default:
                                             if (InConfigSection && (reader.Name != string.Empty) && reader.IsStartElement())
-                                                log.WriteLine("Warning: Unknown or Unrecognized config option: {0} in {1}", reader.Name, config_path);
+                                                gLog.Debug.WriteLine("Warning: Unknown or Unrecognized config option: {0} in {1}", reader.Name, config_path);
                                             break;
                                     }
                                     reader.Read();
                                 }
                             }
                         }
-                        log.WriteLine("\tLoaded Config: {0}", config_path);
+                        gLog.Debug.WriteLine("\tLoaded Config: {0}", config_path);
                         //loaded = true;
                     }
                     catch (Exception ex)
                     {
-                        log.WriteLine("\tFailed to Load Config: {0}", config_path);
-                        Console.WriteLine(ex.ToString());
-                        log.WriteLine("Error: {0}", ex.ToString());
+                        gLog.Error.WriteLine("\tFailed to Load Config: {0}", config_path);
+                        //Console.WriteLine(ex.ToString());
+                        gLog.Verbose.Error.WriteLine("Error: {0}", ex.ToString());
                         //loaded = false;
                     }
                 }
-                else { log.WriteLine("Could not find EMU Config File: {0}", config_path); }
+                else { gLog.Debug.WriteLine("Could not find EMU Config File: {0}", config_path); }
 
                 if (parent_rom != null)
                 {
@@ -313,19 +313,14 @@
             }
 
             private const string Unknown_Platform = "Unknown Platform";
-            private logger log;
             public EmuConfig() : this(null, "") { }
-            public EmuConfig(logger log) : this(log,"") { }
-            public EmuConfig(logger log, string PlatformNameShort) : this(log, PlatformNameShort, PlatformNameShort) { }
-            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong) : this(log, PlatformNameShort, PlatformNameLong, "") { }
-            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage) : this(log, PlatformNameShort, PlatformNameLong, PlatformImage, "") { }
-            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions) : this(log, PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, "") { }
-            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath) : this(log, PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, EmuPath, "") { }
-            public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath, string EmuOptions)
+            public EmuConfig(string PlatformNameShort) : this(PlatformNameShort, PlatformNameShort) { }
+            public EmuConfig(string PlatformNameShort, string PlatformNameLong) : this(PlatformNameShort, PlatformNameLong, "") { }
+            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage) : this(PlatformNameShort, PlatformNameLong, PlatformImage, "") { }
+            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions) : this(PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, "") { }
+            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath) : this(PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, EmuPath, "") { }
+            public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath, string EmuOptions)
             {
-                
-                
-
                 this.PlatformNameShort = PlatformNameShort;
                 this.PlatformNameLong = PlatformNameLong;
                 this.PlatformImage = (PlatformImage == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(PlatformImage);
@@ -337,7 +332,6 @@
                 this.GameImage = "";
                 this.GameExe = "";
                 this.GameExeArgs = "";
-                this.log = log;
             }
             #region IEmuConfig members
             public bool IsFavorites { get { return false; } }
@@ -359,7 +353,7 @@
                     }
                     catch (Exception ex)
                     {
-                        log.WriteLine("PlatformNameShort.get() Error: {0}", ex.ToString());
+                        gLog.Verbose.Error.WriteLine("PlatformNameShort.get() Error: {0}", ex.ToString());
                         return Unknown_Platform;
                     }
                 }
@@ -377,7 +371,7 @@
                     }
                     catch (Exception ex)
                     {
-                        log.WriteLine("PlatformNameLong.get() Error: {0}", ex.ToString());
+                        gLog.Verbose.Error.WriteLine("PlatformNameLong.get() Error: {0}", ex.ToString());
                         return Unknown_Platform;
                     }
                 }
@@ -413,10 +407,10 @@
             {
                 return this.PlatformNameLong.CompareTo(obj.PlatformNameLong);
             }
-            public void RefreshConfig(logger log)
+            public void RefreshConfig()
             {
-                log.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG));
-                this.Create(log,EmuRomPath);
+                gLog.Debug.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG));
+                this.Create(EmuRomPath);
             }
             #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22