Add new platform functions for global directories

This commit is contained in:
cold-brewed
2024-05-17 15:09:04 -04:00
parent 0561f65592
commit aaf3ab575e
3 changed files with 55 additions and 16 deletions

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