/[EmuXPortal]/branches/mono/EmuXPortal/Api/RomConfig.cs
ViewVC logotype

Contents of /branches/mono/EmuXPortal/Api/RomConfig.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 283 - (show annotations) (download)
Wed Aug 17 01:24:40 2016 UTC (3 years, 10 months ago) by william
File size: 5428 byte(s)
update to latest version -- fixe some issues with non-emulator based games (PC)
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Drawing;
6 using System.IO;
7 using Enterprise.Logging;
8
9 namespace EmuXPortal.Api
10 {
11 public interface IRomConfig : IDisposable, IComparable<IRomConfig>
12 {
13 string RomFile { get; }
14 string RomTitle { get; }
15 Image RomImage { get; }
16 IEmuConfig Config { get; }
17 void ReleaseRomImageResource();
18
19 string ToString();
20 }
21
22 public static class RomLoader
23 {
24 private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration
25 public static IRomConfig Load(string rom_file, IEmuConfig EMUConfig)
26 {
27 IRomConfig config = null;
28 config = new RomConfig(rom_file, EMUConfig);
29 return config;
30 }
31 #region private class RomConfig : IRomConfig
32 private class RomConfig : IRomConfig, IDisposable
33 {
34 public RomConfig(string rom_file, IEmuConfig EMUConfig)
35 {
36 FileInfo fi = new FileInfo(rom_file);
37 this.RomFile =fi.FullName;
38 this.RomTitle = EMUConfig.GameTitle == "" ? fi.Name : EMUConfig.GameTitle;
39 string rom_img = "";
40 // load image
41 try
42 {
43 // DefaultGameImage
44 string raw_image_path = string.Format("{0}.jpg", fi.Extension != "" ? fi.FullName.Replace(fi.Extension, "") : fi.FullName);
45 if (File.Exists(raw_image_path)) { rom_img = string.Format(raw_image_path); }
46 }
47 catch (Exception ex)
48 {
49 gLog.Error.WriteLine("Error Loading an Image file for: {0}", fi.FullName);
50 gLog.Verbose.Error.WriteLine(ex.ToString());
51 }
52 try
53 {
54 if (rom_img != string.Empty)
55 {
56 try
57 {
58 this.RomImage = Image.FromFile(rom_img);
59 }
60 catch (Exception ex)
61 {
62 throw ex;
63 }
64 }
65 else
66 {
67 this.RomImage = null;
68 }
69 }
70 catch (Exception ex)
71 {
72 gLog.Error.WriteLine("Error loading rom image: {1}", (rom_img == "") ? "DefaultGameImage" : rom_img);
73 gLog.Verbose.Error.WriteLine(ex.ToString());
74 this.RomImage = null;
75 }
76
77
78 if (EMUConfig.GameImage != string.Empty)
79 {
80 FileInfo fi_gameimage = new FileInfo(EMUConfig.GameImage);
81 if (fi_gameimage.Exists) { this.RomImage = Image.FromFile(fi_gameimage.FullName); }
82 else
83 {
84 FileInfo t = new FileInfo(EMUConfig.ConfigPath);
85 string path = t.FullName.Replace(t.Name, "").Replace(t.Extension, "");
86 string image_path = string.Format(@"{0}{1}", path, fi_gameimage.Name);
87 FileInfo x = new FileInfo(image_path);
88 if (x.Exists) { this.RomImage = Image.FromFile(x.FullName); }
89 else
90 {
91 if (EMUConfig.GameExe != string.Empty)
92 {
93 FileInfo fi_gamexe = new FileInfo(EMUConfig.GameExe);
94 path = fi_gamexe.FullName.Replace(fi_gamexe.Name, "").Replace(fi_gamexe.Extension, "");
95 image_path = string.Format(@"{0}{1}", path, fi_gameimage.Name);
96 x = new FileInfo(image_path);
97 if (x.Exists) { this.RomImage = Image.FromFile(x.FullName); }
98 }
99 }
100 }
101 }
102
103
104 //string config_dir = fi.Directory.Parent.FullName;
105 //Config = EmuConfigLoader.Load(config_dir);
106 Config = EMUConfig;
107 }
108 #region IRomConfig Members
109 public string RomFile { get; private set; }
110 public string RomTitle { get; private set; }
111 public Image RomImage { get; private set; }
112 public IEmuConfig Config { get; private set; }
113 public void ReleaseRomImageResource()
114 {
115 if (this.RomImage != null)
116 this.RomImage.Dispose();
117 }
118
119 public override string ToString()
120 {
121 return string.Format("{2} - {0}{3}{1}", "{", "}", Config.PlatformNameShort, RomFile);
122 }
123 #endregion
124
125 public void Dispose()
126 {
127 if (this.RomImage != null)
128 this.RomImage.Dispose();
129 }
130
131 public int CompareTo(IRomConfig other)
132 {
133 return this.RomFile.CompareTo(other.RomFile);
134 }
135 }
136 #endregion
137 }
138
139
140 }

  ViewVC Help
Powered by ViewVC 1.1.22