/[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 11:35:06	199
@@ -6,11 +6,13 @@
 using System.IO;
 using EmuXPortal.Logging;
 using System.Xml;
+using System.Diagnostics;
 
 namespace EmuXPortal.Api
 {
     public interface IEmuConfig : IComparable<IEmuConfig>, IDisposable
     {
+        bool IsFavorites { get; }
         string ConfigPath { get; }
         string PlatformNameShort { get; }
         string PlatformNameLong { get; }
@@ -31,11 +33,9 @@
         string GameExeArgs { get; }
 
 
-        void RefreshConfig();
+        void RefreshConfig(logger log);
         void ReleasePlatformImageResource();
-    }
-
-
+    }    
 
     public static class EmuConfigLoader
     {
@@ -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); } }
@@ -79,14 +79,28 @@
         #endregion
 
         #region private class EmuConfig : IEmuConfig
-        private class EmuConfig : IEmuConfig, IComparable<IEmuConfig>, IDisposable
+        internal class EmuConfig : IEmuConfig, IComparable<IEmuConfig>, IDisposable
         {
             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);
                                                     }
@@ -262,6 +276,11 @@
             public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath) : this(log, PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, EmuPath, "") { }
             public EmuConfig(logger log, string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath, string EmuOptions)
             {
+                //if (string.IsNullOrEmpty(EmuRomPath))
+                //{
+                //    if (Debugger.IsAttached)
+                //        Debugger.Break();
+                //}
                 this.PlatformNameShort = PlatformNameShort;
                 this.PlatformNameLong = PlatformNameLong;
                 this.PlatformImage = (PlatformImage == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(PlatformImage);
@@ -276,6 +295,7 @@
                 this.log = log;
             }
             #region IEmuConfig members
+            public bool IsFavorites { get { return false; } }
             public string ConfigPath { get; set; }
             private string _PlatformNameShort;
             public string PlatformNameShort
@@ -284,8 +304,13 @@
                 {
                     try
                     {
-                        DirectoryInfo t = new DirectoryInfo(EmuRomPath);
+                        //if (string.IsNullOrEmpty(EmuRomPath))
+                        //{
+                        //    return "EmuRomPath null";
+                        //}
+                        DirectoryInfo t = new DirectoryInfo(EmuRomPath);                      
                         return (_PlatformNameShort == "") ? string.Format("{0} (folder={1})", Unknown_Platform, t.Name) : _PlatformNameShort;
+                        
                     }
                     catch (Exception ex)
                     {
@@ -343,7 +368,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