Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion physfs_platform_raylib.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ char *__PHYSFS_platformCalcUserDir(void)
}

/**
* Gets a subdirectory from the application directory.
* Gets a subdirectory from the application directory, creating the
* org/app directories on disk if they don't already exist.
*
* TODO: Add a user pref directory to raylib?
*/
Expand All @@ -120,6 +121,16 @@ char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
pos += TextCopy(result + pos, app);
result[pos++] = '/';
result[pos] = '\0';

/* Create the org/app directories on disk. MakeDirectory() creates any
* missing intermediate directories, and succeeds if they already exist. */
if (MakeDirectory(result) != 0) {
TraceLog(LOG_WARNING, "PHYSFS: platformCalcPrefDir failed to create: %s", result);
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
MemFree(result);
return NULL;
}

TraceLog(LOG_DEBUG, "PHYSFS: platformCalcPrefDir: %s", result);
return result;
}
Expand Down
16 changes: 13 additions & 3 deletions test/raylib-physfs-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,22 @@ int main(int argc, char *argv[]) {
Assert(UnmountPhysFS("resources"));
AssertNot(UnmountPhysFS("MissingDirectory"));

// SetPhysFSCallbacks()
SetPhysFSCallbacks();

// GetPrefDirectory
const char* perfDir = GetPrefDirectory("RobLoach", "raylib-physfs-test");
AssertNotEqual(perfDir, 0);
Assert(DirectoryExists(perfDir), "GetPrefDirectory() should create the directory on disk");

// Write into the pref directory
{
Assert(SetPhysFSWriteDirectory(perfDir));
Assert(SaveFileTextToPhysFS("pref-test.txt", "Pref file"));
char* prefText = LoadFileText(TextFormat("%spref-test.txt", perfDir));
Assert(TextIsEqual(prefText, "Pref file"));
UnloadFileText(prefText);
}

// SetPhysFSCallbacks()
SetPhysFSCallbacks();

// ClosePhysFS()
Assert(ClosePhysFS());
Expand Down
Loading