--- trunk/EmuXPortal/Api/EmuConfig.cs 2012/08/23 03:08:35 111 +++ trunk/EmuXPortal/Api/EmuConfig.cs 2012/08/23 04:13:19 112 @@ -42,8 +42,8 @@ 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(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); } + 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); } #endregion #region parse emu options public static string GetEMUOptions(IRomConfig config) @@ -81,8 +81,8 @@ #region private class EmuConfig : IEmuConfig private class EmuConfig : IEmuConfig, IComparable, IDisposable { - public IEmuConfig Create(string rom_path) { return this.Create(string.Empty, rom_path); } - public IEmuConfig Create(string config_path, string rom_path) + 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) { EmuRomPath = rom_path; if (config_path == "") { config_path = string.Format(@"{0}\{1}", rom_path, EMU_CONFIG); } @@ -91,8 +91,8 @@ FileInfo fi = new FileInfo(config_path); if (fi.Exists) { - logger.WriteLine("Found EMU Config File: {0}", config_path); - logger.WriteLine("\tLoading Config: {0}", config_path); + log.WriteLine("Found EMU Config File: {0}", config_path); + log.WriteLine("\tLoading Config: {0}", config_path); this.ConfigPath = config_path; //bool loaded = false; try @@ -114,7 +114,7 @@ { value = reader.ReadElementContentAsString(); PlatformNameShort = (value == "") ? PlatformNameShort : value; - logger.WriteLine("\t\tPLATFORMNAMESHORT={0}", PlatformNameShort); + log.WriteLine("\t\tPLATFORMNAMESHORT={0}", PlatformNameShort); } break; case "PLATFORMNAMELONG": @@ -122,7 +122,7 @@ { value = reader.ReadElementContentAsString(); PlatformNameLong = (value == "") ? PlatformNameLong : value; - logger.WriteLine("\t\tPLATFORMNAMELONG={0}", PlatformNameLong); + log.WriteLine("\t\tPLATFORMNAMELONG={0}", PlatformNameLong); } break; case "PLATFORMIMAGE": @@ -131,7 +131,7 @@ string platform_image = reader.ReadElementContentAsString(); PlatformImage = (platform_image == "") ? null : Image.FromFile(string.Format(@"{0}\{1}", rom_path, platform_image)); string str_platform_image = (platform_image == "") ? "DefaultPlatformImage" : platform_image; - logger.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image); + log.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image); } break; case "EXTENSIONS": @@ -139,7 +139,7 @@ { value = reader.ReadElementContentAsString(); Extenstions = (value == "") ? Extenstions : value; - logger.WriteLine("\t\tEXTENSIONS={0}", Extenstions); + log.WriteLine("\t\tEXTENSIONS={0}", Extenstions); } break; case "EMULATORPATH": @@ -147,7 +147,7 @@ { value = reader.ReadElementContentAsString(); EmuPath = (value == "") ? EmuPath : value; - logger.WriteLine("\t\tEMULATORPATH={0}", EmuPath); + log.WriteLine("\t\tEMULATORPATH={0}", EmuPath); } break; case "EMULATOROPTIONS": @@ -155,7 +155,7 @@ { value = reader.ReadElementContentAsString(); EmuOptions = (value == "") ? EmuOptions : value; - logger.WriteLine("\tEMULATOROPTIONS={0}", EmuOptions); + log.WriteLine("\tEMULATOROPTIONS={0}", EmuOptions); } break; #region External Non-Emulator Rom Support @@ -165,7 +165,7 @@ value = reader.ReadElementContentAsString(); string gametitle = (value == "") ? GameTitle : value; GameTitle = gametitle; - logger.WriteLine("\tGAMETITLE={0}", GameTitle); + log.WriteLine("\tGAMETITLE={0}", GameTitle); } break; case "GAMEIMAGE": @@ -174,7 +174,7 @@ value = reader.ReadElementContentAsString(); string gameimage = (value == "") ? GameImage : value; GameImage = gameimage; - logger.WriteLine("\tGAMEIMAGE={0}", GameImage); + log.WriteLine("\tGAMEIMAGE={0}", GameImage); } break; case "GAMEEXE": @@ -183,7 +183,7 @@ value = reader.ReadElementContentAsString(); string gameexe = (value == "") ? GameExe : value; GameExe = gameexe; - logger.WriteLine("\tGAMEEXE={0}", GameExe); + log.WriteLine("\tGAMEEXE={0}", GameExe); } break; case "GAMEEXEARGS": @@ -192,7 +192,7 @@ value = reader.ReadElementContentAsString(); string gameexeargs = (value == "") ? GameExeArgs : value; GameExeArgs = gameexeargs; - logger.WriteLine("\tGAMEEXEARGS={0}", GameExeArgs); + log.WriteLine("\tGAMEEXEARGS={0}", GameExeArgs); } break; case "EXTERNALCONFIGSPATH": @@ -201,7 +201,7 @@ string searchPattern = "*.config"; string external_configs_path = reader.ReadElementContentAsString(); //EmuOptions = (external_configs_path == "") ? EmuOptions : value; - logger.WriteLine("\tEXTERNALCONFIGSPATH={0}", external_configs_path); + log.WriteLine("\tEXTERNALCONFIGSPATH={0}", external_configs_path); DirectoryInfo ext_path = new DirectoryInfo(external_configs_path); string ext_rom_path = string.Format(@"{0}\{1}", rom_path, external_configs_path); // try the path in romroot @@ -216,7 +216,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(file, rom_path); + IEmuConfig config = EmuConfigLoader.Load(log, file, rom_path); if (config != null) externalconfigs.Add(config); } @@ -228,37 +228,39 @@ #endregion default: if (InConfigSection && (reader.Name != string.Empty) && reader.IsStartElement()) - logger.WriteLine("Warning: Unknown or Unrecognized config option: {0} in {1}", reader.Name, config_path); + log.WriteLine("Warning: Unknown or Unrecognized config option: {0} in {1}", reader.Name, config_path); break; } reader.Read(); } } } - logger.WriteLine("\tLoaded Config: {0}", config_path); + log.WriteLine("\tLoaded Config: {0}", config_path); //loaded = true; } catch (Exception ex) { - logger.WriteLine("\tFailed to Load Config: {0}", config_path); + log.WriteLine("\tFailed to Load Config: {0}", config_path); Console.WriteLine(ex.ToString()); - logger.WriteLine("Error: {0}", ex.ToString()); + log.WriteLine("Error: {0}", ex.ToString()); //loaded = false; } } - else { logger.WriteLine("Could not find EMU Config File: {0}", config_path); } + else { log.WriteLine("Could not find EMU Config File: {0}", config_path); } return this; } private const string Unknown_Platform = "Unknown Platform"; - public EmuConfig() : this("") { } - 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) + 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) { this.PlatformNameShort = PlatformNameShort; this.PlatformNameLong = PlatformNameLong; @@ -271,6 +273,7 @@ this.GameImage = ""; this.GameExe = ""; this.GameExeArgs = ""; + this.log = log; } #region IEmuConfig members public string ConfigPath { get; set; } @@ -286,7 +289,7 @@ } catch (Exception ex) { - logger.WriteLine("PlatformNameShort.get() Error: {0}", ex.ToString()); + log.WriteLine("PlatformNameShort.get() Error: {0}", ex.ToString()); return Unknown_Platform; } } @@ -304,7 +307,7 @@ } catch (Exception ex) { - logger.WriteLine("PlatformNameLong.get() Error: {0}", ex.ToString()); + log.WriteLine("PlatformNameLong.get() Error: {0}", ex.ToString()); return Unknown_Platform; } } @@ -342,8 +345,8 @@ } public void RefreshConfig() { - logger.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG)); - this.Create(EmuRomPath); + log.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG)); + this.Create(log,EmuRomPath); } #endregion