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];
|
entries = new string[count];
|
||||||
for (int i = 0, j = 0; i < rawFiles.Length; i++) {
|
for (int i = 0, j = 0; i < rawFiles.Length; i++) {
|
||||||
string file = rawFiles[i];
|
if (rawFiles[i] == null) continue;
|
||||||
if (file == null) continue;
|
entries[j] = rawFiles[i]; j++;
|
||||||
entries[j] = Path.GetFileName(file); j++;
|
|
||||||
}
|
}
|
||||||
Array.Sort(entries);
|
Array.Sort(entries);
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,6 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
public TexturePackScreen(Game game) : base(game) {
|
public TexturePackScreen(Game game) : base(game) {
|
||||||
titleText = "Select a texture pack zip";
|
titleText = "Select a texture pack zip";
|
||||||
entries = Platform.DirectoryFiles("texpacks", "*.zip");
|
entries = Platform.DirectoryFiles("texpacks", "*.zip");
|
||||||
|
|
||||||
for (int i = 0; i < entries.Length; i++) {
|
|
||||||
entries[i] = Path.GetFileName(entries[i]);
|
|
||||||
}
|
|
||||||
Array.Sort(entries);
|
Array.Sort(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +60,7 @@ namespace ClassicalSharp.Audio {
|
|||||||
musicFiles = new string[musicCount];
|
musicFiles = new string[musicCount];
|
||||||
for (int i = 0, j = 0; i < files.Length; i++) {
|
for (int i = 0, j = 0; i < files.Length; i++) {
|
||||||
if (!Utils.CaselessEnds(files[i], ".ogg")) continue;
|
if (!Utils.CaselessEnds(files[i], ".ogg")) continue;
|
||||||
musicFiles[j] = Path.GetFileName(files[i]);
|
musicFiles[j] = files[i]; j++;
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disposingMusic = false;
|
disposingMusic = false;
|
||||||
@ -78,7 +77,8 @@ namespace ClassicalSharp.Audio {
|
|||||||
string file = musicFiles[rnd.Next(0, musicFiles.Length)];
|
string file = musicFiles[rnd.Next(0, musicFiles.Length)];
|
||||||
Utils.LogDebug("playing music file: " + file);
|
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);
|
OggContainer container = new OggContainer(fs);
|
||||||
try {
|
try {
|
||||||
musicOut.SetVolume(game.MusicVolume / 100.0f);
|
musicOut.SetVolume(game.MusicVolume / 100.0f);
|
||||||
@ -88,7 +88,7 @@ namespace ClassicalSharp.Audio {
|
|||||||
return;
|
return;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ErrorHandler.LogError("AudioPlayer.DoMusicThread()", 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;
|
if (disposingMusic) break;
|
||||||
|
@ -115,12 +115,22 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public static string[] DirectoryFiles(string relPath) {
|
public static string[] DirectoryFiles(string relPath) {
|
||||||
string path = Path.Combine(AppDirectory, 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) {
|
public static string[] DirectoryFiles(string relPath, string filter) {
|
||||||
string path = Path.Combine(AppDirectory, relPath);
|
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) {
|
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) {
|
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);
|
Int32 idx = Menu_Index(screen->Widgets, Array_Elems(screen->Widgets), (Widget*)w);
|
||||||
*filename = StringsBuffer_UNSAFE_Get(&screen->Entries, screen->CurrentIndex + idx);
|
*filename = StringsBuffer_UNSAFE_Get(&screen->Entries, screen->CurrentIndex + idx);
|
||||||
@ -1234,10 +1222,12 @@ void TexturePackScreen_EntryClick(GuiElement* screenElem, GuiElement* w) {
|
|||||||
ListScreen_SetCurrentIndex(screen, curPage);
|
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");
|
String zip = String_FromConst(".zip");
|
||||||
if (!String_CaselessEnds(path, &zip)) return;
|
if (!String_CaselessEnds(filename, &zip)) return;
|
||||||
ListScreen_AddFilename(obj, path);
|
|
||||||
|
StringsBuffer* entries = (StringsBuffer*)obj;
|
||||||
|
StringsBuffer_Add(entries, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
Screen* TexturePackScreen_MakeInstance(void) {
|
Screen* TexturePackScreen_MakeInstance(void) {
|
||||||
@ -1258,13 +1248,15 @@ Screen* TexturePackScreen_MakeInstance(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*----------------------------------------------------LoadLevelScreen------------------------------------------------------*
|
*----------------------------------------------------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 cw = String_FromConst(".cw"); String lvl = String_FromConst(".lvl");
|
||||||
String fcm = String_FromConst(".fcm"); String dat = String_FromConst(".dat");
|
String fcm = String_FromConst(".fcm"); String dat = String_FromConst(".dat");
|
||||||
|
|
||||||
if (!(String_CaselessEnds(path, &cw) || String_CaselessEnds(path, &lvl)
|
if (!(String_CaselessEnds(filename, &cw) || String_CaselessEnds(filename, &lvl)
|
||||||
|| String_CaselessEnds(path, &fcm) || String_CaselessEnds(path, &dat))) return;
|
|| String_CaselessEnds(filename, &fcm) || String_CaselessEnds(filename, &dat))) return;
|
||||||
ListScreen_AddFilename(obj, path);
|
|
||||||
|
StringsBuffer* entries = (StringsBuffer*)obj;
|
||||||
|
StringsBuffer_Add(entries, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadLevelScreen_EntryClick(GuiElement* screenElem, GuiElement* w) {
|
void LoadLevelScreen_EntryClick(GuiElement* screenElem, GuiElement* w) {
|
||||||
|
@ -27,7 +27,7 @@ DateTime Platform_CurrentLocalTime(void);
|
|||||||
bool Platform_DirectoryExists(STRING_PURE String* path);
|
bool Platform_DirectoryExists(STRING_PURE String* path);
|
||||||
ReturnCode Platform_DirectoryCreate(STRING_PURE String* path);
|
ReturnCode Platform_DirectoryCreate(STRING_PURE String* path);
|
||||||
bool Platform_FileExists(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_EnumFiles(STRING_PURE String* path, void* obj, Platform_EnumFilesCallback callback);
|
||||||
|
|
||||||
ReturnCode Platform_FileCreate(void** file, STRING_PURE String* path);
|
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();
|
if (find == INVALID_HANDLE_VALUE) return GetLastError();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
String filePath = String_FromRawArray(data.cFileName);
|
String path = String_FromRawArray(data.cFileName);
|
||||||
if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
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));
|
} while (FindNextFileA(find, &data));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user