mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Fix last commit breaking audio
This commit is contained in:
parent
533cca344f
commit
bb1a3d1e74
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user