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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 253 - (hide annotations) (download)
Tue Aug 5 12:48:58 2014 UTC (6 years, 6 months ago) by william
File size: 4341 byte(s)
Reverse merged revision(s) 248-247 from trunk:
+ current WIP for flowlayout panel

........

........

1 william 16 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.IO;
6 william 175 using System.Drawing;
7 william 238 using Enterprise.Logging;
8 william 16
9     namespace EmuXPortal.Api
10     {
11 william 175 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 william 238 public void RefreshConfig() { }
40 william 175 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 william 105 public class PlatformParser : IDisposable
58 william 16 {
59     private const string EMU_IGNORE_FILE = "emu_ignore.txt"; // if this file is present, that folder is ignored
60 william 17
61 william 238 public PlatformParser(string path)
62 william 16 {
63 william 238 List<string> romdirs = GetRomDirectories(path);
64 william 241 gLog.Info.WriteLine("Found {0} EMU Folders", romdirs.Count);
65 william 175 this.Platforms = new List<IEmuConfig>();
66     this.Platforms.Add(new FavoritePlatform());
67 william 238 var emu_platforms = GetEMUConfigFiles(romdirs);
68 william 175 this.Platforms.AddRange(emu_platforms);
69 william 31 this.Platforms.Sort();
70 william 16 }
71    
72 william 17 public List<IEmuConfig> Platforms { get; private set; }
73    
74 william 238 private List<string> GetRomDirectories(string path)
75 william 16 {
76 william 241 gLog.Info.WriteLine("Searching for EMU Folders in: {0}", path);
77 william 16 List<string> dirs = new List<string>();
78     foreach (string dir in Directory.GetDirectories(path))
79     {
80 william 17 bool ignore = false;
81 william 16 foreach (string file in Directory.GetFiles(dir))
82     {
83     FileInfo fi = new FileInfo(file);
84     if (fi.Name.ToLower() == EMU_IGNORE_FILE)
85     {
86 william 241 gLog.Warn.WriteLine("\tIgnoreing EMU Folder: {0}", dir);
87 william 16 ignore = true;
88     break;
89     }
90     }
91     if (!ignore)
92     {
93 william 241 gLog.Info.WriteLine("\tAdding EMU Folder: {0}", dir);
94 william 16 dirs.Add(dir);
95     }
96     }
97     return dirs;
98     }
99    
100 william 238 private List<IEmuConfig> GetEMUConfigFiles(List<string> romdirs)
101 william 17 {
102     List<IEmuConfig> emuconfigs = new List<IEmuConfig>();
103 william 241 gLog.Info.WriteLine("Reading EMU Config files");
104 william 17 foreach (string dir in romdirs)
105     {
106     IEmuConfig emuconfig = null;
107 william 238 emuconfig = EmuConfigLoader.Load(dir);
108 william 17 emuconfigs.Add(emuconfig);
109     }
110 william 241 gLog.Info.WriteLine("Finished Reading EMU Config files");
111 william 17 return emuconfigs;
112     }
113 william 253
114    
115 william 105 public void Dispose()
116     {
117     Platforms.ForEach(x => x.Dispose());
118     Platforms.Clear();
119     Platforms = null;
120     }
121 william 16 }
122     }
123    

  ViewVC Help
Powered by ViewVC 1.1.22