1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.IO; |
6 |
using System.Drawing; |
7 |
using Enterprise.Logging; |
8 |
|
9 |
namespace EmuXPortal.Api |
10 |
{ |
11 |
public class FavoritePlatform : IEmuConfig |
12 |
{ |
13 |
#region IEmuConfig members |
14 |
public bool IsFavorites { get { return true; } } |
15 |
public string ConfigPath { get { return ""; } } |
16 |
public string PlatformNameShort { get { return "Favorites"; } } |
17 |
public string PlatformNameLong { get { return "Favorites"; } } |
18 |
public Image PlatformImage { get { return Properties.Resources.DefaultPlatformImage; } } |
19 |
public string Extenstions { get { return ""; } } |
20 |
public string EmuPath { get { return ""; } } |
21 |
public string EmuOptions { get { return ""; } } |
22 |
public string EmuRomPath { get { return ""; } set { } } |
23 |
|
24 |
public override string ToString() |
25 |
{ |
26 |
return string.Format("{0}", PlatformNameShort); |
27 |
} |
28 |
|
29 |
public bool HasExternalConfigs { get { return false; } } |
30 |
public List<IEmuConfig> ExternalConfigs { get { return new List<IEmuConfig>(); } } |
31 |
|
32 |
|
33 |
public string GameTitle { get { return ""; } } |
34 |
public string GameImage { get { return ""; } } |
35 |
public string GameExe { get { return ""; } } |
36 |
public string GameExeArgs { get { return ""; } } |
37 |
|
38 |
|
39 |
public void RefreshConfig() { } |
40 |
public void ReleasePlatformImageResource() |
41 |
{ |
42 |
if (this.PlatformImage != null) |
43 |
this.PlatformImage.Dispose(); |
44 |
} |
45 |
public int CompareTo(IEmuConfig obj) |
46 |
{ |
47 |
return this.PlatformNameLong.CompareTo(obj.PlatformNameLong); |
48 |
} |
49 |
public void Dispose() |
50 |
{ |
51 |
if (this.PlatformImage != null) |
52 |
this.PlatformImage.Dispose(); |
53 |
} |
54 |
#endregion |
55 |
} |
56 |
|
57 |
public class PlatformParser : IDisposable |
58 |
{ |
59 |
private const string EMU_IGNORE_FILE = "emu_ignore.txt"; // if this file is present, that folder is ignored |
60 |
|
61 |
public PlatformParser(string path) |
62 |
{ |
63 |
List<string> romdirs = GetRomDirectories(path); |
64 |
gLog.Debug.WriteLine("Found {0} EMU Folders", romdirs.Count); |
65 |
this.Platforms = new List<IEmuConfig>(); |
66 |
this.Platforms.Add(new FavoritePlatform()); |
67 |
var emu_platforms = GetEMUConfigFiles(romdirs); |
68 |
this.Platforms.AddRange(emu_platforms); |
69 |
this.Platforms.Sort(); |
70 |
} |
71 |
|
72 |
public List<IEmuConfig> Platforms { get; private set; } |
73 |
|
74 |
private List<string> GetRomDirectories(string path) |
75 |
{ |
76 |
gLog.Debug.WriteLine("Searching for EMU Folders in: {0}", path); |
77 |
List<string> dirs = new List<string>(); |
78 |
foreach (string dir in Directory.GetDirectories(path)) |
79 |
{ |
80 |
bool ignore = false; |
81 |
foreach (string file in Directory.GetFiles(dir)) |
82 |
{ |
83 |
FileInfo fi = new FileInfo(file); |
84 |
if (fi.Name.ToLower() == EMU_IGNORE_FILE) |
85 |
{ |
86 |
gLog.Debug.WriteLine("\tIgnoreing EMU Folder: {0}", dir); |
87 |
ignore = true; |
88 |
break; |
89 |
} |
90 |
} |
91 |
if (!ignore) |
92 |
{ |
93 |
gLog.Debug.WriteLine("\tAdding EMU Folder: {0}", dir); |
94 |
dirs.Add(dir); |
95 |
} |
96 |
} |
97 |
return dirs; |
98 |
} |
99 |
|
100 |
private List<IEmuConfig> GetEMUConfigFiles(List<string> romdirs) |
101 |
{ |
102 |
List<IEmuConfig> emuconfigs = new List<IEmuConfig>(); |
103 |
gLog.Debug.WriteLine("Reading EMU Config files"); |
104 |
foreach (string dir in romdirs) |
105 |
{ |
106 |
IEmuConfig emuconfig = null; |
107 |
emuconfig = EmuConfigLoader.Load(dir); |
108 |
emuconfigs.Add(emuconfig); |
109 |
} |
110 |
gLog.Debug.WriteLine("Finished Reading EMU Config files"); |
111 |
return emuconfigs; |
112 |
} |
113 |
|
114 |
|
115 |
public void Dispose() |
116 |
{ |
117 |
Platforms.ForEach(x => x.Dispose()); |
118 |
Platforms.Clear(); |
119 |
Platforms = null; |
120 |
} |
121 |
} |
122 |
} |
123 |
|