From e4e1852462bf70612e9fa375c56a0fdeda71be92 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sun, 6 Nov 2022 22:32:58 +0600 Subject: [PATCH] Start of global config infrastructure --- src/include/86box/plat.h | 1 + src/qt/qt_platform.cpp | 12 ++++++++++++ src/unix/unix.c | 12 ++++++++++++ src/win/win.c | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index aa01ac129..cd88f3653 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -106,6 +106,7 @@ 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_init_rom_paths(); extern int plat_dir_check(char *path); extern int plat_dir_create(char *path); diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index bcf51d70d..734af2aab 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -609,6 +609,18 @@ plat_chdir(char *path) return QDir::setCurrent(QString(path)) ? 0 : -1; } +void +plat_get_global_config_dir(char* strptr) +{ +#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); +} + void plat_init_rom_paths() { diff --git a/src/unix/unix.c b/src/unix/unix.c index f2c6ed125..acd81c1f9 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -810,6 +810,18 @@ plat_init_rom_paths() #endif } +void +plat_get_global_config_dir(char *strptr) +{ +#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); +} + bool process_media_commands_3(uint8_t *id, char *fn, uint8_t *wp, int cmdargc) { diff --git a/src/win/win.c b/src/win/win.c index 5515d8e78..e99b94984 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -882,6 +882,26 @@ plat_mmap(size_t size, uint8_t executable) return VirtualAlloc(NULL, size, MEM_COMMIT, executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE); } +void +plat_get_global_config_dir(char* strptr) +{ + wchar_t appdata_dir[1024] = { L'\0' }; + + if (_wgetenv(L"LOCALAPPDATA") && _wgetenv(L"LOCALAPPDATA")[0] != L'\0') { + size_t len = 0; + wcsncpy(appdata_dir, _wgetenv(L"LOCALAPPDATA"), 1024); + len = wcslen(appdata_dir); + if (appdata_dir[len - 1] != L'\\') { + appdata_dir[len] = L'\\'; + appdata_dir[len + 1] = L'\0'; + } + wcscat(appdata_dir, L"86box"); + CreateDirectoryW(appdata_dir, NULL); + wcscat(appdata_dir, L"\\"); + c16stombs(strptr, appdata_dir, 1024); + } +} + void plat_init_rom_paths() {