/[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	2012/08/23 04:13:19	112
+++ trunk/EmuXPortal/Api/EmuConfig.cs	2014/08/04 05:01:23	170
@@ -31,7 +31,7 @@
         string GameExeArgs { get; }
 
 
-        void RefreshConfig();
+        void RefreshConfig(logger log);
         void ReleasePlatformImageResource();
     }
 
@@ -46,9 +46,9 @@
         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)
+        public static string GetEMUOptions(logger log, IRomConfig config)
         {
-            EMUOptions EMUOptions = new EMUOptions(config);
+            EMUOptions EMUOptions = new EMUOptions(log, 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(IRomConfig config)
+            public EMUOptions(logger log, IRomConfig config)
             {
                 init_dict(config);
-                config.Config.RefreshConfig();
+                config.Config.RefreshConfig(log);
                 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); } }
@@ -84,9 +84,23 @@
             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); }
-
+                if (rom_path == "")
+                {
+                    if (config_path != "")
+                    {
+                        EmuRomPath = config_path.Replace(EMU_CONFIG, "").TrimEnd(new char[] { '\\' });
+                    }
+                    else
+                    {
+                        EmuRomPath = Config.RomPath;
+                    }
+                }
+                else { EmuRomPath = rom_path; }
+                if (config_path == "")
+                {
+                    config_path = string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG);
+                }
+             
                 // read the actual config emu.config
                 FileInfo fi = new FileInfo(config_path);
                 if (fi.Exists)
@@ -129,7 +143,7 @@
                                             if (reader.IsStartElement())
                                             {
                                                 string platform_image = reader.ReadElementContentAsString();
-                                                PlatformImage = (platform_image == "") ? null : Image.FromFile(string.Format(@"{0}\{1}", rom_path, platform_image));
+                                                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);
                                             }
@@ -203,7 +217,7 @@
                                                 //EmuOptions = (external_configs_path == "") ? EmuOptions : value;
                                                 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);
+                                                string ext_rom_path = string.Format(@"{0}\{1}", EmuRomPath, external_configs_path);
                                                 // try the path in romroot
                                                 if (!ext_path.Exists) { ext_path = new DirectoryInfo(ext_rom_path); }
                                                 if (ext_path.Exists)
@@ -216,7 +230,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, rom_path);
+                                                        IEmuConfig config = EmuConfigLoader.Load(log, file, EmuRomPath);
                                                         if (config != null)
                                                             externalconfigs.Add(config);
                                                     }
@@ -343,7 +357,7 @@
             {
                 return this.PlatformNameLong.CompareTo(obj.PlatformNameLong);
             }
-            public void RefreshConfig()
+            public void RefreshConfig(logger log)
             {
                 log.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG));
                 this.Create(log,EmuRomPath);

 

  ViewVC Help
Powered by ViewVC 1.1.22