/[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	2014/08/04 05:01:23	170
+++ trunk/EmuXPortal/Api/EmuConfig.cs	2014/08/04 12:39:13	200
@@ -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; }
@@ -33,9 +35,7 @@
 
         void RefreshConfig(logger log);
         void ReleasePlatformImageResource();
-    }
-
-
+    }    
 
     public static class EmuConfigLoader
     {
@@ -79,11 +79,12 @@
         #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)
             {
+                IEmuConfig parent_rom = null;
                 if (rom_path == "")
                 {
                     if (config_path != "")
@@ -100,7 +101,36 @@
                 {
                     config_path = string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG);
                 }
-             
+
+
+                if (rom_path == "")
+                {
+                    FileInfo emu_config = new FileInfo(string.Format(@"{0}\{1}", new FileInfo(config_path).Directory, EMU_CONFIG));
+                    //if (emu_config.Exists)
+                    //{
+                    //    EmuRomPath = emu_config.Directory.FullName;
+                    //}
+                    while (!emu_config.Exists)
+                    {
+                        try
+                        {
+                            emu_config = new FileInfo(string.Format(@"{0}\{1}", emu_config.Directory.Parent.FullName, EMU_CONFIG));                           
+                        }
+                        catch (Exception)
+                        {
+                            break;
+                        }
+                    }
+                    if (emu_config.Exists)
+                    {
+                        EmuRomPath = emu_config.Directory.FullName;
+                        // load the rom config
+                        parent_rom = EmuConfigLoader.Load(log, emu_config.FullName, EmuRomPath);
+                    }
+
+                    
+                }
+
                 // read the actual config emu.config
                 FileInfo fi = new FileInfo(config_path);
                 if (fi.Exists)
@@ -262,6 +292,23 @@
                 }
                 else { log.WriteLine("Could not find EMU Config File: {0}", config_path); }
 
+                if (parent_rom != null)
+                {
+                    if (parent_rom.HasExternalConfigs)
+                    {
+                        foreach (var rom in parent_rom.ExternalConfigs)
+                        {
+                            if (rom.ConfigPath == config_path)
+                            {
+                                this.PlatformNameShort = parent_rom.PlatformNameShort;
+                                this.PlatformNameLong = parent_rom.PlatformNameLong;
+                                break;
+                            }
+                        }
+                        
+                    }
+                }
+
                 return this;
             }
 
@@ -276,6 +323,9 @@
             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)
             {
+                
+                
+
                 this.PlatformNameShort = PlatformNameShort;
                 this.PlatformNameLong = PlatformNameLong;
                 this.PlatformImage = (PlatformImage == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(PlatformImage);
@@ -290,6 +340,7 @@
                 this.log = log;
             }
             #region IEmuConfig members
+            public bool IsFavorites { get { return false; } }
             public string ConfigPath { get; set; }
             private string _PlatformNameShort;
             public string PlatformNameShort
@@ -298,8 +349,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)
                     {

 

  ViewVC Help
Powered by ViewVC 1.1.22