Add provisions for portable mode to global dir functions

This commit is contained in:
David Hrdlička
2025-08-24 20:49:16 +02:00
committed by GitHub
parent 1b2aa32c67
commit 156d6f8bc8
4 changed files with 56 additions and 26 deletions

View File

@@ -228,6 +228,8 @@ int other_scsi_present = 0; /* SCSI contro
present */ present */
int is_pcjr = 0; /* The current machine is PCjr. */ int is_pcjr = 0; /* The current machine is PCjr. */
int portable_mode = 0; /* We are running in portable mode
(global dirs = exe path) */
// Accelerator key array // Accelerator key array
struct accelKey acc_keys[NUM_ACCELS]; struct accelKey acc_keys[NUM_ACCELS];

View File

@@ -42,6 +42,8 @@
#define GLOBAL_CONFIG_FILE "86box_global.cfg" #define GLOBAL_CONFIG_FILE "86box_global.cfg"
#define NVR_PATH "nvr" #define NVR_PATH "nvr"
#define SCREENSHOT_PATH "screenshots" #define SCREENSHOT_PATH "screenshots"
#define VMM_PATH "Virtual Machines"
#define VMM_PATH_WINDOWS "86Box VMs"
/* Recently used images */ /* Recently used images */
#define MAX_PREV_IMAGES 10 #define MAX_PREV_IMAGES 10
@@ -195,7 +197,10 @@ extern char global_cfg_path[1024]; /* full path of global config file */
extern int open_dir_usr_path; /* default file open dialog directory of usr_path */ extern int open_dir_usr_path; /* default file open dialog directory of usr_path */
extern char uuid[MAX_UUID_LEN]; /* UUID or machine identifier */ extern char uuid[MAX_UUID_LEN]; /* UUID or machine identifier */
extern char vmm_path[1024]; /* VM Manager path to scan */ extern char vmm_path[1024]; /* VM Manager path to scan */
extern int start_vmm; extern int start_vmm; /* the current execution will start the manager */
extern int portable_mode /* we are running in portable mode
(global dirs = exe path) */
#ifndef USE_NEW_DYNAREC #ifndef USE_NEW_DYNAREC
extern FILE *stdlog; /* file to log output to */ extern FILE *stdlog; /* file to log output to */
#endif #endif

View File

@@ -668,6 +668,9 @@ plat_chdir(char *path)
void void
plat_get_global_config_dir(char *outbuf, const size_t len) plat_get_global_config_dir(char *outbuf, const size_t len)
{ {
if (portable_mode) {
strncpy(outbuf, exe_path, len);
} else {
const auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); const auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
if (!dir.exists()) { if (!dir.exists()) {
if (!dir.mkpath(".")) { if (!dir.mkpath(".")) {
@@ -677,9 +680,15 @@ plat_get_global_config_dir(char *outbuf, const size_t len)
strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len); strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len);
} }
path_slash(outbuf);
}
void void
plat_get_global_data_dir(char *outbuf, const size_t len) plat_get_global_data_dir(char *outbuf, const size_t len)
{ {
if (portable_mode) {
strncpy(outbuf, exe_path, len);
} else {
const auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); const auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
if (!dir.exists()) { if (!dir.exists()) {
if (!dir.mkpath(".")) { if (!dir.mkpath(".")) {
@@ -689,22 +698,34 @@ plat_get_global_data_dir(char *outbuf, const size_t len)
strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len); strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len);
} }
path_slash(outbuf);
}
void void
plat_get_temp_dir(char *outbuf, const uint8_t len) plat_get_temp_dir(char *outbuf, const uint8_t len)
{ {
const auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); const auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len); strncpy(outbuf, dir.canonicalPath().toUtf8().constData(), len);
path_slash(outbuf);
} }
void void
plat_get_vmm_dir(char *outbuf, const size_t len) plat_get_vmm_dir(char *outbuf, const size_t len)
{ {
QString path;
if (portable_mode) {
path = QDir(exe_path).filePath(VMM_PATH);
} else {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
const auto path = QDir::home().filePath("86Box VMs"); path = QDir::home().filePath(VMM_PATH_WINDOWS);
#else #else
const auto path = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("Virtual Machines"); path = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath(VMM_PATH);
#endif #endif
}
strncpy(outbuf, path.toUtf8().constData(), len); strncpy(outbuf, path.toUtf8().constData(), len);
path_slash(outbuf);
} }
void void

View File

@@ -875,21 +875,23 @@ plat_init_rom_paths(void)
void void
plat_get_global_config_dir(char *outbuf, const size_t len) plat_get_global_config_dir(char *outbuf, const size_t len)
{ {
char *prefPath = SDL_GetPrefPath(NULL, "86Box"); return plat_get_global_data_dir(outbuf, len);
strncpy(outbuf, prefPath, len);
path_slash(outbuf);
SDL_free(prefPath);
} }
void void
plat_get_global_data_dir(char *outbuf, const size_t len) plat_get_global_data_dir(char *outbuf, const size_t len)
{ {
if (portable_mode) {
strncpy(outbuf, exe_path, len);
} else {
char *prefPath = SDL_GetPrefPath(NULL, "86Box"); char *prefPath = SDL_GetPrefPath(NULL, "86Box");
strncpy(outbuf, prefPath, len); strncpy(outbuf, prefPath, len);
path_slash(outbuf);
SDL_free(prefPath); SDL_free(prefPath);
} }
path_slash(outbuf);
}
void void
plat_get_temp_dir(char *outbuf, uint8_t len) plat_get_temp_dir(char *outbuf, uint8_t len)
{ {