3 |
|
using System.Collections.Generic; |
4 |
|
using System.Linq; |
5 |
|
using System.Text; |
6 |
– |
using EmuXPortal.Logging; |
6 |
|
using System.IO; |
7 |
|
using System.Diagnostics; |
8 |
+ |
using Enterprise.Logging; |
9 |
|
|
10 |
|
namespace EmuXPortal.Api |
11 |
|
{ |
12 |
|
public class RomParser :IDisposable |
13 |
|
{ |
14 |
|
private IEmuConfig Config { get; set; } |
15 |
< |
public RomParser(logger log, IEmuConfig config) |
15 |
> |
public RomParser(IEmuConfig config) |
16 |
|
{ |
17 |
|
this.Config = config; |
18 |
|
if (!this.Config.IsFavorites) |
19 |
|
{ |
20 |
< |
List<IRomConfigPair> roms = GetRoms(log); |
21 |
< |
log.WriteLine("Found {0} Roms", roms.Count); |
22 |
< |
this.Roms = GenerateRomConfig(log, roms, config); |
20 |
> |
List<IRomConfigPair> roms = GetRoms(); |
21 |
> |
gLog.Debug.WriteLine("Found {0} Roms", roms.Count); |
22 |
> |
this.Roms = GenerateRomConfig(roms, config); |
23 |
|
} |
24 |
|
else |
25 |
|
{ |
26 |
< |
this.Roms = RomFavorite.GetRoms(log); |
27 |
< |
log.WriteLine("Found {0} Roms", this.Roms.Count); |
26 |
> |
this.Roms = RomFavorite.GetRoms(); |
27 |
> |
gLog.Debug.WriteLine("Found {0} Roms", this.Roms.Count); |
28 |
|
} |
29 |
|
} |
30 |
|
public List<IRomConfig> Roms { get; private set; } |
31 |
< |
private List<IRomConfigPair> GetRoms(logger log) |
31 |
> |
private List<IRomConfigPair> GetRoms() |
32 |
|
{ |
33 |
< |
if (Config.HasExternalConfigs) { return GetRomsEX(log); } |
33 |
> |
if (Config.HasExternalConfigs) { return GetRomsEX(); } |
34 |
|
string path = Config.EmuRomPath; string searchPattern = Config.Extenstions; |
35 |
< |
log.WriteLine("Searching for Roms in Folder: {0}", path); |
35 |
> |
gLog.Debug.WriteLine("Searching for Roms in Folder: {0}", path); |
36 |
|
Predicate<string> rom_predicate = new Predicate<string>(delegate(string t) |
37 |
|
{ |
38 |
|
string search_exts = searchPattern.Replace("*", ""); |
61 |
|
return rompairlist; |
62 |
|
} |
63 |
|
|
64 |
< |
private List<IRomConfigPair> GetRomsEX(logger log) |
64 |
> |
private List<IRomConfigPair> GetRomsEX() |
65 |
|
{ |
66 |
|
List<IEmuConfig> configs = Config.ExternalConfigs; |
67 |
|
List<IRomConfigPair> roms = new List<IRomConfigPair>(); |
69 |
|
|
70 |
|
foreach (IEmuConfig config in configs) |
71 |
|
{ |
72 |
< |
var reconfig = FixExternalConfig(log,Config, config); |
72 |
> |
var reconfig = FixExternalConfig(Config, config); |
73 |
|
roms.Add(new RomConfigPair(reconfig.GameExe, reconfig)); |
74 |
|
} |
75 |
|
|
76 |
|
return roms; |
77 |
|
} |
78 |
< |
private IEmuConfig FixExternalConfig(logger log,IEmuConfig parent_config, IEmuConfig child_config) |
78 |
> |
private IEmuConfig FixExternalConfig(IEmuConfig parent_config, IEmuConfig child_config) |
79 |
|
{ |
80 |
|
string PlatformNameShort = child_config.PlatformNameShort.Contains("Unknown") ? parent_config.PlatformNameShort != "" ? parent_config.PlatformNameShort : "" : child_config.PlatformNameShort; |
81 |
|
string PlatformNameLong = child_config.PlatformNameLong.Contains("Unknown") ? parent_config.PlatformNameLong != "" ? parent_config.PlatformNameLong : "" : child_config.PlatformNameLong; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
< |
EmuXPortal.Api.EmuConfigLoader.EmuConfig c = new EmuConfigLoader.EmuConfig(log, |
90 |
< |
PlatformNameShort, PlatformNameLong, PlatformImage, |
91 |
< |
Extenstions, EmuPath, EmuOptions); |
89 |
> |
EmuXPortal.Api.EmuConfigLoader.EmuConfig c = new EmuConfigLoader.EmuConfig(PlatformNameShort, PlatformNameLong, PlatformImage,Extenstions, EmuPath, EmuOptions); |
90 |
|
c.EmuRomPath = string.IsNullOrEmpty(child_config.EmuRomPath) ? string.IsNullOrEmpty(parent_config.EmuRomPath) ? "" : parent_config.EmuRomPath : child_config.EmuRomPath; |
91 |
|
|
92 |
|
|
98 |
|
c.GameImage = child_config.GameImage; |
99 |
|
return c; |
100 |
|
} |
101 |
< |
private List<IRomConfig> GenerateRomConfig(logger log, List<IRomConfigPair> roms, IEmuConfig config) |
101 |
> |
private List<IRomConfig> GenerateRomConfig(List<IRomConfigPair> roms, IEmuConfig config) |
102 |
|
{ |
103 |
|
List<IRomConfig> romconfigs = new List<IRomConfig>(); |
104 |
< |
log.WriteLine("Generating Rom Configs"); |
105 |
< |
foreach (IRomConfigPair rom in roms) { romconfigs.Add(RomLoader.Load(log, rom.RomFile, rom.RomConfig)); } |
104 |
> |
gLog.Debug.WriteLine("Generating Rom Configs"); |
105 |
> |
foreach (IRomConfigPair rom in roms) { romconfigs.Add(RomLoader.Load(rom.RomFile, rom.RomConfig)); } |
106 |
|
return romconfigs; |
107 |
|
} |
108 |
|
|