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

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

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

--- branches/mono/EmuXPortal.Api/Api/RomCache.cs	2019/05/06 02:26:16	395
+++ branches/mono/EmuXPortal.Api/Api/RomCache.cs	2019/06/23 23:32:26	396
@@ -6,6 +6,7 @@
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Windows.Forms;
+using System.Linq;
 
 namespace EmuXPortal.Api
 {
@@ -15,8 +16,8 @@
 		IEmuPlatform GetCachedPlatform(string platform_path);
 		IEmuConfig GetCachedPlatformAsEmuConfig(string platform_path);
 
-		List<IEmuPlatform> GetCachedPlatforms();
-		List<IEmuConfig> GetCachedPlatformsAsEmuConfigs();
+		HashSet<IEmuPlatform> GetCachedPlatforms();
+		HashSet<IEmuConfig> GetCachedPlatformsAsEmuConfigs();
 
 		IRomConfig GetCachedRom(string platform_path, string rom_file);
 
@@ -55,7 +56,7 @@
 			if (bGenerateAllCache) {
 				BuildCache (abort_event);
 			} else {
-				m_CachedPlatforms = new List<IEmuPlatform> ();
+				m_CachedPlatforms = new HashSet<IEmuPlatform> ();
 				var cached_platform_paths = RomCache.GetCachedPlatformPaths ();
 			}
 			if (!isPlatformPathCached(platform_path)) {
@@ -71,7 +72,7 @@
 		}
 		private void BuildCache (string cache_path, AbortEvent abort_event)
 		{
-			m_CachedPlatforms = new List<IEmuPlatform> ();
+			m_CachedPlatforms = new HashSet<IEmuPlatform> ();
 			var cached_platform_paths = RomCache.GetCachedPlatformPaths (cache_path);
 
 			if (cached_platform_paths.Count == 0) {
@@ -108,13 +109,13 @@
 			}
 			return cached;
 		}
-		private  List<IEmuPlatform> m_CachedPlatforms;
-		private List<IEmuPlatform> CachedPlatforms{get { return m_CachedPlatforms;} }
+		private  HashSet<IEmuPlatform> m_CachedPlatforms;
+		private HashSet<IEmuPlatform> CachedPlatforms{get { return m_CachedPlatforms;} }
 
-		public List<IEmuPlatform> GetCachedPlatforms() { return this.CachedPlatforms; }
-		public List<IEmuConfig> GetCachedPlatformsAsEmuConfigs ()
+		public HashSet<IEmuPlatform> GetCachedPlatforms() { return this.CachedPlatforms; }
+		public HashSet<IEmuConfig> GetCachedPlatformsAsEmuConfigs ()
 		{
-			List<IEmuConfig> configs = new List<IEmuConfig> ();
+			HashSet<IEmuConfig> configs = new HashSet<IEmuConfig> ();
 			foreach (var platform in this.CachedPlatforms) {
 				EmuXPortal.Api.EmuConfigLoader.EmuConfig config = new EmuConfigLoader.EmuConfig(platform);
 				configs.Add(config);
@@ -185,13 +186,13 @@
 	}
 	internal class RomCache : IRomCache
 	{
-		internal static List<string> GetCachedPlatformPaths ()
+		internal static HashSet<string> GetCachedPlatformPaths ()
 		{
 			return GetCachedPlatformPaths("");
 		}
-		internal static List<string> GetCachedPlatformPaths (string m_cache_path)
+		internal static HashSet<string> GetCachedPlatformPaths (string m_cache_path)
 		{
-			List<string> cached_platform_paths = new List<string> ();
+			HashSet<string> cached_platform_paths = new HashSet<string> ();
 			Dictionary<string, string> _map = new Dictionary<string, string> ();
 			// read cache map
 			string cache_map_file = RomCache.GetCacheMapFile (m_cache_path);
@@ -200,7 +201,7 @@
 			if (f_map.Exists) {
 				serializer.DeSerialize (f_map.FullName, out _map);
 			} else {
-				return new List<string>();
+				return new HashSet<string>();
 			}
 			foreach (var t in _map) {
 				var key = t.Key;
@@ -208,7 +209,7 @@
 				//gLog.Debug.WriteLine("[key:{0}] [value:{1}]", key, value);
 				cached_platform_paths.Add(t.Value);
 			}
-			cached_platform_paths.Sort();
+			cached_platform_paths = new HashSet<string> (cached_platform_paths.OrderBy (s => s));
 			return cached_platform_paths;
 		}
 
@@ -371,7 +372,7 @@
 			gLog.Info.WriteLine ("Purging missing rom entries");
 			Stopwatch st = new Stopwatch();
 			st.Start();
-			var roms = new List<IEmuRom>(this.m_cache.Roms);
+			var roms = new HashSet<IEmuRom>(this.m_cache.Roms);
 			foreach (var t in this.m_cache.Roms) {
 				string romfile = t.RomFile;
 				if (!File.Exists (romfile)) {
@@ -390,7 +391,7 @@
 			// grab only the updated config
 			var updated_cache = new EmuPlatform (abort_event, true, this.m_cache.PlatformPath);
 			// store the current rom list
-			var roms = new List<IEmuRom>(this.m_cache.Roms);
+			var roms = new HashSet<IEmuRom>(this.m_cache.Roms);
 			// overwrite the cache with the updated cconfig
 			m_cache = updated_cache;
 			// restore the original roms
@@ -398,8 +399,8 @@
 		}
 		private bool UpdateRomList ()
 		{
-			List<IEmuRom> roms = new List<IEmuRom> ();
-			List<string> images = EmuRom.GetImagesInPath(m_cache.EmulatorRomPath);
+			HashSet<IEmuRom> roms = new HashSet<IEmuRom> ();
+			HashSet<string> images = EmuRom.GetImagesInPath(m_cache.EmulatorRomPath);
 			bool result = EmuRom.EnumerateRoms (m_cache, images, m_cache.Roms, this.abort_event, m_cache.PlatformPath, m_cache.Extenstions, out roms);
 			images.Clear();
 			images=null;

 

  ViewVC Help
Powered by ViewVC 1.1.22