/[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:39:20	22
+++ trunk/EmuXPortal/Api/EmuConfig.cs	2012/04/04 05:42:03	32
@@ -9,7 +9,7 @@
 
 namespace EmuXPortal.Api
 {
-    public interface IEmuConfig
+    public interface IEmuConfig : IComparable
     {
         string PlatformNameShort { get; }
         string PlatformNameLong { get; }
@@ -18,12 +18,15 @@
         string EmuPath { get; }
         string EmuOptions { get; }
         string EmuRomPath { get; set; }
+        string ToString();
     }
 
+   
 
     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)
         {
@@ -89,10 +92,44 @@
                 }
             }
             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
+        {
+            #region Replaceable Constant Options
+            private const string ROM_FILE = "%ROM_FILE%";
+            private const string ROM_PATH = "%ROM_PATH%";
+            #endregion
+            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 string Options { get; set; }
+        }
+        #endregion
+
         #region private class EmuConfig : IEmuConfig
-        private class EmuConfig : IEmuConfig
+        private class EmuConfig : IEmuConfig, IComparable
         {
             private const string Unknown_Platform = "Unknown Platform";
             public EmuConfig() : this("") { }
@@ -153,6 +190,19 @@
             public string EmuOptions { get; set; }
             public string EmuRomPath { get; set; }
             #endregion      
+        
+            public override string ToString()
+            {
+                return string.Format("{2} {0}{3}{1}","{","}", PlatformNameLong,PlatformNameShort);
+            }
+            #region IComparable Members
+
+            public int CompareTo(object obj)
+            {
+                return this.PlatformNameLong.CompareTo((obj as EmuConfig).PlatformNameLong);
+            }
+
+            #endregion
         }
         #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22