Пример #1
0
        /// <summary>1
        /// Call to reload song list after songs were added to songs or downloads directories.
        /// Should be called while the user is in the main menu.
        /// </summary>
        /// <param name="fullReload">Call with true to reload the entire song list. Otherwise only new
        ///     songs will be loaded (unfortunately unable to detect modified songs)</param>
        public static void ReloadSongList(bool fullReload = true)
        {
            SongDownloader.needRefresh = false;

            if (fullReload)
            {
                SongList.sFirstTime             = true;
                SongList.OnSongListLoaded.mDone = false;
                SongList.SongSourceDirs         = new Il2CppSystem.Collections.Generic.List <SongList.SongSourceDir>();
                SongList.AddSongSearchDir(Application.dataPath, downloadsDirectory);
                SongList.I.StartAssembleSongList();
            }
            else
            {
                List <SongList.SongSourceDir> sourceDirs = new List <SongList.SongSourceDir>();
                sourceDirs.Add(new SongList.SongSourceDir(Application.streamingAssetsPath, mainSongDirectory));
                sourceDirs.Add(new SongList.SongSourceDir(Application.dataPath, downloadsDirectory));
                for (int i = 0; i < sourceDirs.Count; i++)
                {
                    SongList.SongSourceDir sourceDir = sourceDirs[i];
                    string[] files = Directory.GetFiles(sourceDir.dir, "*.audica");
                    for (int j = 0; j < files.Length; j++)
                    {
                        string file = files[j].Replace('\\', '/');
                        if (!SongLoadingManager.songFilenames.Contains(Path.GetFileName(file)) &&
                            !SongDownloader.downloadedFileNames.Contains(Path.GetFileName(file)))
                        {
                            SongList.I.ProcessSingleSong(sourceDir, file, new Il2CppSystem.Collections.Generic.HashSet <string>());
                        }
                    }
                }
            }

            SongDownloader.downloadedFileNames.Clear();
            SongLoadingManager.StartSongListUpdate(fullReload);

            DebugText("Reloading Songs");
        }
Пример #2
0
        /// <summary>
        /// Coroutine that downloads a song from given download URL. Caller is responsible to call
        /// SongBrowser.ReloadSongList() once download is done
        /// </summary>
        /// <param name="songID">SongID of download target, typically Song.song_id</param>
        /// <param name="downloadUrl">Download target, typically Song.download_url</param>
        /// <param name="onDownloadComplete">Called when download has been written to disk.
        ///     First argument is the songID of the downloaded song.
        ///     Second argument is true if the download succeeded, false otherwise.</param>
        public static IEnumerator DownloadSong(string songID, string downloadUrl, Action <string, bool> onDownloadComplete = null)
        {
            string audicaName   = songID + ".audica";
            string path         = Path.Combine(SongBrowser.mainSongDirectory, audicaName);
            string downloadPath = Path.Combine(SongBrowser.downloadsDirectory, audicaName);

            if (!File.Exists(path) && !File.Exists(downloadPath))
            {
                WWW www = new WWW(downloadUrl);
                yield return(www);

                byte[] results = www.bytes;
                File.WriteAllBytes(downloadPath, results);
            }
            yield return(null);

            SongList.SongSourceDir dir = new SongList.SongSourceDir(Application.dataPath, SongBrowser.downloadsDirectory);
            string file    = downloadPath.Replace('\\', '/');
            bool   success = SongList.I.ProcessSingleSong(dir, file, new Il2CppSystem.Collections.Generic.HashSet <string>());

            downloadedFileNames.Add(audicaName);

            if (success)
            {
                needRefresh = true;
            }
            else
            {
                failedDownloads.Add(audicaName);
                if (File.Exists(downloadPath))
                {
                    File.Delete(downloadPath);
                }
            }

            onDownloadComplete?.Invoke(songID, success);
        }