1 |
william |
18 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
|
|
using EmuXPortal.Logging; |
6 |
|
|
using System.IO; |
7 |
|
|
|
8 |
|
|
namespace EmuXPortal.Api |
9 |
|
|
{ |
10 |
|
|
public class RomParser |
11 |
|
|
{ |
12 |
|
|
public RomParser(string path, string searchPattern) |
13 |
|
|
{ |
14 |
|
|
List<string> roms = GetRoms(path, searchPattern); |
15 |
|
|
logger.WriteLine("Found {0} Roms", roms.Count); |
16 |
|
|
this.Roms = GenerateRomConfig(roms); |
17 |
|
|
} |
18 |
|
|
public List<IRomConfig> Roms { get; private set; } |
19 |
|
|
private List<string> GetRoms(string path, string searchPattern) |
20 |
|
|
{ |
21 |
william |
26 |
logger.WriteLine("Searching for Roms in Folder: {0}", path); |
22 |
|
|
List<string> roms = (searchPattern == "*.*") |
23 |
|
|
? new List<string>(Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)) |
24 |
|
|
: new List<string>(Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Where(s => searchPattern.Contains(Path.GetExtension(s).ToLower()))); |
25 |
|
|
foreach (string rom in roms) { FileInfo fi = new FileInfo(rom); logger.WriteLine("\tAdding: {0}", fi.Name); } |
26 |
william |
18 |
return roms; |
27 |
|
|
} |
28 |
|
|
private List<IRomConfig> GenerateRomConfig(List<string> roms) |
29 |
|
|
{ |
30 |
|
|
List<IRomConfig> romconfigs = new List<IRomConfig>(); |
31 |
|
|
logger.WriteLine("Generating Rom Configs"); |
32 |
|
|
foreach (string rom in roms) { romconfigs.Add(RomLoader.Load(rom)); } |
33 |
|
|
return romconfigs; |
34 |
|
|
} |
35 |
|
|
} |
36 |
|
|
} |