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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (hide annotations) (download)
Tue Apr 3 21:39:47 2012 UTC (9 years, 6 months ago) by william
File size: 4011 byte(s)
add more logging in ConfigLoader

1 william 12 #define CONFIGURATION_TESTING // when defined will use config-dbg.ini, otherwise config.ini
2     using System;
3     using System.Collections.Generic;
4     using System.Linq;
5     using System.Text;
6     using System.Windows.Forms;
7 william 13 using System.Xml;
8     using System.IO;
9 william 14 using EmuXPortal.Logging;
10 william 12
11     namespace EmuXPortal.Api
12     {
13     public interface IConfigLoader
14     {
15     bool LoadConfig();
16     bool LoadConfig(string path);
17     }
18     public interface IConfig
19     {
20     string RomPath { get; }
21     string DisplayDevice { get; }
22     }
23     public static class Config
24     {
25     private static ConfigLoader loader = new ConfigLoader();
26     #region public class ConfigLoader : IConfigLoader
27     private class ConfigLoader : IConfigLoader, IConfig
28     {
29     private static string APP_PATH = Application.StartupPath;
30     #if CONFIGURATION_TESTING
31     private static string CONFIG_FILE = "config-dbg.ini";
32     #else
33     private static string CONFIG_FILE = "config.ini";
34     #endif
35     private static string CONFIG_FILE_PATH = string.Format(@"{0}\{1}", APP_PATH, CONFIG_FILE);
36     #region IConfigLoader Members
37     public bool LoadConfig() { return LoadConfig(CONFIG_FILE_PATH); }
38     public bool LoadConfig(string path)
39     {
40     bool loaded = false;
41 william 13 try
42     {
43 william 14 logger.WriteLine("Loading Config: {0}", path);
44 william 13 using (FileStream fs = new FileStream(CONFIG_FILE_PATH, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
45     {
46     using (XmlReader reader = XmlReader.Create(fs))
47     {
48     reader.ReadToFollowing("ROMPATH");
49     RomPath = reader.ReadElementContentAsString();
50 william 15 logger.WriteLine("\tROMPATH={0}", RomPath);
51 william 13 reader.ReadToFollowing("DISPLAYDEVICE");
52     DisplayDevice = reader.ReadElementContentAsString();
53 william 15 logger.WriteLine("\tDISPLAYDEVICE={0}", DisplayDevice);
54 william 13 }
55     }
56 william 14 logger.WriteLine("Loaded Config: {0}", path);
57 william 13 loaded = true;
58     }
59     catch (Exception ex)
60     {
61 william 14 logger.WriteLine("\tFailed to Load Config: {0}", path);
62 william 13 Console.WriteLine(ex.ToString());
63 william 14 logger.WriteLine("Error: {0}", ex.ToString());
64 william 13 loaded = false;
65     }
66 william 12 return loaded;
67     }
68     #endregion
69     #region IConfig Members
70     public string RomPath { get; private set; }
71     public string DisplayDevice { get; private set; }
72     #endregion
73     }
74     #endregion
75    
76     #region IConfigLoader Members
77     public static bool LoadConfig() { return loader.LoadConfig(); }
78     public static bool LoadConfig(string path) { return loader.LoadConfig(path); }
79     #endregion
80    
81     #region IConfig Members
82     public static string RomPath { get { return loader.RomPath; } }
83     public static string DisplayDevice { get { return loader.DisplayDevice; } }
84     #endregion
85 william 13 public static void InitializePresentationForm(Form frm)
86 william 15 {
87 william 13 DisplayHelper helper = new DisplayHelper(DisplayDevice);
88 william 15 logger.WriteLine("Initializing Form: {0}", frm.Name);
89     Screen s = helper.PhysicalDisplayDevice;
90 william 13 frm.Location = new System.Drawing.Point(s.Bounds.X,s.Bounds.Y);
91 william 15 logger.WriteLine("\tLocation={0}", frm.Location.ToString());
92 william 13 frm.Size = s.Bounds.Size;
93 william 15 logger.WriteLine("\tSize={0}", frm.Size.ToString());
94     logger.WriteLine("Initialized Form: {0}", frm.Name);
95 william 13 }
96 william 12 }
97    
98    
99     }

  ViewVC Help
Powered by ViewVC 1.1.22