1 |
william |
17 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
|
|
using System.Drawing; |
6 |
|
|
using System.IO; |
7 |
|
|
using EmuXPortal.Logging; |
8 |
|
|
|
9 |
|
|
namespace EmuXPortal.Api |
10 |
|
|
{ |
11 |
|
|
public interface IEmuConfig |
12 |
|
|
{ |
13 |
|
|
string PlatformNameShort { get; } |
14 |
|
|
string PlatformNameLong { get; } |
15 |
|
|
Image PlatformImage { get; } |
16 |
|
|
string Extenstions { get; } |
17 |
|
|
string EmuPath { get; } |
18 |
|
|
string EmuOptions { get; } |
19 |
|
|
string EmuRomPath { get; set; } |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
public static class EmuConfigLoader |
24 |
|
|
{ |
25 |
|
|
private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration |
26 |
|
|
public static IEmuConfig Load(string rom_path) { return Load(string.Empty, rom_path); } |
27 |
|
|
public static IEmuConfig Load(string config_path, string rom_path) |
28 |
|
|
{ |
29 |
|
|
EmuConfig config = new EmuConfig(); |
30 |
|
|
config.EmuRomPath = rom_path; |
31 |
|
|
if (config_path == "") { config_path = string.Format(@"{0}\{1}", rom_path, EMU_CONFIG); } |
32 |
|
|
|
33 |
|
|
// read the actual config emu.config |
34 |
|
|
FileInfo fi = new FileInfo(config_path); |
35 |
|
|
if (fi.Exists) |
36 |
|
|
{ |
37 |
|
|
logger.WriteLine("Found EMU Config File: {0}", config_path); |
38 |
|
|
} |
39 |
|
|
else |
40 |
|
|
{ |
41 |
|
|
logger.WriteLine("Could not find EMU Config File: {0}", config_path); |
42 |
|
|
} |
43 |
|
|
return config; |
44 |
|
|
} |
45 |
|
|
#region private class EmuConfig : IEmuConfig |
46 |
|
|
private class EmuConfig : IEmuConfig |
47 |
|
|
{ |
48 |
|
|
private const string Unknown_Platform = "Unknown Platform"; |
49 |
|
|
public EmuConfig() : this("") { } |
50 |
|
|
public EmuConfig(string PlatformNameShort) : this(PlatformNameShort, PlatformNameShort) { } |
51 |
|
|
public EmuConfig(string PlatformNameShort, string PlatformNameLong) : this(PlatformNameShort, PlatformNameLong, "") { } |
52 |
|
|
public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage) : this(PlatformNameShort, PlatformNameLong, PlatformImage, "") { } |
53 |
|
|
public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions) : this(PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, "") { } |
54 |
|
|
public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath) : this(PlatformNameShort, PlatformNameLong, PlatformImage, Extenstions, EmuPath, "") { } |
55 |
|
|
public EmuConfig(string PlatformNameShort, string PlatformNameLong, string PlatformImage, string Extenstions, string EmuPath, string EmuOptions) |
56 |
|
|
{ |
57 |
|
|
this.PlatformNameShort = PlatformNameShort; |
58 |
|
|
this.PlatformNameLong = PlatformNameLong; |
59 |
|
|
this.PlatformImage = (PlatformImage == "") ? Properties.Resources.DefaultPlatformImage : Image.FromFile(PlatformImage); |
60 |
|
|
this.Extenstions = (Extenstions == "") ? "*.*" : Extenstions; |
61 |
|
|
this.EmuPath = EmuPath; |
62 |
|
|
this.EmuOptions = EmuOptions; |
63 |
|
|
} |
64 |
|
|
#region IEmuConfig members |
65 |
|
|
private string _PlatformNameShort; |
66 |
|
|
public string PlatformNameShort |
67 |
|
|
{ |
68 |
|
|
get |
69 |
|
|
{ |
70 |
|
|
try |
71 |
|
|
{ |
72 |
|
|
DirectoryInfo t = new DirectoryInfo(EmuRomPath); |
73 |
|
|
return (_PlatformNameShort == "") ? string.Format("{0} (folder={1})", Unknown_Platform, t.Name) : _PlatformNameShort; |
74 |
|
|
} |
75 |
|
|
catch(Exception ex) |
76 |
|
|
{ |
77 |
|
|
logger.WriteLine("PlatformNameShort.get() Error: {0}",ex.ToString()); |
78 |
|
|
return Unknown_Platform; |
79 |
|
|
} |
80 |
|
|
} |
81 |
|
|
private set { _PlatformNameShort = value; } |
82 |
|
|
} |
83 |
|
|
private string _PlatformNameLong; |
84 |
|
|
public string PlatformNameLong |
85 |
|
|
{ |
86 |
|
|
get |
87 |
|
|
{ |
88 |
|
|
try |
89 |
|
|
{ |
90 |
|
|
DirectoryInfo t = new DirectoryInfo(EmuRomPath); |
91 |
|
|
return (_PlatformNameLong == "") ? string.Format("{0} (folder={1})", Unknown_Platform, t.Name) : _PlatformNameLong; |
92 |
|
|
} |
93 |
|
|
catch (Exception ex) |
94 |
|
|
{ |
95 |
|
|
logger.WriteLine("PlatformNameLong.get() Error: {0}", ex.ToString()); |
96 |
|
|
return Unknown_Platform; |
97 |
|
|
} |
98 |
|
|
} |
99 |
|
|
private set { _PlatformNameLong = value; } |
100 |
|
|
} |
101 |
|
|
public Image PlatformImage { get; private set; } |
102 |
|
|
public string Extenstions { get; private set; } |
103 |
|
|
public string EmuPath { get; private set; } |
104 |
|
|
public string EmuOptions { get; private set; } |
105 |
|
|
public string EmuRomPath { get; set; } |
106 |
|
|
#endregion |
107 |
|
|
} |
108 |
|
|
#endregion |
109 |
|
|
|
110 |
|
|
} |
111 |
|
|
} |