From 4b55dc8caeddce64f35c5d3386f4f03c0f350b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= <13226155+dhrdlicka@users.noreply.github.com> Date: Sat, 3 May 2025 01:41:18 +0200 Subject: [PATCH 1/2] plat: use size_t for global dir path buffer length --- src/include/86box/plat.h | 4 ++-- src/qt/qt_platform.cpp | 12 ++++++------ src/unix/unix.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index bbc673dcf..de0a9f30c 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -143,8 +143,8 @@ 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 *outbuf, uint8_t len); -extern void plat_get_global_data_dir(char *outbuf, uint8_t len); +extern void plat_get_global_config_dir(char *outbuf, size_t len); +extern void plat_get_global_data_dir(char *outbuf, size_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); diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index be40452fd..3bdbdf569 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -595,14 +595,14 @@ ProgSettings::reloadStrings() { translatedstrings.clear(); translatedstrings[STRING_MOUSE_CAPTURE] = QCoreApplication::translate("", "Click to capture mouse").toStdWString(); - + char mouseCaptureKeyseq[100]; sprintf(mouseCaptureKeyseq, qPrintable(QCoreApplication::translate("", "Press %s to release mouse")), acc_keys[FindAccelerator("release_mouse")].seq); translatedstrings[STRING_MOUSE_RELEASE] = QString(mouseCaptureKeyseq).toStdWString(); - + sprintf(mouseCaptureKeyseq, qPrintable(QCoreApplication::translate("", "Press %s or middle button to release mouse")), acc_keys[FindAccelerator("release_mouse")].seq); - translatedstrings[STRING_MOUSE_RELEASE_MMB] = QString(mouseCaptureKeyseq).toStdWString(); - + translatedstrings[STRING_MOUSE_RELEASE_MMB] = QString(mouseCaptureKeyseq).toStdWString(); + translatedstrings[STRING_INVALID_CONFIG] = QCoreApplication::translate("", "Invalid configuration").toStdWString(); translatedstrings[STRING_NO_ST506_ESDI_CDROM] = QCoreApplication::translate("", "MFM/RLL or ESDI CD-ROM drives never existed").toStdWString(); translatedstrings[STRING_PCAP_ERROR_NO_DEVICES] = QCoreApplication::translate("", "No PCap devices found").toStdWString(); @@ -639,7 +639,7 @@ plat_chdir(char *path) } void -plat_get_global_config_dir(char *outbuf, const uint8_t len) +plat_get_global_config_dir(char *outbuf, const size_t len) { const auto dir = QDir(QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation)[0]); if (!dir.exists()) { @@ -651,7 +651,7 @@ plat_get_global_config_dir(char *outbuf, const uint8_t len) } void -plat_get_global_data_dir(char *outbuf, const uint8_t len) +plat_get_global_data_dir(char *outbuf, const size_t len) { const auto dir = QDir(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)[0]); if (!dir.exists()) { diff --git a/src/unix/unix.c b/src/unix/unix.c index 2e92a90d3..bdee9006b 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -844,7 +844,7 @@ plat_init_rom_paths(void) } void -plat_get_global_config_dir(char *outbuf, const uint8_t len) +plat_get_global_config_dir(char *outbuf, const size_t len) { char *prefPath = SDL_GetPrefPath(NULL, "86Box"); strncpy(outbuf, prefPath, len); @@ -853,7 +853,7 @@ plat_get_global_config_dir(char *outbuf, const uint8_t len) } void -plat_get_global_data_dir(char *outbuf, const uint8_t len) +plat_get_global_data_dir(char *outbuf, const size_t len) { char *prefPath = SDL_GetPrefPath(NULL, "86Box"); strncpy(outbuf, prefPath, len); From fac052a50f398564769c300e35937ae38b29e492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= <13226155+dhrdlicka@users.noreply.github.com> Date: Sat, 3 May 2025 01:45:21 +0200 Subject: [PATCH 2/2] config: move some settings to a global config --- src/86box.c | 65 +++++++++----- src/config.c | 178 ++++++++++++++++++++++---------------- src/include/86box/86box.h | 1 + 3 files changed, 146 insertions(+), 98 deletions(-) diff --git a/src/86box.c b/src/86box.c index 1d7a73060..4131e7ecc 100644 --- a/src/86box.c +++ b/src/86box.c @@ -160,7 +160,7 @@ int window_remember; int vid_resize; /* (C) allow resizing */ int invert_display = 0; /* (C) invert the display */ int suppress_overscan = 0; /* (C) suppress overscans */ -int lang_id = 0; /* (C) language id */ +int lang_id = 0; /* (G) language id */ int scale = 0; /* (C) screen scale factor */ int dpi_scale = 0; /* (C) DPI scaling of the emulated screen */ @@ -168,7 +168,7 @@ int vid_api = 0; /* (C) video r int vid_cga_contrast = 0; /* (C) video */ int video_fullscreen = 0; /* (C) video */ int video_fullscreen_scale = 0; /* (C) video */ -int video_fullscreen_first = 0; /* (C) video */ +int video_fullscreen_first = 0; /* (G) video */ int enable_overscan = 0; /* (C) video */ int force_43 = 0; /* (C) video */ int video_filter_method = 1; /* (C) video */ @@ -199,13 +199,13 @@ int cpu = 0; /* (C) cpu typ int fpu_type = 0; /* (C) fpu type */ int fpu_softfloat = 0; /* (C) fpu uses softfloat */ int time_sync = 0; /* (C) enable time sync */ -int confirm_reset = 1; /* (C) enable reset confirmation */ -int confirm_exit = 1; /* (C) enable exit confirmation */ -int confirm_save = 1; /* (C) enable save confirmation */ +int confirm_reset = 1; /* (G) enable reset confirmation */ +int confirm_exit = 1; /* (G) enable exit confirmation */ +int confirm_save = 1; /* (G) enable save confirmation */ int enable_discord = 0; /* (C) enable Discord integration */ int pit_mode = -1; /* (C) force setting PIT mode */ int fm_driver = 0; /* (C) select FM sound driver */ -int open_dir_usr_path = 0; /* (C) default file open dialog directory +int open_dir_usr_path = 0; /* (G) default file open dialog directory of usr_path */ int video_fullscreen_scale_maximized = 0; /* (C) Whether fullscreen scaling settings also apply when maximized. */ @@ -215,7 +215,7 @@ int hook_enabled = 1; /* (C) Keyboar int test_mode = 0; /* (C) Test mode */ char uuid[MAX_UUID_LEN] = { '\0' }; /* (C) UUID or machine identifier */ int sound_muted = 0; /* (C) Is sound muted? */ -int inhibit_multimedia_keys; /* (C) Inhibit multimedia keys on Windows. */ +int inhibit_multimedia_keys; /* (G) Inhibit multimedia keys on Windows. */ int other_ide_present = 0; /* IDE controllers from non-IDE cards are present */ @@ -229,27 +229,27 @@ struct accelKey acc_keys[NUM_ACCELS]; struct accelKey def_acc_keys[NUM_ACCELS] = { { .name="send_ctrl_alt_del", .desc="Send Control+Alt+Del", .seq="Ctrl+F12" }, - - { .name="send_ctrl_alt_esc", .desc="Send Control+Alt+Escape", + + { .name="send_ctrl_alt_esc", .desc="Send Control+Alt+Escape", .seq="Ctrl+F10" }, - - { .name="fullscreen", .desc="Toggle fullscreen", + + { .name="fullscreen", .desc="Toggle fullscreen", .seq="Ctrl+Alt+PgUp" }, - - { .name="screenshot", .desc="Screenshot", + + { .name="screenshot", .desc="Screenshot", .seq="Ctrl+F11" }, - - { .name="release_mouse", .desc="Release mouse pointer", + + { .name="release_mouse", .desc="Release mouse pointer", .seq="Ctrl+End" }, - - { .name="hard_reset", .desc="Hard reset", + + { .name="hard_reset", .desc="Hard reset", .seq="Ctrl+Alt+F12" }, - - { .name="pause", .desc="Toggle pause", + + { .name="pause", .desc="Toggle pause", .seq="Ctrl+Alt+F1" }, - - { .name="mute", .desc="Toggle mute", - .seq="Ctrl+Alt+M" } + + { .name="mute", .desc="Toggle mute", + .seq="Ctrl+Alt+M" } }; @@ -271,6 +271,7 @@ extern double exp_pow_table[0x800]; char exe_path[2048]; /* path (dir) of executable */ char usr_path[1024]; /* path (dir) of user data */ char cfg_path[1024]; /* full path of config file */ +char global_cfg_path[1024]; /* full path of config file */ FILE *stdlog = NULL; /* file to log output to */ #if 0 int scrnsz_x = SCREEN_RES_X; /* current screen size, X */ @@ -308,7 +309,7 @@ static int suppr_seen = 1; void pclog_ensure_stdlog_open(void); #endif -/* +/* Ensures STDLOG is open for pclog_ex and pclog_ex_cyclic */ void pclog_ensure_stdlog_open(void) @@ -616,6 +617,7 @@ pc_show_usage(char *s) "-M or --missing\t\t- dump missing machines and video cards\n" "-N or --noconfirm\t\t- do not ask for confirmation on quit\n" "-P or --vmpath path\t\t- set 'path' to be root for vm\n" + "-O or --global path\t\t- set 'path' to be global config file\n" "-R or --rompath path\t\t- set 'path' to be ROM path\n" #ifndef USE_SDL_UI "-S or --settings\t\t\t- show only the settings dialog\n" @@ -655,6 +657,7 @@ pc_init(int argc, char *argv[]) char *ppath = NULL; char *rpath = NULL; char *cfg = NULL; + char *global = NULL; char *p; char temp[2048]; char *fn[FDD_NUM] = { NULL }; @@ -769,6 +772,11 @@ usage: #ifdef DEPRECATE_USAGE deprecated = 0; #endif + } else if (!strcasecmp(argv[c], "--global") || !strcasecmp(argv[c], "-O")) { + if ((c + 1) == argc || plat_dir_check(argv[c + 1])) + goto usage; + + global = argv[++c]; } else if (!strcasecmp(argv[c], "--image") || !strcasecmp(argv[c], "-I")) { if ((c + 1) == argc) goto usage; @@ -996,6 +1004,14 @@ usage: /* At this point, we can safely create the full path name. */ path_append_filename(cfg_path, usr_path, p); + /* Build the global configuration file path. */ + if (global == NULL) { + plat_get_global_config_dir(global_cfg_path, sizeof(global_cfg_path)); + path_append_filename(global_cfg_path, global_cfg_path, CONFIG_FILE); + } else { + strncpy(global_cfg_path, global, sizeof(global_cfg_path) - 1); + } + /* * Get the current directory's name * @@ -1025,7 +1041,8 @@ usage: pclog("# ROM path: %s\n", rom_path->path); } - pclog("# Configuration file: %s\n#\n\n", cfg_path); + pclog("# Global configuration file: %s\n", global_cfg_path); + pclog("# VM configuration file: %s\n#\n\n", cfg_path); /* * We are about to read the configuration file, which MAY * put data into global variables (the hard- and floppy diff --git a/src/config.c b/src/config.c index 52a80763a..f3d771e30 100644 --- a/src/config.c +++ b/src/config.c @@ -88,6 +88,7 @@ static int cy; static int cw; static int ch; static ini_t config; +static ini_t global; #ifdef ENABLE_CONFIG_LOG int config_do_log = ENABLE_CONFIG_LOG; @@ -107,6 +108,35 @@ config_log(const char *fmt, ...) # define config_log(fmt, ...) #endif +/* Load global configuration */ +static void +load_global(void) +{ + ini_section_t cat = ini_find_section(global, ""); + char *p; + + p = ini_section_get_string(cat, "language", NULL); + if (p != NULL) + lang_id = plat_language_code(p); + else + lang_id = plat_language_code(DEFAULT_LANGUAGE); + + open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0); + + confirm_reset = ini_section_get_int(cat, "confirm_reset", 1); + confirm_exit = ini_section_get_int(cat, "confirm_exit", 1); + confirm_save = ini_section_get_int(cat, "confirm_save", 1); + + video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1); + + inhibit_multimedia_keys = ini_section_get_int(cat, "inhibit_multimedia_keys", 0); + + mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0); + if (mouse_sensitivity < 0.1) + mouse_sensitivity = 0.1; + else if (mouse_sensitivity > 2.0) + mouse_sensitivity = 2.0; +} /* Load "General" section. */ static void @@ -128,12 +158,8 @@ load_general(void) video_fullscreen_scale = ini_section_get_int(cat, "video_fullscreen_scale", 1); - video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1); - video_filter_method = ini_section_get_int(cat, "video_filter_method", 1); - inhibit_multimedia_keys = ini_section_get_int(cat, "inhibit_multimedia_keys", 0); - force_43 = !!ini_section_get_int(cat, "force_43", 0); scale = ini_section_get_int(cat, "scale", 1); if (scale > 9) @@ -179,26 +205,8 @@ load_general(void) hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0); sound_muted = ini_section_get_int(cat, "sound_muted", 0); - confirm_reset = ini_section_get_int(cat, "confirm_reset", 1); - confirm_exit = ini_section_get_int(cat, "confirm_exit", 1); - confirm_save = ini_section_get_int(cat, "confirm_save", 1); - - p = ini_section_get_string(cat, "language", NULL); - if (p != NULL) - lang_id = plat_language_code(p); - else - lang_id = plat_language_code(DEFAULT_LANGUAGE); - - mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0); - if (mouse_sensitivity < 0.1) - mouse_sensitivity = 0.1; - else if (mouse_sensitivity > 2.0) - mouse_sensitivity = 2.0; - enable_discord = !!ini_section_get_int(cat, "enable_discord", 0); - open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0); - video_framerate = ini_section_get_int(cat, "video_gl_framerate", -1); video_vsync = ini_section_get_int(cat, "video_gl_vsync", 0); @@ -1800,7 +1808,21 @@ config_load(void) int i; ini_section_t c; - config_log("Loading config file '%s'..\n", cfg_path); + config_log("Loading global config file '%s'...\n", global_cfg_path); + + global = ini_read(global_cfg_path); + + if (global == NULL) { + global = ini_new(); + + lang_id = plat_language_code(DEFAULT_LANGUAGE); + + config_log("Global config file not present or invalid!\n"); + } else { + load_global(); + } + + config_log("Loading VM config file '%s'...\n", cfg_path); memset(hdd, 0, sizeof(hard_disk_t)); memset(cdrom, 0, sizeof(cdrom_t) * CDROM_NUM); @@ -1812,8 +1834,7 @@ config_load(void) config = ini_read(cfg_path); if (config == NULL) { - config = ini_new(); - config_changed = 1; + config = ini_new(); cpu_f = (cpu_family_t *) &cpu_families[0]; cpu = 0; @@ -1873,9 +1894,7 @@ config_load(void) cassette_pcm = 0; cassette_ui_writeprot = 0; - lang_id = plat_language_code(DEFAULT_LANGUAGE); - - config_log("Config file not present or invalid!\n"); + config_log("VM config file not present or invalid!\n"); } else { load_general(); /* General */ for (i = 0; i < MONITORS_NUM; i++) @@ -1913,29 +1932,74 @@ config_load(void) if (c != NULL) ini_rename_section(c, "3Dfx Voodoo Banshee"); - /* Mark the configuration as changed. */ - config_changed = 1; - - config_log("Config loaded.\n\n"); + config_log("VM config loaded.\n\n"); } + /* Mark the configuration as changed. */ + config_changed = 1; + video_copy = (video_grayscale || invert_display) ? video_transform_copy : memcpy; } +/* Save global configuration */ +static void +save_global(void) +{ + ini_section_t cat = ini_find_or_create_section(global, ""); + char buffer[512] = { 0 }; + + if (lang_id == plat_language_code(DEFAULT_LANGUAGE)) + ini_section_delete_var(cat, "language"); + else { + plat_language_code_r(lang_id, buffer, 511); + ini_section_set_string(cat, "language", buffer); + } + + if (open_dir_usr_path) + ini_section_set_int(cat, "open_dir_usr_path", open_dir_usr_path); + else + ini_section_delete_var(cat, "open_dir_usr_path"); + + if (confirm_reset != 1) + ini_section_set_int(cat, "confirm_reset", confirm_reset); + else + ini_section_delete_var(cat, "confirm_reset"); + + if (confirm_exit != 1) + ini_section_set_int(cat, "confirm_exit", confirm_exit); + else + ini_section_delete_var(cat, "confirm_exit"); + + if (confirm_save != 1) + ini_section_set_int(cat, "confirm_save", confirm_save); + else + ini_section_delete_var(cat, "confirm_save"); + + if (video_fullscreen_first == 1) + ini_section_delete_var(cat, "video_fullscreen_first"); + else + ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first); + + if (inhibit_multimedia_keys == 1) + ini_section_set_int(cat, "inhibit_multimedia_keys", inhibit_multimedia_keys); + else + ini_section_delete_var(cat, "inhibit_multimedia_keys"); + + if (mouse_sensitivity != 1.0) + ini_section_set_double(cat, "mouse_sensitivity", mouse_sensitivity); + else + ini_section_delete_var(cat, "mouse_sensitivity"); +} + /* Save "General" section. */ static void save_general(void) { ini_section_t cat = ini_find_or_create_section(config, "General"); char temp[512]; - char buffer[512] = { 0 }; const char *va_name; - ini_section_set_int(cat, "inhibit_multimedia_keys", inhibit_multimedia_keys); - if (inhibit_multimedia_keys == 0) - ini_section_delete_var(cat, "inhibit_multimedia_keys"); - ini_section_set_int(cat, "sound_muted", sound_muted); if (sound_muted == 0) ini_section_delete_var(cat, "sound_muted"); @@ -1955,11 +2019,6 @@ save_general(void) else ini_section_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale); - if (video_fullscreen_first == 1) - ini_section_delete_var(cat, "video_fullscreen_first"); - else - ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first); - if (video_filter_method == 1) ini_section_delete_var(cat, "video_filter_method"); else @@ -2041,43 +2100,11 @@ save_general(void) else ini_section_delete_var(cat, "hide_tool_bar"); - if (confirm_reset != 1) - ini_section_set_int(cat, "confirm_reset", confirm_reset); - else - ini_section_delete_var(cat, "confirm_reset"); - - if (confirm_exit != 1) - ini_section_set_int(cat, "confirm_exit", confirm_exit); - else - ini_section_delete_var(cat, "confirm_exit"); - - if (confirm_save != 1) - ini_section_set_int(cat, "confirm_save", confirm_save); - else - ini_section_delete_var(cat, "confirm_save"); - - if (mouse_sensitivity != 1.0) - ini_section_set_double(cat, "mouse_sensitivity", mouse_sensitivity); - else - ini_section_delete_var(cat, "mouse_sensitivity"); - - if (lang_id == plat_language_code(DEFAULT_LANGUAGE)) - ini_section_delete_var(cat, "language"); - else { - plat_language_code_r(lang_id, buffer, 511); - ini_section_set_string(cat, "language", buffer); - } - if (enable_discord) ini_section_set_int(cat, "enable_discord", enable_discord); else ini_section_delete_var(cat, "enable_discord"); - if (open_dir_usr_path) - ini_section_set_int(cat, "open_dir_usr_path", open_dir_usr_path); - else - ini_section_delete_var(cat, "open_dir_usr_path"); - if (video_framerate != -1) ini_section_set_int(cat, "video_gl_framerate", video_framerate); else @@ -3133,6 +3160,9 @@ save_other_removable_devices(void) void config_save(void) { + save_global(); /* Global */ + ini_write(global, global_cfg_path); + save_general(); /* General */ for (uint8_t i = 0; i < MONITORS_NUM; i++) save_monitor(i); /* Monitors */ diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index e19665535..c4ebb80e0 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -175,6 +175,7 @@ extern int hook_enabled; /* (C) Keyboard hook is enabled */ extern char exe_path[2048]; /* path (dir) of executable */ extern char usr_path[1024]; /* path (dir) of user data */ extern char cfg_path[1024]; /* full path of config file */ +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 char uuid[MAX_UUID_LEN]; /* UUID or machine identifier */ #ifndef USE_NEW_DYNAREC