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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 105 - (show annotations) (download)
Wed Aug 22 02:36:47 2012 UTC (8 years, 2 months ago) by william
File size: 4088 byte(s)
**** memory optimization (bulk WIP)

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 this.RomImage = (rom_img == "") ? Properties.Resources.DefaultGameImage : Image.FromFile(rom_img);
42 }
43 catch (Exception ex)
44 {
45 logger.WriteLine("Error loading rom image: {1}{0}Error:{0}{2}", System.Environment.NewLine, (rom_img == "") ? "DefaultGameImage" : rom_img, ex.ToString());
46 this.RomImage = Properties.Resources.DefaultGameImage;
47 }
48
49
50 if (EMUConfig.GameImage != string.Empty)
51 {
52 FileInfo fi_gameimage = new FileInfo(EMUConfig.GameImage);
53 if (fi_gameimage.Exists) { this.RomImage = Image.FromFile(fi_gameimage.FullName); }
54 else
55 {
56 FileInfo t = new FileInfo(EMUConfig.ConfigPath);
57 string path = t.FullName.Replace(t.Name, "").Replace(t.Extension, "");
58 string image_path = string.Format(@"{0}{1}", path, fi_gameimage.Name);
59 FileInfo x = new FileInfo(image_path);
60 if (x.Exists) { this.RomImage = Image.FromFile(x.FullName); }
61 else
62 {
63 if (EMUConfig.GameExe != string.Empty)
64 {
65 FileInfo fi_gamexe = new FileInfo(EMUConfig.GameExe);
66 path = fi_gamexe.FullName.Replace(fi_gamexe.Name, "").Replace(fi_gamexe.Extension, "");
67 image_path = string.Format(@"{0}{1}", path, fi_gameimage.Name);
68 x = new FileInfo(image_path);
69 if (x.Exists) { this.RomImage = Image.FromFile(x.FullName); }
70 }
71 }
72 }
73 }
74
75
76 //string config_dir = fi.Directory.Parent.FullName;
77 //Config = EmuConfigLoader.Load(config_dir);
78 Config = EMUConfig;
79 }
80 #region IRomConfig Members
81 public string RomFile { get; private set; }
82 public string RomTitle { get; private set; }
83 public Image RomImage { get; private set; }
84 public IEmuConfig Config { get; private set; }
85 #endregion
86
87 public void Dispose()
88 {
89 if (this.RomImage != null)
90 this.RomImage.Dispose();
91 }
92 }
93 #endregion
94 }
95
96
97 }

  ViewVC Help
Powered by ViewVC 1.1.22