/[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	2012/04/04 07:22:40	38
+++ trunk/EmuXPortal/Api/RomParser.cs	2012/06/19 03:38:40	85
@@ -11,15 +11,19 @@
 {
     public class RomParser
     {
+        private IEmuConfig Config { get; set; }
         public RomParser(IEmuConfig config)
         {
-            List<string> roms = GetRoms(config.EmuRomPath, config.Extenstions);
+            this.Config = config;
+            List<IRomConfigPair> roms = GetRoms();
             logger.WriteLine("Found {0} Roms", roms.Count);
             this.Roms = GenerateRomConfig(roms,config);
         }
         public List<IRomConfig> Roms { get; private set; }
-        private List<string> GetRoms(string path, string searchPattern)
+        private List<IRomConfigPair> GetRoms()
         {
+            if (Config.HasExternalConfigs) { return GetRomsEX(); }
+            string path = Config.EmuRomPath; string searchPattern = Config.Extenstions;
             logger.WriteLine("Searching for Roms in Folder: {0}", path);
             List<string> roms = (searchPattern == "*.*")
                 ? new List<string>(Directory.GetFiles(path, "*.*", SearchOption.AllDirectories))
@@ -32,15 +36,47 @@
                 logger.WriteLine("\tAdding: {0}", fi.Name);
             }
 #endif
+            List<IRomConfigPair> rompairlist = new List<IRomConfigPair>();
+            foreach (string rom in roms)
+            {
+                rompairlist.Add(new RomConfigPair(rom, Config));
+            }
             #endregion
+            return rompairlist;
+        }
+
+        private List<IRomConfigPair> GetRomsEX()
+        {
+            List<IEmuConfig> configs = Config.ExternalConfigs;
+            List<IRomConfigPair> roms = new List<IRomConfigPair>();
+
+
+            foreach (IEmuConfig config in configs) { roms.Add(new RomConfigPair(config.GameExe, config)); }
+
             return roms;
         }
-        private List<IRomConfig> GenerateRomConfig(List<string> roms, IEmuConfig config)
+
+        private List<IRomConfig> GenerateRomConfig(List<IRomConfigPair> roms, IEmuConfig config)
         {
             List<IRomConfig> romconfigs = new List<IRomConfig>();
             logger.WriteLine("Generating Rom Configs");
-            foreach (string rom in roms) { romconfigs.Add(RomLoader.Load(rom, config)); }
+            foreach (IRomConfigPair rom in roms) { romconfigs.Add(RomLoader.Load(rom.RomFile, rom.RomConfig)); }
             return romconfigs;
         }
+
+        private interface IRomConfigPair
+        {
+            string RomFile { get; }
+            IEmuConfig RomConfig { get; }
+        }
+        private class RomConfigPair : IRomConfigPair
+        {
+            public RomConfigPair() : this("", EmuConfigLoader.Empty) { }
+            public RomConfigPair(string romFile, IEmuConfig romConfig) { RomFile = romFile; RomConfig = romConfig; }
+            #region IRomConfigPair members
+            public string RomFile { get; private set; }
+            public IEmuConfig RomConfig { get; private set; }
+            #endregion
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22