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

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

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

--- trunk/EmuXPortal/Api/RomFavorite.cs	2014/08/04 05:06:37	171
+++ trunk/EmuXPortal/Api/RomFavorite.cs	2014/08/04 05:36:08	172
@@ -19,10 +19,34 @@
         const string ROM_FILE = "rom";
         #endregion
         private static List<IRomConfig> lst_favorites = new List<IRomConfig>();
+
+        private class FavoriesComparor : IEqualityComparer<IRomConfig>
+        {
+            public bool Equals(IRomConfig x, IRomConfig y) { return x.RomFile.Equals(y.RomFile); }
+            public int GetHashCode(IRomConfig obj) { return obj.RomFile.GetHashCode(); }
+        }
         #region static members
+
+        public static List<IRomConfig> GetFavorites()
+        {
+            List<IRomConfig> favorites = new List<IRomConfig>();
+            foreach (var rom in lst_favorites)
+            {
+                favorites.Add(rom);
+            }
+            return favorites;
+        }
+
         public static bool IsFavorite(logger log,IRomConfig rom)
         {
-            return lst_favorites.Contains(rom);
+            foreach (var c_rom in lst_favorites)
+            {
+                if (c_rom.RomFile == rom.RomFile)
+                {
+                    return true;
+                }
+            }
+            return false;
         }
         public static bool AddFavorite(logger log, IRomConfig rom)
         {
@@ -47,7 +71,7 @@
             return true;
         }
         public static bool UpdateFavorites(logger log)
-        {
+        {            
             bool ret = SaveFavorites(log);
             if (!ret)
             {
@@ -101,8 +125,9 @@
                             }                            
                         }
                     }
-                }
+                }                
                 log.WriteLine("Loaded Favorites: {0}", ini);
+                SaveFavorites(log);
                 return true;
 
             }
@@ -116,6 +141,8 @@
         }
         internal static bool SaveFavorites(logger log)
         {
+            // clean-up any duplicates
+            lst_favorites = lst_favorites.Distinct(new FavoriesComparor()).ToList();
             string ini = Config.ConfigLoader.FAVORITES_FILE_INI;
             try
             {

 

  ViewVC Help
Powered by ViewVC 1.1.22