19 |
string EmuOptions { get; } |
string EmuOptions { get; } |
20 |
string EmuRomPath { get; set; } |
string EmuRomPath { get; set; } |
21 |
string ToString(); |
string ToString(); |
22 |
|
|
23 |
|
void RefreshConfig(); |
24 |
} |
} |
25 |
|
|
26 |
|
|
29 |
{ |
{ |
30 |
private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration |
private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration |
31 |
#region load |
#region load |
32 |
public static IEmuConfig Load(string rom_path) { return Load(string.Empty, rom_path); } |
public static IEmuConfig Load(string rom_path) { return new EmuConfig().Create(rom_path); } |
33 |
public static IEmuConfig Load(string config_path, string rom_path) |
public static IEmuConfig Load(string config_path, string rom_path) { return new EmuConfig().Create(config_path, rom_path); } |
|
{ |
|
|
EmuConfig config = new EmuConfig(); |
|
|
config.EmuRomPath = rom_path; |
|
|
if (config_path == "") { config_path = string.Format(@"{0}\{1}", rom_path, EMU_CONFIG); } |
|
|
|
|
|
// read the actual config emu.config |
|
|
FileInfo fi = new FileInfo(config_path); |
|
|
if (fi.Exists) |
|
|
{ |
|
|
logger.WriteLine("Found EMU Config File: {0}", config_path); |
|
|
logger.WriteLine("\tLoading Config: {0}", config_path); |
|
|
//bool loaded = false; |
|
|
try |
|
|
{ |
|
|
using (FileStream fs = new FileStream(config_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) |
|
|
{ |
|
|
using (XmlReader reader = XmlReader.Create(fs)) |
|
|
{ |
|
|
string value = ""; |
|
|
reader.ReadToFollowing("PLATFORMNAMESHORT"); |
|
|
value = reader.ReadElementContentAsString(); |
|
|
config.PlatformNameShort = (value == "") ? config.PlatformNameShort: value; |
|
|
logger.WriteLine("\t\tPLATFORMNAMESHORT={0}", config.PlatformNameShort); |
|
|
|
|
|
reader.ReadToFollowing("PLATFORMNAMELONG"); |
|
|
value = reader.ReadElementContentAsString(); |
|
|
config.PlatformNameLong = (value == "") ? config.PlatformNameLong : value; |
|
|
logger.WriteLine("\t\tPLATFORMNAMELONG={0}", config.PlatformNameLong); |
|
|
|
|
|
reader.ReadToFollowing("PLATFORMIMAGE"); |
|
|
string platform_image = reader.ReadElementContentAsString(); |
|
|
config.PlatformImage = (platform_image == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(string.Format(@"{0}\{1}",rom_path,platform_image)); |
|
|
string str_platform_image = (platform_image == "") ? "DefaultPlatformImage" : platform_image; |
|
|
logger.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image); |
|
|
|
|
|
reader.ReadToFollowing("EXTENSIONS"); |
|
|
value = reader.ReadElementContentAsString(); |
|
|
config.Extenstions = (value == "") ? config.Extenstions : value; |
|
|
logger.WriteLine("\t\tEXTENSIONS={0}", config.Extenstions); |
|
|
|
|
|
reader.ReadToFollowing("EMULATORPATH"); |
|
|
value = reader.ReadElementContentAsString(); |
|
|
config.EmuPath = (value == "") ? config.EmuPath : value; |
|
|
logger.WriteLine("\t\tEMULATORPATH={0}", config.EmuPath); |
|
|
|
|
|
reader.ReadToFollowing("EMULATOROPTIONS"); |
|
|
value = reader.ReadElementContentAsString(); |
|
|
config.EmuOptions = (value == "") ? config.EmuOptions : value; |
|
|
logger.WriteLine("\tEMULATOROPTIONS={0}", config.EmuOptions); |
|
|
} |
|
|
} |
|
|
logger.WriteLine("\tLoaded Config: {0}", config_path); |
|
|
//loaded = true; |
|
|
} |
|
|
catch(Exception ex) |
|
|
{ |
|
|
logger.WriteLine("\tFailed to Load Config: {0}", config_path); |
|
|
Console.WriteLine(ex.ToString()); |
|
|
logger.WriteLine("Error: {0}", ex.ToString()); |
|
|
//loaded = false; |
|
|
} |
|
|
} |
|
|
else { logger.WriteLine("Could not find EMU Config File: {0}", config_path); } |
|
|
|
|
|
return config; |
|
|
} |
|
34 |
#endregion |
#endregion |
35 |
#region parse emu options |
#region parse emu options |
36 |
public static string GetEMUOptions(IRomConfig config) |
public static string GetEMUOptions(IRomConfig config) |
50 |
public EMUOptions(IRomConfig config) |
public EMUOptions(IRomConfig config) |
51 |
{ |
{ |
52 |
init_dict(config); |
init_dict(config); |
53 |
|
config.Config.RefreshConfig(); |
54 |
string options = config.Config.EmuOptions; |
string options = config.Config.EmuOptions; |
55 |
string real_options = options; |
string real_options = options; |
56 |
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); } } |
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); } } |
68 |
#region private class EmuConfig : IEmuConfig |
#region private class EmuConfig : IEmuConfig |
69 |
private class EmuConfig : IEmuConfig, IComparable |
private class EmuConfig : IEmuConfig, IComparable |
70 |
{ |
{ |
71 |
|
public IEmuConfig Create(string rom_path) { return this.Create(string.Empty, rom_path); } |
72 |
|
public IEmuConfig Create(string config_path, string rom_path) |
73 |
|
{ |
74 |
|
EmuRomPath = rom_path; |
75 |
|
if (config_path == "") { config_path = string.Format(@"{0}\{1}", rom_path, EMU_CONFIG); } |
76 |
|
|
77 |
|
// read the actual config emu.config |
78 |
|
FileInfo fi = new FileInfo(config_path); |
79 |
|
if (fi.Exists) |
80 |
|
{ |
81 |
|
logger.WriteLine("Found EMU Config File: {0}", config_path); |
82 |
|
logger.WriteLine("\tLoading Config: {0}", config_path); |
83 |
|
//bool loaded = false; |
84 |
|
try |
85 |
|
{ |
86 |
|
using (FileStream fs = new FileStream(config_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) |
87 |
|
{ |
88 |
|
using (XmlReader reader = XmlReader.Create(fs)) |
89 |
|
{ |
90 |
|
string value = ""; |
91 |
|
reader.ReadToFollowing("PLATFORMNAMESHORT"); |
92 |
|
value = reader.ReadElementContentAsString(); |
93 |
|
PlatformNameShort = (value == "") ? PlatformNameShort : value; |
94 |
|
logger.WriteLine("\t\tPLATFORMNAMESHORT={0}", PlatformNameShort); |
95 |
|
|
96 |
|
reader.ReadToFollowing("PLATFORMNAMELONG"); |
97 |
|
value = reader.ReadElementContentAsString(); |
98 |
|
PlatformNameLong = (value == "") ? PlatformNameLong : value; |
99 |
|
logger.WriteLine("\t\tPLATFORMNAMELONG={0}", PlatformNameLong); |
100 |
|
|
101 |
|
reader.ReadToFollowing("PLATFORMIMAGE"); |
102 |
|
string platform_image = reader.ReadElementContentAsString(); |
103 |
|
PlatformImage = (platform_image == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(string.Format(@"{0}\{1}", rom_path, platform_image)); |
104 |
|
string str_platform_image = (platform_image == "") ? "DefaultPlatformImage" : platform_image; |
105 |
|
logger.WriteLine("\t\tPLATFORMIMAGE={0}", str_platform_image); |
106 |
|
|
107 |
|
reader.ReadToFollowing("EXTENSIONS"); |
108 |
|
value = reader.ReadElementContentAsString(); |
109 |
|
Extenstions = (value == "") ? Extenstions : value; |
110 |
|
logger.WriteLine("\t\tEXTENSIONS={0}", Extenstions); |
111 |
|
|
112 |
|
reader.ReadToFollowing("EMULATORPATH"); |
113 |
|
value = reader.ReadElementContentAsString(); |
114 |
|
EmuPath = (value == "") ? EmuPath : value; |
115 |
|
logger.WriteLine("\t\tEMULATORPATH={0}", EmuPath); |
116 |
|
|
117 |
|
reader.ReadToFollowing("EMULATOROPTIONS"); |
118 |
|
value = reader.ReadElementContentAsString(); |
119 |
|
EmuOptions = (value == "") ? EmuOptions : value; |
120 |
|
logger.WriteLine("\tEMULATOROPTIONS={0}", EmuOptions); |
121 |
|
} |
122 |
|
} |
123 |
|
logger.WriteLine("\tLoaded Config: {0}", config_path); |
124 |
|
//loaded = true; |
125 |
|
} |
126 |
|
catch (Exception ex) |
127 |
|
{ |
128 |
|
logger.WriteLine("\tFailed to Load Config: {0}", config_path); |
129 |
|
Console.WriteLine(ex.ToString()); |
130 |
|
logger.WriteLine("Error: {0}", ex.ToString()); |
131 |
|
//loaded = false; |
132 |
|
} |
133 |
|
} |
134 |
|
else { logger.WriteLine("Could not find EMU Config File: {0}", config_path); } |
135 |
|
|
136 |
|
return this; |
137 |
|
} |
138 |
|
|
139 |
private const string Unknown_Platform = "Unknown Platform"; |
private const string Unknown_Platform = "Unknown Platform"; |
140 |
public EmuConfig() : this("") { } |
public EmuConfig() : this("") { } |
141 |
public EmuConfig(string PlatformNameShort) : this(PlatformNameShort, PlatformNameShort) { } |
public EmuConfig(string PlatformNameShort) : this(PlatformNameShort, PlatformNameShort) { } |
206 |
{ |
{ |
207 |
return this.PlatformNameLong.CompareTo((obj as EmuConfig).PlatformNameLong); |
return this.PlatformNameLong.CompareTo((obj as EmuConfig).PlatformNameLong); |
208 |
} |
} |
209 |
|
public void RefreshConfig() |
210 |
|
{ |
211 |
|
logger.WriteLine("Refreshing config for: {0} from {1}", this.ToString(), string.Format(@"{0}\{1}", EmuRomPath, EMU_CONFIG)); |
212 |
|
this.Create(EmuRomPath); |
213 |
|
} |
214 |
#endregion |
#endregion |
215 |
} |
} |
216 |
#endregion |
#endregion |