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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/EmuXPortal/Api/RomConfig.cs	2012/08/22 02:12:46	104
+++ trunk/EmuXPortal/Api/RomConfig.cs	2012/08/22 02:36:47	105
@@ -4,10 +4,11 @@
 using System.Text;
 using System.Drawing;
 using System.IO;
+using EmuXPortal.Logging;
 
 namespace EmuXPortal.Api
 {
-    public interface IRomConfig
+    public interface IRomConfig : IDisposable
     {
         string RomFile { get; }
         string RomTitle { get; }
@@ -25,7 +26,7 @@
             return config;
         }
         #region private class RomConfig : IRomConfig
-        private class RomConfig : IRomConfig
+        private class RomConfig : IRomConfig, IDisposable
         {
             public RomConfig(string rom_file, IEmuConfig EMUConfig)
             {
@@ -35,7 +36,15 @@
                 string rom_img = "";
                 // load image
                 if (File.Exists(string.Format("{0}.jpg", fi.FullName.Replace(fi.Extension, "")))) { rom_img = string.Format("{0}.jpg", fi.FullName.Replace(fi.Extension, "")); }
-                this.RomImage = (rom_img == "") ? Properties.Resources.DefaultGameImage : Image.FromFile(rom_img);
+                try
+                {
+                    this.RomImage = (rom_img == "") ? Properties.Resources.DefaultGameImage : Image.FromFile(rom_img);
+                }
+                catch (Exception ex)
+                {
+                    logger.WriteLine("Error loading rom image: {1}{0}Error:{0}{2}", System.Environment.NewLine, (rom_img == "") ? "DefaultGameImage" : rom_img, ex.ToString());
+                    this.RomImage = Properties.Resources.DefaultGameImage;
+                }
 
 
                 if (EMUConfig.GameImage != string.Empty)
@@ -74,6 +83,12 @@
             public Image RomImage { get; private set; }
             public IEmuConfig Config { get; private set; }
             #endregion
+
+            public void Dispose()
+            {
+                if (this.RomImage != null)
+                    this.RomImage.Dispose();
+            }
         }
         #endregion
     }

 

  ViewVC Help
Powered by ViewVC 1.1.22