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

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

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

--- trunk/EmuXPortal/Api/RomParser.cs	2014/08/04 06:31:48	175
+++ trunk/EmuXPortal/Api/RomParser.cs	2014/08/04 11:35:06	199
@@ -30,7 +30,7 @@
         public List<IRomConfig> Roms { get; private set; }
         private List<IRomConfigPair> GetRoms(logger log)
         {
-            if (Config.HasExternalConfigs) { return GetRomsEX(); }
+            if (Config.HasExternalConfigs) { return GetRomsEX(log); }
             string path = Config.EmuRomPath; string searchPattern = Config.Extenstions;
             log.WriteLine("Searching for Roms in Folder: {0}", path);
             Predicate<string> rom_predicate = new Predicate<string>(delegate(string t)
@@ -61,17 +61,56 @@
             return rompairlist;
         }
 
-        private List<IRomConfigPair> GetRomsEX()
+        private List<IRomConfigPair> GetRomsEX(logger log)
         {
             List<IEmuConfig> configs = Config.ExternalConfigs;
             List<IRomConfigPair> roms = new List<IRomConfigPair>();
 
 
-            foreach (IEmuConfig config in configs) { roms.Add(new RomConfigPair(config.GameExe, config)); }
+            foreach (IEmuConfig config in configs)
+            {
+                var reconfig = FixExternalConfig(log,Config, config);
+               roms.Add(new RomConfigPair(reconfig.GameExe, reconfig));
+            }
 
             return roms;
         }
+        private IEmuConfig FixExternalConfig(logger log,IEmuConfig parent_config, IEmuConfig child_config)
+        {
+            string PlatformNameShort = child_config.PlatformNameShort.Contains("Unknown") ? parent_config.PlatformNameShort != "" ? parent_config.PlatformNameShort : "" : child_config.PlatformNameShort;
+            string PlatformNameLong = child_config.PlatformNameLong.Contains("Unknown") ? parent_config.PlatformNameLong != "" ? parent_config.PlatformNameLong : "" : child_config.PlatformNameLong;
+            string PlatformImage = child_config.GameImage == "" ? parent_config.GameImage != "" ? parent_config.GameImage : "" : child_config.GameImage;
+            string Extenstions = child_config.Extenstions == "" ? parent_config.Extenstions != "" ? parent_config.Extenstions : "" : child_config.Extenstions;
+            string EmuPath = child_config.EmuPath == "" ? parent_config.EmuPath != "" ? parent_config.EmuPath : "" : child_config.EmuPath;
+            string EmuOptions = child_config.EmuOptions == "" ? parent_config.EmuOptions != "" ? parent_config.EmuOptions : "" : child_config.EmuOptions;
+
+            FileInfo fi = new FileInfo(PlatformImage);
+            if (!fi.Exists)
+            {
+                PlatformImage = string.Format(@"{0}\{1}", new FileInfo(child_config.GameExe).Directory.FullName, PlatformImage);
+                fi = new FileInfo(PlatformImage);
+                if (!fi.Exists)
+                {
+                    PlatformImage = string.Format(@"{0}\{1}", new FileInfo(parent_config.EmuRomPath).Directory.FullName, PlatformImage);
+                    fi = new FileInfo(PlatformImage);
+                    if (!fi.Exists) { PlatformImage = ""; }
+                }
+            }
+            fi = null;
 
+            EmuXPortal.Api.EmuConfigLoader.EmuConfig c = new EmuConfigLoader.EmuConfig(log, 
+                PlatformNameShort, PlatformNameLong, PlatformImage,
+                Extenstions, EmuPath, EmuOptions);
+            c.EmuRomPath = string.IsNullOrEmpty(child_config.EmuRomPath) ? string.IsNullOrEmpty(parent_config.EmuRomPath) ? "" : parent_config.EmuRomPath : child_config.EmuRomPath;
+
+                        
+            c.GameExe = child_config.GameExe;
+            c.GameExeArgs = child_config.GameExeArgs;
+            c.GameImage = child_config.GameImage;
+            c.GameTitle = child_config.GameTitle;
+            c.ConfigPath = child_config.ConfigPath;
+            return c;
+        }
         private List<IRomConfig> GenerateRomConfig(logger log, List<IRomConfigPair> roms, IEmuConfig config)
         {
             List<IRomConfig> romconfigs = new List<IRomConfig>();
@@ -102,4 +141,4 @@
             Roms = null;
         }
     }
-}
+}
\ No newline at end of file

 

  ViewVC Help
Powered by ViewVC 1.1.22