From cad154423e778369479d1710008695c323be6639 Mon Sep 17 00:00:00 2001 From: minenice55 Date: Wed, 10 Jan 2024 20:38:48 -0500 Subject: [PATCH 1/2] do this properly --- Assets/Scripts/GlobalGameManager.cs | 1 - Assets/Scripts/Minigames.cs | 13 ++++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/GlobalGameManager.cs b/Assets/Scripts/GlobalGameManager.cs index 654e2351..8db4ed1f 100644 --- a/Assets/Scripts/GlobalGameManager.cs +++ b/Assets/Scripts/GlobalGameManager.cs @@ -98,7 +98,6 @@ namespace HeavenStudio CustomScreenWidth = PersistentDataManager.gameSettings.resolutionWidth; CustomScreenHeight = PersistentDataManager.gameSettings.resolutionHeight; - if (PersistentDataManager.gameSettings.dspSize == 0) PersistentDataManager.gameSettings.dspSize = 512; if (PersistentDataManager.gameSettings.sampleRate == 0) diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 8d155908..63477306 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -151,12 +151,15 @@ namespace HeavenStudio public static string JukeboxAudioConverter(string filePath, AudioType audioType, string specificType) { - if (Directory.Exists(Path.Combine(Application.temporaryCachePath, "/savewav"))) + string wavCachePath = Path.Combine(Application.temporaryCachePath, "/savewav"); + if (Directory.Exists(wavCachePath)) { - Directory.Delete(Path.Combine(Application.temporaryCachePath, "/savewav"), true); + Directory.Delete(wavCachePath, true); + } + if (!Directory.Exists(wavCachePath)) + { + Directory.CreateDirectory(wavCachePath); } - if (!Directory.Exists(Application.temporaryCachePath, "/savewav")) - Directory.CreateDirectory(Application.temporaryCachePath, "/savewav"); if (audioType == AudioType.MPEG) { Debug.Log($"mp3 loaded, Converting {filePath} to wav..."); @@ -175,7 +178,7 @@ namespace HeavenStudio AudioClip clip = DownloadHandlerAudioClip.GetContent(www); string fileName = Path.GetFileNameWithoutExtension(filePath); SavWav.Save("/savewav/" + fileName, clip, true); - filePath = Path.Combine(Application.temporaryCachePath, "/savewav/" + fileName + ".wav"); + filePath = Path.Combine(wavCachePath, $"/{fileName}.wav"); clip = null; } From 71d610c09b6e562878e09a041c0db896e8675f4c Mon Sep 17 00:00:00 2001 From: minenice55 Date: Wed, 10 Jan 2024 20:43:25 -0500 Subject: [PATCH 2/2] don't put separator chars here --- Assets/Scripts/Minigames.cs | 6 +++--- Assets/Scripts/Util/SavWav.cs | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 63477306..7bb891ab 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -151,7 +151,7 @@ namespace HeavenStudio public static string JukeboxAudioConverter(string filePath, AudioType audioType, string specificType) { - string wavCachePath = Path.Combine(Application.temporaryCachePath, "/savewav"); + string wavCachePath = Path.Combine(Application.temporaryCachePath, "savewav"); if (Directory.Exists(wavCachePath)) { Directory.Delete(wavCachePath, true); @@ -177,8 +177,8 @@ namespace HeavenStudio } AudioClip clip = DownloadHandlerAudioClip.GetContent(www); string fileName = Path.GetFileNameWithoutExtension(filePath); - SavWav.Save("/savewav/" + fileName, clip, true); - filePath = Path.Combine(wavCachePath, $"/{fileName}.wav"); + SavWav.Save(fileName, clip, true); + filePath = Path.Combine(wavCachePath, $"{fileName}.wav"); clip = null; } diff --git a/Assets/Scripts/Util/SavWav.cs b/Assets/Scripts/Util/SavWav.cs index e3167257..a099bcd7 100644 --- a/Assets/Scripts/Util/SavWav.cs +++ b/Assets/Scripts/Util/SavWav.cs @@ -49,17 +49,18 @@ public static class SavWav public static void Save(string filename, AudioClip clip, bool trim = false) { + string wavCachePath = Path.Combine(Application.temporaryCachePath, "savewav"); if (!filename.ToLower().EndsWith(".wav")) { filename += ".wav"; } - var filepath = Path.Combine(Application.temporaryCachePath, filename); + var filepath = Path.Combine(wavCachePath, filename); // Make sure directory exists if user is saving to sub dir. - if (!Directory.Exists(Path.GetDirectoryName(filepath))) + if (!Directory.Exists(Path.GetDirectoryName(wavCachePath))) { - Directory.CreateDirectory(Path.GetDirectoryName(filepath)); + Directory.CreateDirectory(Path.GetDirectoryName(wavCachePath)); } using (var fileStream = new FileStream(filepath, FileMode.Create))