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

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

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

--- branches/mono/EmuXPortal.Api/Api/RomFavorite.cs	2019/05/06 02:26:16	395
+++ branches/mono/EmuXPortal.Api/Api/RomFavorite.cs	2019/06/23 23:32:26	396
@@ -60,7 +60,7 @@
 
 
 
-		private static List<IRomFavorite> lst_favorites = new List<IRomFavorite> ();
+		private static HashSet<IRomFavorite> lst_favorites = new HashSet<IRomFavorite> ();
 
 		private class FavoriesComparor : IEqualityComparer<IRomFavorite> {
 			public bool Equals (IRomFavorite x, IRomFavorite y) { return x.RomConfig.RomFile.Equals (y.RomConfig.RomFile); }
@@ -68,9 +68,9 @@
 		}
 		#region static members
 
-		internal static List<IRomConfig> GetRoms (IPlatformCache cache)
+		internal static HashSet<IRomConfig> GetRoms (IPlatformCache cache)
 		{
-			List<IRomConfig> roms = new List<IRomConfig> ();
+			HashSet<IRomConfig> roms = new HashSet<IRomConfig> ();
 			//lst_favorites.ForEach(s => roms.Add(s.RomConfig));
 
 			foreach (var rom in lst_favorites) {
@@ -100,9 +100,9 @@
 			return string.Format (favorite.ToString ());
 		}
 		public static string GetRomTitleFromConfig (IRomConfig config) { return GetRomTitleFromFavorite (GetFavoriteInfoFromRom (config)); }
-		public static List<IRomFavorite> GetFavorites ()
+		public static HashSet<IRomFavorite> GetFavorites ()
 		{
-			List<IRomFavorite> favorites = new List<IRomFavorite> ();
+			HashSet<IRomFavorite> favorites = new HashSet<IRomFavorite> ();
 			foreach (var rom in lst_favorites) {
 				favorites.Add (rom);
 			}
@@ -134,15 +134,16 @@
 				gLog.Error.WriteLine ("Rom is not favorited: [{0}]", rom.RomTitle);
 				return false;
 			}
-			List<int> indices = new List<int> ();
+			HashSet<int> indices = new HashSet<int> ();
 			for (int i = 0; i < lst_favorites.Count; i++) {
-				var k = lst_favorites [i];
+				var k = lst_favorites.ElementAt(i);
 				if (k.RomConfig.RomFile == rom.RomFile) {
-					indices.Add (lst_favorites.IndexOf (k));
+					indices.Add (i);
 				}
 			}
 			foreach (var index in indices) {
-				lst_favorites.RemoveAt (index);
+				var i = lst_favorites.ElementAt (index);
+				lst_favorites.Remove(i);
 			}
 
 			gLog.Info.WriteLine ("Removed rom from favorites: [{0}]", rom.RomTitle);
@@ -245,8 +246,7 @@
 						gLog.Warn.WriteLine ("Unexpected element '{0}' in favorites", favorite.Name);
 					}
 				}
-				lst_favorites = lst_favorites.Distinct (new FavoriesComparor ()).ToList ();
-				lst_favorites = lst_favorites.OrderBy (s => s.RomConfig.RomTitle).ToList ();
+				lst_favorites = new HashSet<IRomFavorite> (lst_favorites.Distinct (new FavoriesComparor ()).OrderBy (s => s.RomConfig.RomTitle));				
 				gLog.Info.WriteLine ("Loaded Favorites: {0}", ini);
 				SaveFavorites ();
 				return true;
@@ -260,8 +260,7 @@
 		internal static bool SaveFavorites ()
 		{
 			// clean-up any duplicates
-			List<IRomFavorite> lst_f = lst_favorites.Distinct (new FavoriesComparor ()).ToList ();
-			lst_f = lst_f.OrderBy (s => s.DateAdded).ToList ();
+			HashSet<IRomFavorite> lst_f = new HashSet<IRomFavorite> (lst_favorites.Distinct (new FavoriesComparor ()).OrderBy (s => s.DateAdded));
 			string ini = Config.ConfigLoader.FAVORITES_FILE_INI;
 			try {
 				gLog.Debug.WriteLine ("Saving Favorites: {0}", ini);

 

  ViewVC Help
Powered by ViewVC 1.1.22