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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (show annotations) (download)
Wed Apr 4 07:22:40 2012 UTC (8 years, 5 months ago) by william
File size: 1788 byte(s)
+ speed-up rom parseing by not logging all found roms

1 //#define LIST_ADDED_ROMS // when defined will log all found rom files
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using EmuXPortal.Logging;
7 using System.IO;
8 using System.Diagnostics;
9
10 namespace EmuXPortal.Api
11 {
12 public class RomParser
13 {
14 public RomParser(IEmuConfig config)
15 {
16 List<string> roms = GetRoms(config.EmuRomPath, config.Extenstions);
17 logger.WriteLine("Found {0} Roms", roms.Count);
18 this.Roms = GenerateRomConfig(roms,config);
19 }
20 public List<IRomConfig> Roms { get; private set; }
21 private List<string> GetRoms(string path, string searchPattern)
22 {
23 logger.WriteLine("Searching for Roms in Folder: {0}", path);
24 List<string> roms = (searchPattern == "*.*")
25 ? new List<string>(Directory.GetFiles(path, "*.*", SearchOption.AllDirectories))
26 : new List<string>(Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Where(s => searchPattern.Contains(Path.GetExtension(s).ToLower())));
27 #region LIST_ADDED_ROMS
28 #if LIST_ADDED_ROMS
29 foreach (string rom in roms)
30 {
31 FileInfo fi = new FileInfo(rom);
32 logger.WriteLine("\tAdding: {0}", fi.Name);
33 }
34 #endif
35 #endregion
36 return roms;
37 }
38 private List<IRomConfig> GenerateRomConfig(List<string> roms, IEmuConfig config)
39 {
40 List<IRomConfig> romconfigs = new List<IRomConfig>();
41 logger.WriteLine("Generating Rom Configs");
42 foreach (string rom in roms) { romconfigs.Add(RomLoader.Load(rom, config)); }
43 return romconfigs;
44 }
45 }
46 }

  ViewVC Help
Powered by ViewVC 1.1.22