Skip to content
Permalink
Browse files

Fix not being able to load audio/maps/texpacks from within subdirecto…

…ries (Thanks steve82)
  • Loading branch information
UnknownShadow200 committed Dec 29, 2019
1 parent a3a4eb2 commit 5300b8fc497386887750d9249d309000f92dfd88
Showing with 24 additions and 8 deletions.
  1. +3 −2 src/Audio.c
  2. +6 −6 src/Menus.c
  3. +13 −0 src/Utils.c
  4. +2 −0 src/Utils.h
@@ -912,8 +912,9 @@ static int Audio_LoadVolume(const char* volKey, const char* boolKey) {
}

static void Audio_FilesCallback(const String* path, void* obj) {
String file = *path; Utils_UNSAFE_GetFilename(&file);
StringsBuffer_Add(&files, &file);
String relPath = *path;
Utils_UNSAFE_TrimFirstDirectory(&relPath);
StringsBuffer_Add(&files, &relPath);
}

static void Audio_Init(void) {
@@ -1484,11 +1484,11 @@ static void TexturePackScreen_EntryClick(void* screen, void* widget) {

static void TexturePackScreen_FilterFiles(const String* path, void* obj) {
static const String zip = String_FromConst(".zip");
String file = *path;
String relPath = *path;
if (!String_CaselessEnds(path, &zip)) return;

Utils_UNSAFE_GetFilename(&file);
StringsBuffer_Add((StringsBuffer*)obj, &file);
Utils_UNSAFE_TrimFirstDirectory(&relPath);
StringsBuffer_Add((StringsBuffer*)obj, &relPath);
}

static void TexturePackScreen_LoadEntries(struct ListScreen* s) {
@@ -1650,11 +1650,11 @@ static void LoadLevelScreen_EntryClick(void* screen, void* widget) {

static void LoadLevelScreen_FilterFiles(const String* path, void* obj) {
IMapImporter importer = Map_FindImporter(path);
String file = *path;
String relPath = *path;
if (!importer) return;

Utils_UNSAFE_GetFilename(&file);
StringsBuffer_Add((StringsBuffer*)obj, &file);
Utils_UNSAFE_TrimFirstDirectory(&relPath);
StringsBuffer_Add((StringsBuffer*)obj, &relPath);
}

static void LoadLevelScreen_LoadEntries(struct ListScreen* s) {
@@ -49,6 +49,19 @@ void Utils_UNSAFE_GetFilename(STRING_REF String* path) {
}
}

void Utils_UNSAFE_TrimFirstDirectory(STRING_REF String* path) {
char c;
int i;

for (i = 0; i < path->length; i++) {
c = path->buffer[i];
if (c == '/' || c == '\\') {
*path = String_UNSAFE_SubstringAt(path, i + 1); return;
}
}
}


int Utils_AccumulateWheelDelta(float* accumulator, float delta) {
int steps;
/* Some mice may use deltas of say (0.2, 0.3, 0.4, 0.1) */
@@ -35,6 +35,8 @@ cc_bool Utils_IsUrlPrefix(const String* value);
cc_bool Utils_EnsureDirectory(const char* dirName);
/* Gets the filename portion of a path. (e.g. "dir/file.txt" -> "file.txt") */
void Utils_UNSAFE_GetFilename(STRING_REF String* path);
/* Gets rid of first directory in a path. (e.g. "dx/gl/aa.txt" -> "gl/aa.txt" */
void Utils_UNSAFE_TrimFirstDirectory(STRING_REF String* path);
int Utils_AccumulateWheelDelta(float* accumulator, float delta);
#define Utils_AdjViewDist(value) ((int)(1.4142135f * (value)))

0 comments on commit 5300b8f

Please sign in to comment.
You can’t perform that action at this time.