@@ -318,14 +318,15 @@ public int GetValue(string section, string key, int defaultValue)
318318 public bool IsGameFollowed ( string gameName )
319319 => SettingsIni . GetBooleanValue ( "Channels" , gameName , false ) ;
320320
321- public bool ToggleFavoriteMap ( string mapName , string gameModeName , bool isFavorite )
321+ public bool ToggleFavoriteMap ( string mapSHA1 , string gameModeName , bool isFavorite )
322322 {
323- if ( string . IsNullOrEmpty ( mapName ) )
323+ if ( string . IsNullOrEmpty ( mapSHA1 ) )
324324 return isFavorite ;
325325
326- string favoriteMapKey = FavoriteMapKey ( mapName , gameModeName ) ;
327- isFavorite = IsFavoriteMap ( mapName , gameModeName ) ;
328- if ( isFavorite )
326+ string favoriteMapKey = FavoriteMapKey ( mapSHA1 , gameModeName ) ;
327+
328+ bool isCurrentlyFavorite = FavoriteMaps . Contains ( favoriteMapKey ) ;
329+ if ( isCurrentlyFavorite )
329330 FavoriteMaps . Remove ( favoriteMapKey ) ;
330331 else
331332 FavoriteMaps . Add ( favoriteMapKey ) ;
@@ -334,7 +335,7 @@ public bool ToggleFavoriteMap(string mapName, string gameModeName, bool isFavori
334335
335336 WriteFavoriteMaps ( ) ;
336337
337- return ! isFavorite ;
338+ return ! isCurrentlyFavorite ;
338339 }
339340
340341 private void LoadFavoriteMaps ( IniFile iniFile )
@@ -349,7 +350,7 @@ private void LoadFavoriteMaps(IniFile iniFile)
349350 WriteFavoriteMaps ( ) ;
350351 }
351352
352- private void WriteFavoriteMaps ( )
353+ public void WriteFavoriteMaps ( )
353354 {
354355 var favoriteMapsSection = SettingsIni . GetOrAddSection ( FAVORITE_MAPS ) ;
355356 favoriteMapsSection . RemoveAllKeys ( ) ;
@@ -361,12 +362,41 @@ private void WriteFavoriteMaps()
361362
362363 /// <summary>
363364 /// Checks if a specified map name and game mode name belongs to the favorite map list.
365+ /// Name-based favorites are migrated to SHA1.
364366 /// </summary>
365- /// <param name="nameName">The name of the map.</param>
366- /// <param name="gameModeName">The name of the game mode</param>
367- public bool IsFavoriteMap ( string nameName , string gameModeName ) => FavoriteMaps . Contains ( FavoriteMapKey ( nameName , gameModeName ) ) ;
367+ /// <param name="mapSHA1">The SHA1 hash of the map.</param>
368+ /// <param name="mapName">The name of the map.</param>
369+ /// <param name="gameModeName">The name of the game mode.</param>
370+ public bool IsFavoriteMap ( string mapSHA1 , string mapName , string gameModeName )
371+ {
372+ // SHA1-based lookup first
373+ if ( ! string . IsNullOrEmpty ( mapSHA1 ) && FavoriteMaps . Contains ( FavoriteMapKey ( mapSHA1 , gameModeName ) ) )
374+ return true ;
375+
376+ // Fallback to name-based
377+ string nameKey = FavoriteMapKey ( mapName , gameModeName ) ;
378+ if ( FavoriteMaps . Contains ( nameKey ) )
379+ {
380+ // Migrate to SHA1
381+ if ( ! string . IsNullOrEmpty ( mapSHA1 ) )
382+ {
383+ string sha1Key = FavoriteMapKey ( mapSHA1 , gameModeName ) ;
384+ if ( ! FavoriteMaps . Contains ( sha1Key ) )
385+ {
386+ FavoriteMaps . Add ( sha1Key ) ;
387+ WriteFavoriteMaps ( ) ;
388+ }
389+ // Note: We don't remove the name-based entry here to allow other maps
390+ // with the same name to also migrate. The name-based entry will be
391+ // cleaned up when all maps with that name have been processed.
392+ }
393+ return true ;
394+ }
395+
396+ return false ;
397+ }
368398
369- private string FavoriteMapKey ( string nameName , string gameModeName ) => $ "{ nameName } :{ gameModeName } ";
399+ private string FavoriteMapKey ( string identifier , string gameModeName ) => $ "{ identifier } :{ gameModeName } ";
370400
371401 public void ReloadSettings ( ) => SettingsIni . Reload ( ) ;
372402
0 commit comments