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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 106 - (show annotations) (download)
Wed Aug 22 02:47:38 2012 UTC (8 years, 2 months ago) by william
File size: 4508 byte(s)

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 EmuXPortal.Logging;
8
9 namespace EmuXPortal.Api
10 {
11 public interface IRomConfig : IDisposable
12 {
13 string RomFile { get; }
14 string RomTitle { get; }
15 Image RomImage { get; }
16 IEmuConfig Config { get; }
17 }
18
19 public static class RomLoader
20 {
21 private const string EMU_CONFIG = "emu.config"; // if this file signifies the emulator configuration
22 public static IRomConfig Load(string rom_file, IEmuConfig EMUConfig)
23 {
24 IRomConfig config = null;
25 config = new RomConfig(rom_file, EMUConfig);
26 return config;
27 }
28 #region private class RomConfig : IRomConfig
29 private class RomConfig : IRomConfig, IDisposable
30 {
31 public RomConfig(string rom_file, IEmuConfig EMUConfig)
32 {
33 FileInfo fi = new FileInfo(rom_file);
34 this.RomFile =fi.FullName;
35 this.RomTitle = EMUConfig.GameTitle == "" ? fi.Name : EMUConfig.GameTitle;
36 string rom_img = "";
37 // load image
38 if (File.Exists(string.Format("{0}.jpg", fi.FullName.Replace(fi.Extension, "")))) { rom_img = string.Format("{0}.jpg", fi.FullName.Replace(fi.Extension, "")); }
39 try
40 {
41 if (rom_img != string.Empty)
42 {
43 try
44 {
45 this.RomImage = Image.FromFile(rom_img);
46 }
47 catch (Exception ex)
48 {
49 throw ex;
50 }
51 }
52 else
53 {
54 this.RomImage = Properties.Resources.DefaultGameImage;
55 }
56 }
57 catch (Exception ex)
58 {
59 logger.WriteLine("Error loading rom image: {1}{0}Error:{0}{2}", System.Environment.NewLine, (rom_img == "") ? "DefaultGameImage" : rom_img, ex.ToString());
60 this.RomImage = Properties.Resources.DefaultGameImage;
61 }
62
63
64 if (EMUConfig.GameImage != string.Empty)
65 {
66 FileInfo fi_gameimage = new FileInfo(EMUConfig.GameImage);
67 if (fi_gameimage.Exists) { this.RomImage = Image.FromFile(fi_gameimage.FullName); }
68 else
69 {
70 FileInfo t = new FileInfo(EMUConfig.ConfigPath);
71 string path = t.FullName.Replace(t.Name, "").Replace(t.Extension, "");
72 string image_path = string.Format(@"{0}{1}", path, fi_gameimage.Name);
73 FileInfo x = new FileInfo(image_path);
74 if (x.Exists) { this.RomImage = Image.FromFile(x.FullName); }
75 else
76 {
77 if (EMUConfig.GameExe != string.Empty)
78 {
79 FileInfo fi_gamexe = new FileInfo(EMUConfig.GameExe);
80 path = fi_gamexe.FullName.Replace(fi_gamexe.Name, "").Replace(fi_gamexe.Extension, "");
81 image_path = string.Format(@"{0}{1}", path, fi_gameimage.Name);
82 x = new FileInfo(image_path);
83 if (x.Exists) { this.RomImage = Image.FromFile(x.FullName); }
84 }
85 }
86 }
87 }
88
89
90 //string config_dir = fi.Directory.Parent.FullName;
91 //Config = EmuConfigLoader.Load(config_dir);
92 Config = EMUConfig;
93 }
94 #region IRomConfig Members
95 public string RomFile { get; private set; }
96 public string RomTitle { get; private set; }
97 public Image RomImage { get; private set; }
98 public IEmuConfig Config { get; private set; }
99 #endregion
100
101 public void Dispose()
102 {
103 if (this.RomImage != null)
104 this.RomImage.Dispose();
105 }
106 }
107 #endregion
108 }
109
110
111 }

  ViewVC Help
Powered by ViewVC 1.1.22