1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-05 13:53:38 +00:00

Fix lovr.filesystem.setRequirePath;

This commit is contained in:
bjorn 2018-03-22 10:39:31 -07:00
parent adee0a3012
commit 5fd20cc955
3 changed files with 28 additions and 24 deletions

View file

@ -290,13 +290,7 @@ int l_lovrFilesystemSetIdentity(lua_State* L) {
} }
int l_lovrFilesystemSetRequirePath(lua_State* L) { int l_lovrFilesystemSetRequirePath(lua_State* L) {
char* requirePath = strdup(luaL_checkstring(L, 1)); lovrFilesystemSetRequirePath(luaL_checkstring(L, 1));
char* pattern;
lovrFilesystemClearRequirePath();
while ((pattern = strsep(&requirePath, ";")) != NULL) {
lovrFilesystemAddRequirePath(pattern);
}
free(requirePath);
return 0; return 0;
} }

View file

@ -31,9 +31,8 @@ void lovrFilesystemInit(const char* arg0, const char* arg1) {
state.source = malloc(LOVR_PATH_MAX * sizeof(char)); state.source = malloc(LOVR_PATH_MAX * sizeof(char));
state.identity = NULL; state.identity = NULL;
state.isFused = true; state.isFused = true;
vec_init(&state.requirePath); vec_init(&state.requirePatterns);
vec_push(&state.requirePath, "?.lua"); lovrFilesystemSetRequirePath("?.lua;?/init.lua");
vec_push(&state.requirePath, "?/init.lua");
// Try to mount either an archive fused to the executable or an archive from the command line // Try to mount either an archive fused to the executable or an archive from the command line
lovrFilesystemGetExecutablePath(state.source, LOVR_PATH_MAX); lovrFilesystemGetExecutablePath(state.source, LOVR_PATH_MAX);
@ -57,19 +56,12 @@ void lovrFilesystemDestroy() {
free(state.source); free(state.source);
free(state.savePathFull); free(state.savePathFull);
free(state.savePathRelative); free(state.savePathRelative);
vec_deinit(&state.requirePath); free(state.requirePath);
vec_deinit(&state.requirePatterns);
PHYSFS_deinit(); PHYSFS_deinit();
memset(&state, 0, sizeof(FilesystemState)); memset(&state, 0, sizeof(FilesystemState));
} }
void lovrFilesystemAddRequirePath(const char* path) {
vec_push(&state.requirePath, (char*) path);
}
void lovrFilesystemClearRequirePath() {
vec_clear(&state.requirePath);
}
int lovrFilesystemCreateDirectory(const char* path) { int lovrFilesystemCreateDirectory(const char* path) {
return !PHYSFS_mkdir(path); return !PHYSFS_mkdir(path);
} }
@ -145,7 +137,7 @@ const char* lovrFilesystemGetRealDirectory(const char* path) {
} }
vec_str_t* lovrFilesystemGetRequirePath() { vec_str_t* lovrFilesystemGetRequirePath() {
return &state.requirePath; return &state.requirePatterns;
} }
const char* lovrFilesystemGetSaveDirectory() { const char* lovrFilesystemGetSaveDirectory() {
@ -286,6 +278,25 @@ int lovrFilesystemSetIdentity(const char* identity) {
return 0; return 0;
} }
void lovrFilesystemSetRequirePath(const char* requirePath) {
if (state.requirePath) {
free(state.requirePath);
vec_clear(&state.requirePatterns);
}
state.requirePath = strdup(requirePath);
char* p = state.requirePath;
while (1) {
vec_push(&state.requirePatterns, p);
if ((p = strchr(p, ';')) != NULL) {
*p++ = '\0';
} else {
break;
}
}
}
int lovrFilesystemUnmount(const char* path) { int lovrFilesystemUnmount(const char* path) {
return !PHYSFS_unmount(path); return !PHYSFS_unmount(path);
} }

View file

@ -15,13 +15,12 @@ typedef struct {
char* savePathRelative; char* savePathRelative;
char* savePathFull; char* savePathFull;
bool isFused; bool isFused;
vec_str_t requirePath; char* requirePath;
vec_str_t requirePatterns;
} FilesystemState; } FilesystemState;
void lovrFilesystemInit(const char* arg0, const char* arg1); void lovrFilesystemInit(const char* arg0, const char* arg1);
void lovrFilesystemDestroy(); void lovrFilesystemDestroy();
void lovrFilesystemAddRequirePath(const char* path);
void lovrFilesystemClearRequirePath();
int lovrFilesystemCreateDirectory(const char* path); int lovrFilesystemCreateDirectory(const char* path);
int lovrFilesystemGetAppdataDirectory(char* dest, unsigned int size); int lovrFilesystemGetAppdataDirectory(char* dest, unsigned int size);
void lovrFilesystemGetDirectoryItems(const char* path, getDirectoryItemsCallback callback, void* userdata); void lovrFilesystemGetDirectoryItems(const char* path, getDirectoryItemsCallback callback, void* userdata);
@ -42,6 +41,6 @@ int lovrFilesystemMount(const char* path, const char* mountpoint, bool append);
void* lovrFilesystemRead(const char* path, size_t* bytesRead); void* lovrFilesystemRead(const char* path, size_t* bytesRead);
int lovrFilesystemRemove(const char* path); int lovrFilesystemRemove(const char* path);
int lovrFilesystemSetIdentity(const char* identity); int lovrFilesystemSetIdentity(const char* identity);
int lovrFilesystemSetSource(const char* source); void lovrFilesystemSetRequirePath(const char* requirePath);
int lovrFilesystemUnmount(const char* path); int lovrFilesystemUnmount(const char* path);
size_t lovrFilesystemWrite(const char* path, const char* content, size_t size, bool append); size_t lovrFilesystemWrite(const char* path, const char* content, size_t size, bool append);