Start of global config infrastructure

This commit is contained in:
Cacodemon345
2022-11-06 22:32:58 +06:00
parent 954e022244
commit e4e1852462
4 changed files with 45 additions and 0 deletions

View File

@@ -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);

View File

@@ -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()
{

View File

@@ -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)
{

View File

@@ -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()
{