From 7dc84e0f67ce25cdf20af7350275454ff79419e3 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 4 Mar 2022 01:17:38 +0600 Subject: [PATCH] qt: Fix HDD path relativization on Windows --- src/86box.c | 6 +++++- src/config.c | 5 ++++- src/disk/hdd_image.c | 4 ++++ src/include/86box/plat.h | 1 + src/qt/qt_platform.cpp | 12 +++++++++++- src/unix/unix.c | 10 ++++++++++ src/win/win.c | 5 +++++ 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/86box.c b/src/86box.c index 444fe1e81..17a1cca9c 100644 --- a/src/86box.c +++ b/src/86box.c @@ -710,7 +710,11 @@ usage: if (rom_path[0] != '\0') pclog("# ROM path: %s\n", rom_path); else - pclog("# ROM path: %sroms\\\n", exe_path); +#ifndef _WIN32 + pclog("# ROM path: %sroms/\n", exe_path); +#else + pclog("# ROM path: %sroms\\\n", exe_path); +#endif pclog("# Configuration file: %s\n#\n\n", cfg_path); /* * We are about to read the configuration file, which MAY diff --git a/src/config.c b/src/config.c index 658e3be01..ccd949278 100644 --- a/src/config.c +++ b/src/config.c @@ -1402,6 +1402,7 @@ load_hard_disks(void) } else { plat_append_filename(hdd[c].fn, usr_path, p); } + plat_path_normalize(hdd[c].fn); /* If disk is empty or invalid, mark it for deletion. */ if (! hdd_is_valid(c)) { @@ -2810,11 +2811,13 @@ save_hard_disks(void) } sprintf(temp, "hdd_%02i_fn", c+1); - if (hdd_is_valid(c) && (strlen(hdd[c].fn) != 0)) + if (hdd_is_valid(c) && (strlen(hdd[c].fn) != 0)) { + plat_path_normalize(hdd[c].fn); if (!strnicmp(hdd[c].fn, usr_path, strlen(usr_path))) config_set_string(cat, temp, &hdd[c].fn[strlen(usr_path)]); else config_set_string(cat, temp, hdd[c].fn); + } else config_delete_var(cat, temp); } diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index 5244bc638..f52be646c 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -252,6 +252,10 @@ hdd_image_load(int id) int vhd_error = 0; memset(empty_sector, 0, sizeof(empty_sector)); + if (fn) { + plat_path_normalize(fn); + } + hdd_images[id].base = 0; diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index b09207c14..ee04d0e12 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -111,6 +111,7 @@ extern char *plat_get_extension(char *s); extern void plat_append_filename(char *dest, const char *s1, const char *s2); extern void plat_put_backslash(char *s); extern void plat_path_slash(char *path); +extern void plat_path_normalize(char *path); extern int plat_path_abs(char *path); 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 785f85619..4ec31b842 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -235,15 +235,25 @@ plat_path_abs(char *path) #endif } +void +plat_path_normalize(char* path) +{ + while (*path++ != 0) + { + if (*path == '\\') *path = '/'; + } +} + void plat_path_slash(char *path) { auto len = strlen(path); - auto separator = QDir::separator().toLatin1(); + auto separator = '/'; if (path[len-1] != separator) { path[len] = separator; path[len+1] = 0; } + plat_path_normalize(path); } void diff --git a/src/unix/unix.c b/src/unix/unix.c index 9eb2b2c35..83f6b4a9b 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -282,12 +282,22 @@ plat_path_abs(char *path) return path[0] == '/'; } +void +plat_path_normalize(char* path) +{ + while (*path++ != 0) + { + if (*path == '\\') *path = '/'; + } +} + void plat_path_slash(char *path) { if ((path[strlen(path)-1] != '/')) { strcat(path, "/"); } + plat_path_normalize(path); } void diff --git a/src/win/win.c b/src/win/win.c index e54f4d243..1490a1ce1 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -731,6 +731,11 @@ plat_remove(char *path) } } +void +plat_path_normalize(char* path) +{ + /* No-op */ +} /* Make sure a path ends with a trailing (back)slash. */ void