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

Diff of /branches/mono/EmuXPortal.Api/Api/IEmuRom.cs

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

--- branches/mono/EmuXPortal.Api/Api/IEmuRom.cs	2019/05/06 02:26:16	395
+++ branches/mono/EmuXPortal.Api/Api/IEmuRom.cs	2019/06/23 23:32:26	396
@@ -27,13 +27,13 @@
 		private static readonly string[] VALID_IMAGE_EXTENSIONS = new string[] { ".jpg", ".png", ".gif", ".bmp", ".tiff" };
 		//private static readonly HashSet<string> VALID_IMAGE_EXTENSIONS = new HashSet<string>( new string[] { ".jpg"});
 
-		public static List<string> GetImagesInPath(string path) {	
-			List<string> images = new List<string>();
+		public static HashSet<string> GetImagesInPath(string path) {	
+			HashSet<string> images = new HashSet<string>();
 			Predicate<string> rom_predicate = new Predicate<string> (delegate(string t) {								
 				string ext = Path.GetExtension (t).ToLower ();
 				return VALID_IMAGE_EXTENSIONS.Contains (ext) && t.ToLower ().EndsWith (ext);
 			});
-			var files = new List<string> (Directory.GetFiles (path, "*.*", SearchOption.AllDirectories).Where (s => rom_predicate (s)));
+			var files = new HashSet<string> (Directory.GetFiles (path, "*.*", SearchOption.AllDirectories).Where (s => rom_predicate (s)));
 
 			foreach (var file in files) {
 				if (File.Exists (file)) {
@@ -43,13 +43,13 @@
 			return images;
 		}
 
-		public static bool EnumerateRoms (IEmuPlatform platform_config,List<string> found_images, AbortEvent abort_event, string path, string extensions, out List<IEmuRom> roms) {
-			return EnumerateRoms(platform_config, found_images, new List<IEmuRom>(),abort_event,path,extensions,out roms);
+		public static bool EnumerateRoms (IEmuPlatform platform_config,HashSet<string> found_images, AbortEvent abort_event, string path, string extensions, out HashSet<IEmuRom> roms) {
+			return EnumerateRoms(platform_config, found_images, new HashSet<IEmuRom>(),abort_event,path,extensions,out roms);
 		}
-		public static bool EnumerateRoms (IEmuPlatform platform_config, List<string> found_images, List<IEmuRom> existing_roms, AbortEvent abort_event, string path, string extensions, out List<IEmuRom> roms)
+		public static bool EnumerateRoms (IEmuPlatform platform_config, HashSet<string> found_images, HashSet<IEmuRom> existing_roms, AbortEvent abort_event, string path, string extensions, out HashSet<IEmuRom> roms)
 		{
 			bool result = true;
-			roms = new List<IEmuRom> ();
+			roms = new HashSet<IEmuRom> ();
 
 			Dictionary<string,EmuRom> dict = new Dictionary<string, EmuRom> ();
 			foreach (var t in existing_roms) {
@@ -60,13 +60,13 @@
 
 			Predicate<string> rom_predicate = new Predicate<string> (delegate(string t) {
 				string search_exts = extensions.Replace ("*", "");
-				List<string> exts = new List<string> (search_exts.Split (new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));             
+				HashSet<string> exts = new HashSet<string> (search_exts.Split (new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));             
 				string ext = Path.GetExtension (t).ToLower ();
 				return exts.Contains (ext) && t.ToLower ().EndsWith (ext);
 			});
 			var files = from f in (extensions == "*.*")
-				? new List<string> (Directory.GetFiles (path, "*.*", SearchOption.AllDirectories))
-				: new List<string> (Directory.GetFiles (path, "*.*", SearchOption.AllDirectories).Where (s => rom_predicate (s)))
+				? new HashSet<string> (Directory.GetFiles (path, "*.*", SearchOption.AllDirectories))
+				: new HashSet<string> (Directory.GetFiles (path, "*.*", SearchOption.AllDirectories).Where (s => rom_predicate (s)))
 			            select f;
 
 			HashSet<string> hash_set = new HashSet<string> ();
@@ -113,7 +113,7 @@
 			foreach (var t in dict) {
 				roms.Add(t.Value);
 			}
-			roms.Sort();
+			roms = new HashSet<IEmuRom> (roms.OrderBy (s => s.RomFile.ToLower ()));
 			return result;
 		}
 		public EmuRom (IEmuPlatform platform_config)
@@ -128,14 +128,14 @@
 			this.RomImage = "";
 		}
 
-		public void FindRomImage (List<string> found_images)
+		public void FindRomImage (HashSet<string> found_images)
 		{
 
 			this.RomImage = ""; // reset the rom image (it will be updated later if found)
 			FileInfo fi = new FileInfo (this.RomFile);
 			string filename = fi.FullName.Replace (fi.Extension, "");
 
-			List<string> rom_images = new List<string> ();
+			HashSet<string> rom_images = new HashSet<string> ();
 			foreach (var image in found_images) {
 				FileInfo fi2 = new FileInfo (image);
 				string image_filename = fi2.FullName.Replace (fi2.Extension, "");
@@ -149,7 +149,7 @@
 				if (rom_images.Count > 1) {
 					gLog.Warn.WriteLine("Using first image found for rom: {0}", this.RomFile);
 				}
-				this.RomImage = rom_images[0];
+				this.RomImage = rom_images.ElementAt(0);
 			}
 
 			fi = null;

 

  ViewVC Help
Powered by ViewVC 1.1.22