소스 검색

Only parse DuoVR score saber data once. Unlikely to change during a play
session enough to matter.

Stephen Damm 6 년 전
부모
커밋
6249c38655
2개의 변경된 파일37개의 추가작업 그리고 25개의 파일을 삭제
  1. 1 1
      SongBrowserPlugin/DataAccess/SongBrowserModel.cs
  2. 36 24
      SongBrowserPlugin/UI/ScoreSaberDatabaseDownloader.cs

+ 1 - 1
SongBrowserPlugin/DataAccess/SongBrowserModel.cs

@@ -327,7 +327,7 @@ namespace SongBrowserPlugin
         {
         {
             _log.Trace("UpdateScoreSaberDataMapping()");
             _log.Trace("UpdateScoreSaberDataMapping()");
 
 
-            ScoreSaberDataFile scoreSaberDataFile = ScoreSaberDatabaseDownloader.Instance.ScoreSaberDataFile;
+            ScoreSaberDataFile scoreSaberDataFile = ScoreSaberDatabaseDownloader.ScoreSaberDataFile;
 
 
             // bail
             // bail
             if (scoreSaberDataFile == null)
             if (scoreSaberDataFile == null)

+ 36 - 24
SongBrowserPlugin/UI/ScoreSaberDatabaseDownloader.cs

@@ -16,10 +16,12 @@ namespace SongBrowserPlugin.UI
 
 
         public static ScoreSaberDatabaseDownloader Instance;
         public static ScoreSaberDatabaseDownloader Instance;
 
 
-        public ScoreSaberDataFile ScoreSaberDataFile;
+        public static ScoreSaberDataFile ScoreSaberDataFile = null;        
 
 
         public Action onScoreSaberDataDownloaded;
         public Action onScoreSaberDataDownloaded;
 
 
+        private byte[] _buffer = new byte[4 * 1048576];
+
         /// <summary>
         /// <summary>
         /// Awake.
         /// Awake.
         /// </summary>
         /// </summary>
@@ -43,39 +45,49 @@ namespace SongBrowserPlugin.UI
             StartCoroutine(WaitForDownload());
             StartCoroutine(WaitForDownload());
         }
         }
 
 
+        private void DownloadScoreSaberData()
+        {
+
+        }
+
         /// <summary>
         /// <summary>
         /// Wait for the tsv file from DuoVR to download.
         /// Wait for the tsv file from DuoVR to download.
         /// </summary>
         /// </summary>
         /// <returns></returns>
         /// <returns></returns>
         private IEnumerator WaitForDownload()
         private IEnumerator WaitForDownload()
         {
         {
-            SongBrowserApplication.MainProgressBar.ShowMessage("Downloading DuoVR ScoreSaber data...");
-
-            _log.Info("Attempting to download: {0}", ScoreSaberDatabaseDownloader.PP_DATA_URL);
-            using (UnityWebRequest www = UnityWebRequest.Get(ScoreSaberDatabaseDownloader.PP_DATA_URL))
+            if (ScoreSaberDatabaseDownloader.ScoreSaberDataFile != null)
+            {
+                _log.Info("Using cached copy of DuoVR ScoreSaberData...");
+            }
+            else
             {
             {
-                // Use 4MB cache, large enough for this file to grow for awhile.
-                www.SetCacheable(new CacheableDownloadHandlerScoreSaberData(www, new byte[4 * 1048576]));
-                yield return www.SendWebRequest();
+                SongBrowserApplication.MainProgressBar.ShowMessage("Downloading DuoVR ScoreSaber data...");
 
 
-                _log.Debug("Returned from web request!...");
-                
-                try
-                {
-                    this.ScoreSaberDataFile = (www.downloadHandler as CacheableDownloadHandlerScoreSaberData).ScoreSaberDataFile;
-                    _log.Info("Success downloading DuoVR ScoreSaber data!");
-                    SongBrowserApplication.MainProgressBar.ShowMessage("Success downloading DuoVR ScoreSaber data...");
-                    onScoreSaberDataDownloaded?.Invoke();
-                }
-                catch (System.InvalidOperationException)
+                _log.Info("Attempting to download: {0}", ScoreSaberDatabaseDownloader.PP_DATA_URL);
+                using (UnityWebRequest www = UnityWebRequest.Get(ScoreSaberDatabaseDownloader.PP_DATA_URL))
                 {
                 {
-                    _log.Error("Failed to download DuoVR ScoreSaber data file...");                    
+                    // Use 4MB cache, large enough for this file to grow for awhile.
+                    www.SetCacheable(new CacheableDownloadHandlerScoreSaberData(www, _buffer));
+                    yield return www.SendWebRequest();
+
+                    _log.Debug("Returned from web request!...");
+
+                    try
+                    {
+                        ScoreSaberDatabaseDownloader.ScoreSaberDataFile = (www.downloadHandler as CacheableDownloadHandlerScoreSaberData).ScoreSaberDataFile;
+                        _log.Info("Success downloading DuoVR ScoreSaber data!");
+                    }
+                    catch (System.InvalidOperationException)
+                    {
+                        _log.Error("Failed to download DuoVR ScoreSaber data file...");
+                    }
+                    catch (Exception e)
+                    {
+                        _log.Exception("Exception trying to download DuoVR ScoreSaber data file...", e);
+                    }
                 }
                 }
-                catch (Exception e)
-                {
-                    _log.Exception("Exception trying to download DuoVR ScoreSaber data file...", e);
-                }                
-            }            
+            }
         }
         }
     }
     }
 }
 }