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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 105 - (hide 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 william 17 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.Drawing;
6     using System.IO;
7 william 105 using EmuXPortal.Logging;
8 william 17
9     namespace EmuXPortal.Api
10     {
11 william 105 public interface IRomConfig : IDisposable
12 william 17 {
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 william 29 public static IRomConfig Load(string rom_file, IEmuConfig EMUConfig)
23 william 17 {
24     IRomConfig config = null;
25 william 29 config = new RomConfig(rom_file, EMUConfig);
26 william 17 return config;
27     }
28     #region private class RomConfig : IRomConfig
29 william 105 private class RomConfig : IRomConfig, IDisposable
30 william 17 {
31 william 29 public RomConfig(string rom_file, IEmuConfig EMUConfig)
32 william 17 {
33     FileInfo fi = new FileInfo(rom_file);
34     this.RomFile =fi.FullName;
35 william 85 this.RomTitle = EMUConfig.GameTitle == "" ? fi.Name : EMUConfig.GameTitle;
36 william 17 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 william 105 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 william 85
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 william 29 //string config_dir = fi.Directory.Parent.FullName;
77     //Config = EmuConfigLoader.Load(config_dir);
78     Config = EMUConfig;
79 william 17 }
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 william 105
87     public void Dispose()
88     {
89     if (this.RomImage != null)
90     this.RomImage.Dispose();
91     }
92 william 17 }
93     #endregion
94     }
95    
96    
97     }

  ViewVC Help
Powered by ViewVC 1.1.22