From bb1a3d1e748b5ab8943dcb77ba2b72ae1bdd1afd Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 14 Apr 2018 15:47:21 +1000 Subject: [PATCH] Fix last commit breaking audio --- .../2D/Screens/Menu/LoadLevelScreen.cs | 5 ++-- .../2D/Screens/Menu/TexturePackScreen.cs | 4 --- ClassicalSharp/Audio/AudioPlayer.cs | 8 ++--- ClassicalSharp/Platform/Platform.cs | 14 +++++++-- src/Client/Menus.c | 30 +++++++------------ src/Client/Platform.h | 2 +- src/Client/WinPlatform.c | 10 +++++-- 7 files changed, 38 insertions(+), 35 deletions(-) diff --git a/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs index 378ecc483..a976d9f60 100644 --- a/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs @@ -28,9 +28,8 @@ namespace ClassicalSharp.Gui.Screens { entries = new string[count]; for (int i = 0, j = 0; i < rawFiles.Length; i++) { - string file = rawFiles[i]; - if (file == null) continue; - entries[j] = Path.GetFileName(file); j++; + if (rawFiles[i] == null) continue; + entries[j] = rawFiles[i]; j++; } Array.Sort(entries); } diff --git a/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs b/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs index c2e5ba764..2ea3d2b6b 100644 --- a/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs @@ -11,10 +11,6 @@ namespace ClassicalSharp.Gui.Screens { public TexturePackScreen(Game game) : base(game) { titleText = "Select a texture pack zip"; entries = Platform.DirectoryFiles("texpacks", "*.zip"); - - for (int i = 0; i < entries.Length; i++) { - entries[i] = Path.GetFileName(entries[i]); - } Array.Sort(entries); } diff --git a/ClassicalSharp/Audio/AudioPlayer.cs b/ClassicalSharp/Audio/AudioPlayer.cs index cb2fb2ef4..cd6cdeaa6 100644 --- a/ClassicalSharp/Audio/AudioPlayer.cs +++ b/ClassicalSharp/Audio/AudioPlayer.cs @@ -60,8 +60,7 @@ namespace ClassicalSharp.Audio { musicFiles = new string[musicCount]; for (int i = 0, j = 0; i < files.Length; i++) { if (!Utils.CaselessEnds(files[i], ".ogg")) continue; - musicFiles[j] = Path.GetFileName(files[i]); - j++; + musicFiles[j] = files[i]; j++; } disposingMusic = false; @@ -78,7 +77,8 @@ namespace ClassicalSharp.Audio { string file = musicFiles[rnd.Next(0, musicFiles.Length)]; Utils.LogDebug("playing music file: " + file); - using (Stream fs = Platform.FileOpen(file)) { + string path = Path.Combine("audio", file); + using (Stream fs = Platform.FileOpen(path)) { OggContainer container = new OggContainer(fs); try { musicOut.SetVolume(game.MusicVolume / 100.0f); @@ -88,7 +88,7 @@ namespace ClassicalSharp.Audio { return; } catch (Exception ex) { ErrorHandler.LogError("AudioPlayer.DoMusicThread()", ex); - game.Chat.Add("&cError while trying to play music file " + Path.GetFileName(file)); + game.Chat.Add("&cError while trying to play music file " + file); } } if (disposingMusic) break; diff --git a/ClassicalSharp/Platform/Platform.cs b/ClassicalSharp/Platform/Platform.cs index 8364bfd91..e461ba8a6 100644 --- a/ClassicalSharp/Platform/Platform.cs +++ b/ClassicalSharp/Platform/Platform.cs @@ -115,12 +115,22 @@ namespace ClassicalSharp { public static string[] DirectoryFiles(string relPath) { string path = Path.Combine(AppDirectory, relPath); - return Directory.GetFiles(relPath); + string[] files = Directory.GetFiles(relPath); + + for (int i = 0; i < files.Length; i++) { + files[i] = Path.GetFileName(files[i]); + } + return files; } public static string[] DirectoryFiles(string relPath, string filter) { string path = Path.Combine(AppDirectory, relPath); - return Directory.GetFiles(relPath, filter); + string[] files = Directory.GetFiles(relPath, filter); + + for (int i = 0; i < files.Length; i++) { + files[i] = Path.GetFileName(files[i]); + } + return files; } public static void WriteAllText(string relPath, string text) { diff --git a/src/Client/Menus.c b/src/Client/Menus.c index 3d74af9fc..d21af2eba 100644 --- a/src/Client/Menus.c +++ b/src/Client/Menus.c @@ -318,18 +318,6 @@ void ListScreen_QuickSort(Int32 left, Int32 right) { } } -void ListScreen_AddFilename(void* obj, STRING_PURE String* path) { - /* folder1/folder2/entry.zip --> entry.zip */ - Int32 lastDir = String_LastIndexOf(path, Platform_DirectorySeparator); - String filename = *path; - if (lastDir >= 0) { - filename = String_UNSAFE_SubstringAt(&filename, lastDir + 1); - } - - StringsBuffer* entries = (StringsBuffer*)obj; - StringsBuffer_Add(entries, &filename); -} - void ListScreen_MakePath(ListScreen* screen, GuiElement* w, STRING_PURE String* path, const UInt8* dir, STRING_REF String* filename) { Int32 idx = Menu_Index(screen->Widgets, Array_Elems(screen->Widgets), (Widget*)w); *filename = StringsBuffer_UNSAFE_Get(&screen->Entries, screen->CurrentIndex + idx); @@ -1234,10 +1222,12 @@ void TexturePackScreen_EntryClick(GuiElement* screenElem, GuiElement* w) { ListScreen_SetCurrentIndex(screen, curPage); } -void TexturePackScreen_SelectEntry(STRING_PURE String* path, void* obj) { +void TexturePackScreen_SelectEntry(STRING_PURE String* filename, void* obj) { String zip = String_FromConst(".zip"); - if (!String_CaselessEnds(path, &zip)) return; - ListScreen_AddFilename(obj, path); + if (!String_CaselessEnds(filename, &zip)) return; + + StringsBuffer* entries = (StringsBuffer*)obj; + StringsBuffer_Add(entries, filename); } Screen* TexturePackScreen_MakeInstance(void) { @@ -1258,13 +1248,15 @@ Screen* TexturePackScreen_MakeInstance(void) { /*########################################################################################################################* *----------------------------------------------------LoadLevelScreen------------------------------------------------------* *#########################################################################################################################*/ -void LoadLevelScreen_SelectEntry(STRING_PURE String* path, void* obj) { +void LoadLevelScreen_SelectEntry(STRING_PURE String* filename, void* obj) { String cw = String_FromConst(".cw"); String lvl = String_FromConst(".lvl"); String fcm = String_FromConst(".fcm"); String dat = String_FromConst(".dat"); - if (!(String_CaselessEnds(path, &cw) || String_CaselessEnds(path, &lvl) - || String_CaselessEnds(path, &fcm) || String_CaselessEnds(path, &dat))) return; - ListScreen_AddFilename(obj, path); + if (!(String_CaselessEnds(filename, &cw) || String_CaselessEnds(filename, &lvl) + || String_CaselessEnds(filename, &fcm) || String_CaselessEnds(filename, &dat))) return; + + StringsBuffer* entries = (StringsBuffer*)obj; + StringsBuffer_Add(entries, filename); } void LoadLevelScreen_EntryClick(GuiElement* screenElem, GuiElement* w) { diff --git a/src/Client/Platform.h b/src/Client/Platform.h index 16a61f1dd..c7fa481db 100644 --- a/src/Client/Platform.h +++ b/src/Client/Platform.h @@ -27,7 +27,7 @@ DateTime Platform_CurrentLocalTime(void); bool Platform_DirectoryExists(STRING_PURE String* path); ReturnCode Platform_DirectoryCreate(STRING_PURE String* path); bool Platform_FileExists(STRING_PURE String* path); -typedef void Platform_EnumFilesCallback(STRING_PURE String* path, void* obj); +typedef void Platform_EnumFilesCallback(STRING_PURE String* filename, void* obj); ReturnCode Platform_EnumFiles(STRING_PURE String* path, void* obj, Platform_EnumFilesCallback callback); ReturnCode Platform_FileCreate(void** file, STRING_PURE String* path); diff --git a/src/Client/WinPlatform.c b/src/Client/WinPlatform.c index 62fcdb1fc..4464293f4 100644 --- a/src/Client/WinPlatform.c +++ b/src/Client/WinPlatform.c @@ -138,9 +138,15 @@ ReturnCode Platform_EnumFiles(STRING_PURE String* path, void* obj, Platform_Enum if (find == INVALID_HANDLE_VALUE) return GetLastError(); do { - String filePath = String_FromRawArray(data.cFileName); + String path = String_FromRawArray(data.cFileName); if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - callback(&filePath, obj); + /* folder1/folder2/entry.zip --> entry.zip */ + Int32 lastDir = String_LastIndexOf(&path, Platform_DirectorySeparator); + String filename = path; + if (lastDir >= 0) { + filename = String_UNSAFE_SubstringAt(&filename, lastDir + 1); + } + callback(&filename, obj); } } while (FindNextFileA(find, &data));