/[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/04/04 02:11:37	20
+++ trunk/EmuXPortal/Api/EmuConfig.cs	2012/04/04 03:09:19	23
@@ -20,10 +20,12 @@
         string EmuRomPath { get; set; }
     }
 
+   
 
     public static class EmuConfigLoader
     {
         private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration
+        #region load
         public static IEmuConfig Load(string rom_path) { return Load(string.Empty, rom_path); }
         public static IEmuConfig Load(string config_path, string rom_path)
         {
@@ -44,31 +46,36 @@
                     {
                         using (XmlReader reader = XmlReader.Create(fs))
                         {
+                            string value = "";
                             reader.ReadToFollowing("PLATFORMNAMESHORT");
-                            config.PlatformNameShort = reader.ReadElementContentAsString();
-                            logger.WriteLine("\tPLATFORMNAMESHORT={0}", config.PlatformNameShort);
+                            value = reader.ReadElementContentAsString();
+                            config.PlatformNameShort = (value == "") ? config.PlatformNameShort: value;
+                            logger.WriteLine("\t\tPLATFORMNAMESHORT={0}", config.PlatformNameShort);
 
                             reader.ReadToFollowing("PLATFORMNAMELONG");
-                            config.PlatformNameLong = reader.ReadElementContentAsString();
-                            logger.WriteLine("\tPLATFORMNAMELONG={0}", config.PlatformNameLong);
+                            value = reader.ReadElementContentAsString();
+                            config.PlatformNameLong = (value == "") ? config.PlatformNameLong : value;
+                            logger.WriteLine("\t\tPLATFORMNAMELONG={0}", config.PlatformNameLong);
 
                             reader.ReadToFollowing("PLATFORMIMAGE");
-                            string platform_image = reader.ReadElementContentAsString();
-                            
+                            string platform_image = reader.ReadElementContentAsString();                            
                             config.PlatformImage = (platform_image == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(string.Format(@"{0}\{1}",rom_path,platform_image));
                             string str_platform_image = (platform_image == "") ? "DefaultPlatformImage" : platform_image;
-                            logger.WriteLine("\tPLATFORMIMAGE={0}", str_platform_image);
+                            logger.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image);
 
                             reader.ReadToFollowing("EXTENSIONS");
-                            config.Extenstions = reader.ReadElementContentAsString();
-                            logger.WriteLine("\tEXTENSIONS={0}", config.Extenstions);
+                            value = reader.ReadElementContentAsString();
+                            config.Extenstions = (value == "") ? config.Extenstions : value;
+                            logger.WriteLine("\t\tEXTENSIONS={0}", config.Extenstions);
 
                             reader.ReadToFollowing("EMULATORPATH");
-                            config.EmuPath = reader.ReadElementContentAsString();
-                            logger.WriteLine("\tEMULATORPATH={0}", config.EmuPath);
+                            value = reader.ReadElementContentAsString();
+                            config.EmuPath = (value == "") ? config.EmuPath : value;
+                            logger.WriteLine("\t\tEMULATORPATH={0}", config.EmuPath);
 
                             reader.ReadToFollowing("EMULATOROPTIONS");
-                            config.EmuOptions = reader.ReadElementContentAsString();
+                            value = reader.ReadElementContentAsString();
+                            config.EmuOptions = (value == "") ? config.EmuOptions : value;
                             logger.WriteLine("\tEMULATOROPTIONS={0}", config.EmuOptions);
                         }
                     }
@@ -86,6 +93,36 @@
             else { logger.WriteLine("Could not find EMU Config File: {0}", config_path); }
             return config;
         }
+        #endregion
+        #region parse emu options
+        public static string GetEMUOptions(IRomConfig config)
+        {
+            EMUOptions EMUOptions = new EMUOptions(config);
+            return EMUOptions.Options;
+        }
+        #endregion
+        #region private class EMUOptions
+        private class EMUOptions
+        {
+            private Dictionary<string, string> options_dict = new Dictionary<string, string>();
+            public EMUOptions(IRomConfig config)
+            {
+                init_dict(config);
+                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); } }
+                Options = real_options;
+            }
+            private void init_dict(IRomConfig config)
+            {
+                options_dict.Add("%ROM_FILE%", config.RomFile);
+                options_dict.Add("%ROM_PATH%", config.Config.EmuRomPath);
+            }
+            public const string ROM_FILE = "%ROM_FILE%";
+            public string Options { get; set; }
+        }
+        #endregion
+
         #region private class EmuConfig : IEmuConfig
         private class EmuConfig : IEmuConfig
         {

 

  ViewVC Help
Powered by ViewVC 1.1.22