public void Init(CustomSongInfo newCustomSongInfo) { customSongInfo = newCustomSongInfo; _levelID = customSongInfo.GetIdentifier(); _songName = customSongInfo.songName; _songSubName = customSongInfo.songSubName; _songAuthorName = customSongInfo.GetSongAuthor(); _beatsPerMinute = customSongInfo.beatsPerMinute; _songTimeOffset = customSongInfo.songTimeOffset; _shuffle = customSongInfo.shuffle; _shufflePeriod = customSongInfo.shufflePeriod; _previewStartTime = customSongInfo.previewStartTime; _previewDuration = customSongInfo.previewDuration; _environmentSceneInfo = LoadSceneInfo(customSongInfo.environmentName); }
public void Init(CustomSongInfo newCustomSongInfo) { customSongInfo = newCustomSongInfo; _levelID = customSongInfo.GetIdentifier(); _songName = customSongInfo.songName; _songSubName = customSongInfo.songSubName; _songAuthorName = customSongInfo.GetSongAuthor(); _beatsPerMinute = customSongInfo.beatsPerMinute; _songTimeOffset = customSongInfo.songTimeOffset; _shuffle = customSongInfo.shuffle; _shufflePeriod = customSongInfo.shufflePeriod; _previewStartTime = customSongInfo.previewStartTime; _previewDuration = customSongInfo.previewDuration; _environmentSceneInfo = EnvironmentsLoader.GetSceneInfo(customSongInfo.environmentName); _coverImage = SongLoader.CustomSongsIcon; string _customEnvironment = customSongInfo.customEnvironment; string _customEnvironmentHash = customSongInfo.customEnvironmentHash; }
public IEnumerator DownloadSongCoroutine(Song songInfo, int row) { _loading = true; ui.SetButtonText(ref _downloadButton, "Downloading..."); _downloadButton.interactable = false; if (_deleteButton != null) { _deleteButton.interactable = false; } string downloadedSongPath = ""; UnityWebRequest www = UnityWebRequest.Get(songInfo.downloadUrl); www.timeout = 10; yield return(www.SendWebRequest()); log.Log("Received response from BeatSaver.com..."); if (www.isNetworkError || www.isHttpError) { log.Error(www.error); TextMeshProUGUI _errorText = ui.CreateText(_songDetailViewController.rectTransform, String.Format(www.error), new Vector2(18f, -64f)); Destroy(_errorText.gameObject, 2f); } else { string zipPath = ""; string docPath = ""; string customSongsPath = ""; try { byte[] data = www.downloadHandler.data; docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); customSongsPath = docPath + "/CustomSongs/" + songInfo.id + "/"; zipPath = customSongsPath + songInfo.beatname + ".zip"; if (!Directory.Exists(customSongsPath)) { Directory.CreateDirectory(customSongsPath); } File.WriteAllBytes(zipPath, data); log.Log("Downloaded zip file!"); }catch (Exception e) { log.Exception("EXCEPTION: " + e); _songListViewController._songsTableView.SelectRow(row); RefreshDetails(row); _loading = false; if (_deleteButton != null) { _downloadButton.interactable = true; } yield break; } bool isOverwriting = false; using (var zf = new ZipFile(zipPath)) { foreach (ZipEntry ze in zf) { if (ze.IsFile) { if (string.IsNullOrEmpty(downloadedSongPath) && ze.Name.IndexOf('/') != -1) { downloadedSongPath = customSongsPath + ze.Name.Substring(0, ze.Name.IndexOf('/')); } if (Directory.Exists(customSongsPath + ze.Name.Substring(0, ze.Name.IndexOf('/')))) { yield return(PromptOverwriteFiles(ze.Name.Substring(0, ze.Name.IndexOf('/')))); break; } else { isOverwriting = true; } } else if (ze.IsDirectory) { downloadedSongPath = customSongsPath + ze.Name; if (Directory.Exists(customSongsPath + ze.Name)) { yield return(PromptOverwriteFiles(ze.Name.Trim('\\', '/'))); break; } else { isOverwriting = true; } } } } if (_confirmOverwriteState == Prompt.Yes || isOverwriting) { FastZip zip = new FastZip(); log.Log("Extractibg..."); zip.ExtractZip(zipPath, customSongsPath, null); try { CustomSongInfo downloadedSong = GetCustomSongInfo(downloadedSongPath); CustomLevelStaticData newLevel = null; try { newLevel = ScriptableObject.CreateInstance <CustomLevelStaticData>(); } catch (Exception e) { //LevelStaticData.OnEnable throws null reference exception because we don't have time to set _difficultyLevels } ReflectionUtil.SetPrivateField(newLevel, "_levelId", downloadedSong.GetIdentifier()); ReflectionUtil.SetPrivateField(newLevel, "_authorName", downloadedSong.authorName); ReflectionUtil.SetPrivateField(newLevel, "_songName", downloadedSong.songName); ReflectionUtil.SetPrivateField(newLevel, "_songSubName", downloadedSong.songSubName); ReflectionUtil.SetPrivateField(newLevel, "_previewStartTime", downloadedSong.previewStartTime); ReflectionUtil.SetPrivateField(newLevel, "_previewDuration", downloadedSong.previewDuration); ReflectionUtil.SetPrivateField(newLevel, "_beatsPerMinute", downloadedSong.beatsPerMinute); List <LevelStaticData.DifficultyLevel> difficultyLevels = new List <LevelStaticData.DifficultyLevel>(); LevelStaticData.DifficultyLevel newDiffLevel = new LevelStaticData.DifficultyLevel(); StartCoroutine(LoadAudio("file://" + downloadedSong.path + "/" + downloadedSong.difficultyLevels[0].audioPath, newDiffLevel, "_audioClip")); difficultyLevels.Add(newDiffLevel); ReflectionUtil.SetPrivateField(newLevel, "_difficultyLevels", difficultyLevels.ToArray()); newLevel.OnEnable(); _notUpdatedSongs.Add(newLevel); }catch (Exception e) { log.Exception("Can't play preview! Exception: " + e); } UpdateAlreadyDownloadedSongs(); _songListViewController.RefreshScreen(); log.Log("Downloaded!"); } _confirmOverwriteState = Prompt.NotSelected; File.Delete(zipPath); } try { _songListViewController._songsTableView.SelectRow(row); RefreshDetails(row); } catch (Exception e) { log.Exception(e.ToString()); } _loading = false; if (_deleteButton != null) { _downloadButton.interactable = true; } }