Merge pull request #4458 from cold-brewed/plat-dir-updates

Add new platform functions for global directories
This commit is contained in:
Miran Grča
2024-05-17 23:46:14 +02:00
committed by GitHub
3 changed files with 55 additions and 16 deletions

View File

@@ -138,7 +138,9 @@ extern int plat_getcwd(char *bufp, int max);
extern int plat_chdir(char *path);
extern void plat_tempfile(char *bufp, char *prefix, char *suffix);
extern void plat_get_exe_name(char *s, int size);
extern void plat_get_global_config_dir(char* strptr);
extern void plat_get_global_config_dir(char *outbuf, uint8_t len);
extern void plat_get_global_data_dir(char *outbuf, uint8_t len);
extern void plat_get_temp_dir(char *outbuf, uint8_t len);
extern void plat_init_rom_paths(void);
extern int plat_dir_check(char *path);
extern int plat_dir_create(char *path);

View File

@@ -634,15 +634,34 @@ plat_chdir(char *path)
}
void
plat_get_global_config_dir(char* strptr)
plat_get_global_config_dir(char *outbuf, const uint8_t len)
{
#ifdef __APPLE__
auto dir = QDir(QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)[0] + "/net.86Box.86Box/");
#else
auto dir = QDir(QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)[0] + "/86Box/");
#endif
if (!dir.exists()) dir.mkpath(".");
strncpy(strptr, dir.canonicalPath().toUtf8().constData(), 1024);
const auto dir = QDir(QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation)[0]);
if (!dir.exists()) {
if (!dir.mkpath(".")) {
qWarning("Failed to create global configuration directory %s", dir.absolutePath().toUtf8().constData());
}
}
strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len);
}
void
plat_get_global_data_dir(char *outbuf, const uint8_t len)
{
const auto dir = QDir(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)[0]);
if (!dir.exists()) {
if (!dir.mkpath(".")) {
qWarning("Failed to create global data directory %s", dir.absolutePath().toUtf8().constData());
}
}
strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len);
}
void
plat_get_temp_dir(char *outbuf, const uint8_t len)
{
const auto dir = QDir(QStandardPaths::standardLocations(QStandardPaths::TempLocation)[0]);
strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len);
}
void
@@ -662,6 +681,7 @@ plat_init_rom_paths(void)
for (auto &path : paths) {
#ifdef __APPLE__
rom_add_path(QDir(path).filePath("net.86Box.86Box/roms").toUtf8().constData());
rom_add_path(QDir(path).filePath("86Box/roms").toUtf8().constData());
#else
rom_add_path(QDir(path).filePath("86Box/roms").toUtf8().constData());
#endif

View File

@@ -826,15 +826,32 @@ plat_init_rom_paths(void)
}
void
plat_get_global_config_dir(char *strptr)
plat_get_global_config_dir(char *outbuf, const uint8_t len)
{
#ifdef __APPLE__
char *prefPath = SDL_GetPrefPath(NULL, "net.86Box.86Box");
#else
char *prefPath = SDL_GetPrefPath(NULL, "86Box");
#endif
strncpy(strptr, prefPath, 1024);
path_slash(strptr);
strncpy(outbuf, prefPath, len);
path_slash(outbuf);
SDL_free(prefPath);
}
void
plat_get_global_data_dir(char *outbuf, const uint8_t len)
{
char *prefPath = SDL_GetPrefPath(NULL, "86Box");
strncpy(outbuf, prefPath, len);
path_slash(outbuf);
SDL_free(prefPath);
}
void
plat_get_temp_dir(char *outbuf, uint8_t len)
{
const char *tmpdir = getenv("TMPDIR");
if (tmpdir == NULL) {
tmpdir = "/tmp";
}
strncpy(outbuf, tmpdir, len);
path_slash(outbuf);
}
bool