Browse Source

Fix:
- Better compatibility with SongLoader forks

Debug:
- Added some useful optional logging.

Stephen Damm 6 years ago
parent
commit
f5a89fa930

+ 3 - 1
SongBrowserPlugin/SongBrowserMasterViewController.cs

@@ -10,6 +10,7 @@ using System.Text;
 using HMUI;
 using System.Text.RegularExpressions;
 using System.IO;
+using System.Threading;
 
 namespace SongBrowserPlugin
 {
@@ -240,7 +241,7 @@ namespace SongBrowserPlugin
             }
             catch (Exception e)
             {
-                _log.Exception("Exception trying to sort by newest: {0}", e);
+                _log.Exception("Exception trying to update song list: {0}", e);
             }
         }
 
@@ -423,6 +424,7 @@ namespace SongBrowserPlugin
                 songTableView.ClearSelection();
                 _songListViewController.SelectSong(0);
                 _songSelectionMasterView.HandleSongListDidSelectSong(_songListViewController);
+                
 
                 RefreshUI();
                 RefreshAddFavoriteButton(songList[0]);

+ 23 - 4
SongBrowserPlugin/SongBrowserModel.cs

@@ -88,7 +88,7 @@ namespace SongBrowserPlugin
                     // Flip slashes, match SongLoaderPlugin
                     string slashed_dir = dir.Replace("\\", "/");
 
-                    _log.Debug("Fetching LastWriteTime for {0}", slashed_dir);
+                   //_log.Debug("Fetching LastWriteTime for {0}", slashed_dir);
                     _cachedLastWriteTimes[slashed_dir] = (File.GetLastWriteTimeUtc(dir) - Epoch).TotalMilliseconds;
                 }
 
@@ -121,8 +121,15 @@ namespace SongBrowserPlugin
         /// </summary>
         private void UpdateSongInfos()
         {
-            _customSongInfos = ReflectionUtil.InvokeMethod<SongLoaderPlugin.SongLoader>(SongLoaderPlugin.SongLoader.Instance, "RetrieveAllSongs", null) as List<SongLoaderPlugin.CustomSongInfo>;
-            _levelIdToCustomSongInfo = _customSongInfos.ToDictionary(x => x.GetIdentifier(), x => x);
+            _log.Debug("Attempting to fetch song infos from song loader plugin.");
+            _customSongInfos = SongLoaderPlugin.SongLoader.CustomSongInfos;
+            _customSongInfos.ForEach(x => _log.Debug(x.path));
+            _levelIdToCustomSongInfo = _customSongInfos.ToDictionary(x => x.levelId, x => x);
+
+            /*_customSongInfos.ForEach(x =>
+            {
+                _log.Debug("path={0}", x.levelId);
+            });*/
         }
         
         /// <summary>
@@ -149,7 +156,19 @@ namespace SongBrowserPlugin
                 ["Level3"] = 2,
                 ["Level8"] = 1
             };
-           
+
+            /*_originalSongs.ForEach(x =>
+            {
+                if (_levelIdToCustomSongInfo.ContainsKey(x.levelId))
+                {
+                    _log.Debug("_levelIdToCustomSongInfo.HasKey({0})",  x.levelId);
+                }
+                else
+                {
+                    _log.Debug("!_levelIdToCustomSongInfo.HasKey({0})", x.levelId);
+                }
+            });*/
+
             switch (_settings.sortMode)
             {
                 case SongSortMode.Favorites: