/[EmuXPortal]/trunk/EmuXPortal/Api/ConfigLoader.cs
ViewVC logotype

Diff of /trunk/EmuXPortal/Api/ConfigLoader.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/EmuXPortal/Api/ConfigLoader.cs	2014/08/04 03:09:45	166
+++ trunk/EmuXPortal/Api/ConfigLoader.cs	2014/08/04 03:10:12	167
@@ -1,4 +1,4 @@
-//#define CONFIGURATION_TESTING // when defined will use config-dbg.ini, otherwise config.ini
+#define CONFIGURATION_TESTING // when defined will use config-dbg.ini, otherwise config.ini
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -29,19 +29,81 @@
             private static string APP_PATH = Application.StartupPath;
 #if CONFIGURATION_TESTING
             private static string CONFIG_FILE = "config-dbg.ini";
+            private static string FAVORITES_FILE = "favorites-dbg.ini";
 #else
-                   private static string CONFIG_FILE = "config.ini";
+            private static string CONFIG_FILE = "config.ini";
+            private static string FAVORITES_FILE = "favorites.ini";
 #endif
-            private static string CONFIG_FILE_PATH = string.Format(@"{0}\{1}", APP_PATH, CONFIG_FILE);
+            private static string CONFIG_FILE_PATH = string.Format(@"{0}\", APP_PATH);
+            private static string CONFIG_FILE_INI = string.Format(@"{0}{1}", CONFIG_FILE_PATH, CONFIG_FILE);
+            private static string FAVORITES_FILE_INI = string.Format(@"{0}{1}", CONFIG_FILE_PATH, FAVORITES_FILE);
             #region IConfigLoader Members
-            public bool LoadConfig(logger log) { return LoadConfig(log, CONFIG_FILE_PATH); }
-            public bool LoadConfig(logger log, string path)
+            private bool LoadFavorites(logger log) { return LoadFavorites(log, FAVORITES_FILE_INI); }
+            private bool LoadFavorites(logger log, string ini)
             {
                 bool loaded = false;
                 try
                 {
-                    log.WriteLine("Loading Config: {0}", path);
-                    using (FileStream fs = new FileStream(CONFIG_FILE_PATH, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+                    log.WriteLine("Loading Favorites: {0}", ini);
+                    FileInfo fi = new FileInfo(ini);
+                    if (!fi.Exists)
+                    {
+                        loaded = false;
+                        log.WriteLine("\tFailed to Load Favorites (file not found): {0}", ini);
+                        return loaded;
+                    }
+                    using (FileStream fs = new FileStream(ini, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+                    {
+                        using (XmlReader reader = XmlReader.Create(fs))
+                        {
+                            //reader.ReadToFollowing("ROMPATH");
+                            //RomPath = reader.ReadElementContentAsString();
+                            //if (RomPath == "")
+                            //{
+                            //    log.WriteLine("\t\tROMPATH has not been configured...");
+                            //    MessageBox.Show("Please edit config.ini and update ROMPATH to point to your roms folder", "ROMPATH has not been configured", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                            //    log.WriteLine("Terminating application...");
+                            //    Application.Exit();
+                            //}
+                            //log.WriteLine("\tROMPATH={0}", RomPath);
+                            //reader.ReadToFollowing("DISPLAYDEVICE");
+                            //DisplayDevice = reader.ReadElementContentAsString();
+                            //if (DisplayDevice == "")
+                            //{
+                            //    log.WriteLine("\t\tDISPLAYDEVICE was an empty string...using defaults: {0}", new DisplayHelper(log).PhysicalDisplayDevice.DeviceName);
+                            //    DisplayDevice = new DisplayHelper(log).PhysicalDisplayDevice.DeviceName;
+                            //}
+                            //log.WriteLine("\tDISPLAYDEVICE={0}", DisplayDevice);
+                        }
+                    }
+                    log.WriteLine("Loaded Favorites: {0}", ini);
+                    loaded = true;
+
+                }
+                catch (Exception ex)
+                {
+                    log.WriteLine("\tFailed to Load Favorites: {0}", ini);
+                    Console.WriteLine(ex.ToString());
+                    log.WriteLine("Error: {0}", ex.ToString());
+                    loaded = false;
+                }
+                return loaded;
+            }
+            public bool LoadConfig(logger log) { return LoadConfig(log, CONFIG_FILE_INI); }
+            public bool LoadConfig(logger log, string ini)
+            {
+                bool loaded = false;
+                try
+                {
+                    log.WriteLine("Loading Config: {0}", ini);
+                    FileInfo fi = new FileInfo(ini);
+                    if (!fi.Exists)
+                    {
+                        loaded = false;
+                        log.WriteLine("\tFailed to Load Config (file not found): {0}", ini);
+                        return loaded;
+                    }
+                    using (FileStream fs = new FileStream(ini, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                     {
                         using (XmlReader reader = XmlReader.Create(fs))
                         {
@@ -65,13 +127,17 @@
                             log.WriteLine("\tDISPLAYDEVICE={0}", DisplayDevice);
                         }
                     }
-                    log.WriteLine("Loaded Config: {0}", path);
-                    loaded = true;
-
+                    log.WriteLine("Loaded Config: {0}", ini);
+                    loaded = LoadFavorites(log);
+                    if (!loaded)
+                    {
+                        log.WriteLine("\tFailed to Load Favorites while loading the main config: {0}", ini);
+                    }
+                   
                 }
                 catch (Exception ex)
                 {
-                    log.WriteLine("\tFailed to Load Config: {0}", path);
+                    log.WriteLine("\tFailed to Load Config: {0}", ini);
                     Console.WriteLine(ex.ToString());
                     log.WriteLine("Error: {0}", ex.ToString());
                     loaded = false;

 

  ViewVC Help
Powered by ViewVC 1.1.22