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

Contents of /trunk/EmuXPortal/Api/RomParser.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (show annotations) (download)
Wed Apr 4 04:13:17 2012 UTC (8 years, 5 months ago) by william
File size: 1553 byte(s)
+ speed up rom parsing by passing in the EMUConfig (rather than re-generating it each time)

1 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(IEmuConfig config)
13 {
14 List<string> roms = GetRoms(config.EmuRomPath, config.Extenstions);
15 logger.WriteLine("Found {0} Roms", roms.Count);
16 this.Roms = GenerateRomConfig(roms,config);
17 }
18 public List<IRomConfig> Roms { get; private set; }
19 private List<string> GetRoms(string path, string searchPattern)
20 {
21 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 return roms;
27 }
28 private List<IRomConfig> GenerateRomConfig(List<string> roms, IEmuConfig config)
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, config)); }
33 return romconfigs;
34 }
35 }
36 }

  ViewVC Help
Powered by ViewVC 1.1.22