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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (hide annotations) (download)
Wed Apr 4 04:13:17 2012 UTC (8 years, 6 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 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 william 29 public RomParser(IEmuConfig config)
13 william 18 {
14 william 29 List<string> roms = GetRoms(config.EmuRomPath, config.Extenstions);
15 william 18 logger.WriteLine("Found {0} Roms", roms.Count);
16 william 29 this.Roms = GenerateRomConfig(roms,config);
17 william 18 }
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 william 29 private List<IRomConfig> GenerateRomConfig(List<string> roms, IEmuConfig config)
29 william 18 {
30     List<IRomConfig> romconfigs = new List<IRomConfig>();
31     logger.WriteLine("Generating Rom Configs");
32 william 29 foreach (string rom in roms) { romconfigs.Add(RomLoader.Load(rom, config)); }
33 william 18 return romconfigs;
34     }
35     }
36     }

  ViewVC Help
Powered by ViewVC 1.1.22