From af22ff9e620ea18557e5342d1e055760a58cbab3 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 17 Apr 2021 20:02:37 -0300 Subject: [PATCH 1/5] Add native Win32 version of the nvr directory iteration code for MSVC --- src/config.c | 27 +++++++++++++++++++++++---- src/include/tinyglib.h | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/config.c b/src/config.c index 8a8512b64..b7866dd71 100644 --- a/src/config.c +++ b/src/config.c @@ -32,7 +32,11 @@ #include #include #include -#include +#ifdef _WIN32 +# include +#else +# include +#endif #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -621,21 +625,32 @@ load_machine(void) i = strlen(new_fn); /* Iterate through NVR files. */ +#ifdef _WIN32 + WIN32_FIND_DATA find_data; + strcat(old_fn, "*"); + HANDLE search = FindFirstFile(nvr_path(old_fn), &find_data); + if (search != INVALID_HANDLE_VALUE) { + do { + p = find_data.cFileName; +#else DIR *dirp = opendir(nvr_path(".")); if (dirp) { struct dirent *entry; while ((entry = readdir(dirp))) { + p = entry->d_name; + /* Check if this file corresponds to the old name. */ - if (strncmp(entry->d_name, old_fn, c)) + if (strncmp(p, old_fn, c)) continue; +#endif /* Add extension to the new name. */ - strcpy(&new_fn[i], &entry->d_name[c]); + strcpy(&new_fn[i], &p[c]); /* Only copy if a file with the new name doesn't already exist. */ FILE *g = nvr_fopen(new_fn, "rb"); if (!g) { - FILE *f = nvr_fopen(entry->d_name, "rb"); + FILE *f = nvr_fopen(p, "rb"); g = nvr_fopen(new_fn, "wb"); uint8_t buf[4096]; @@ -645,7 +660,11 @@ load_machine(void) fclose(f); } fclose(g); +#ifdef _WIN32 + } while (FindNextFile(search, &find_data)); +#else } +#endif } } diff --git a/src/include/tinyglib.h b/src/include/tinyglib.h index 24f9409a3..5f6c6a028 100644 --- a/src/include/tinyglib.h +++ b/src/include/tinyglib.h @@ -259,6 +259,7 @@ g_strv_length(gchar **str_array) #define g_rand_new() calloc(1, sizeof(GRand)) #define g_return_val_if_fail(e, v) if (!(e)) return (v) #define g_shell_parse_argv(a, b, c, d) !!(sizeof(b)) /* unimplemented */ +#define g_strdup(str) ((str) ? strdup(str) : NULL) #define g_warn_if_fail(e) do { if (!(e)) pclog("TinyGLib g_warn_if_fail(" #e ")\n"); } while (0) #define g_warn_if_reached() pclog("TinyGLib g_warn_if_reached()\n") #define g_warning(s, ...) tinyglib_pclog("g_warning", s, ##__VA_ARGS__) @@ -271,7 +272,6 @@ g_strv_length(gchar **str_array) #define g_rand_free free #define g_realloc realloc #define g_snprintf snprintf -#define g_strdup(str) str ? strdup(str) : NULL #define g_strerror strerror #define g_strfreev free #define g_string_append_printf sprintf /* unimplemented */ From 22cae247a87cadd74b5fc026024b0c116e7369ff Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 17 Apr 2021 20:05:39 -0300 Subject: [PATCH 2/5] Revert "Add native Win32 version of the nvr directory iteration code for MSVC" This reverts commit af22ff9e620ea18557e5342d1e055760a58cbab3. --- src/config.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/config.c b/src/config.c index b7866dd71..8a8512b64 100644 --- a/src/config.c +++ b/src/config.c @@ -32,11 +32,7 @@ #include #include #include -#ifdef _WIN32 -# include -#else -# include -#endif +#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -625,32 +621,21 @@ load_machine(void) i = strlen(new_fn); /* Iterate through NVR files. */ -#ifdef _WIN32 - WIN32_FIND_DATA find_data; - strcat(old_fn, "*"); - HANDLE search = FindFirstFile(nvr_path(old_fn), &find_data); - if (search != INVALID_HANDLE_VALUE) { - do { - p = find_data.cFileName; -#else DIR *dirp = opendir(nvr_path(".")); if (dirp) { struct dirent *entry; while ((entry = readdir(dirp))) { - p = entry->d_name; - /* Check if this file corresponds to the old name. */ - if (strncmp(p, old_fn, c)) + if (strncmp(entry->d_name, old_fn, c)) continue; -#endif /* Add extension to the new name. */ - strcpy(&new_fn[i], &p[c]); + strcpy(&new_fn[i], &entry->d_name[c]); /* Only copy if a file with the new name doesn't already exist. */ FILE *g = nvr_fopen(new_fn, "rb"); if (!g) { - FILE *f = nvr_fopen(p, "rb"); + FILE *f = nvr_fopen(entry->d_name, "rb"); g = nvr_fopen(new_fn, "wb"); uint8_t buf[4096]; @@ -660,11 +645,7 @@ load_machine(void) fclose(f); } fclose(g); -#ifdef _WIN32 - } while (FindNextFile(search, &find_data)); -#else } -#endif } } From 867f76d9b491c3a2ebd8fca6cb353cbbf14ea134 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 17 Apr 2021 20:17:27 -0300 Subject: [PATCH 3/5] Fix the Windows dirent reimplementation structure name --- src/include/86box/plat_dir.h | 6 +++--- src/win/win_opendir.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/86box/plat_dir.h b/src/include/86box/plat_dir.h index 948db8c84..b8280404c 100644 --- a/src/include/86box/plat_dir.h +++ b/src/include/86box/plat_dir.h @@ -25,7 +25,7 @@ # define MAXDIRLEN 127 -struct direct { +struct dirent { long d_ino; unsigned short d_reclen; unsigned short d_off; @@ -49,7 +49,7 @@ typedef struct { #else char dir[MAXDIRLEN+1]; /* open dir */ #endif - struct direct dent; /* actual directory entry */ + struct dirent dent; /* actual directory entry */ } DIR; @@ -65,7 +65,7 @@ extern DIR *opendirw(const wchar_t *); #else extern DIR *opendir(const char *); #endif -extern struct direct *readdir(DIR *); +extern struct dirent *readdir(DIR *); extern long telldir(DIR *); extern void seekdir(DIR *, long); extern int closedir(DIR *); diff --git a/src/win/win_opendir.c b/src/win/win_opendir.c index 1740140cc..d7755e372 100644 --- a/src/win/win_opendir.c +++ b/src/win/win_opendir.c @@ -124,7 +124,7 @@ closedir(DIR *p) * standard "." and ".." entries. Many applications do assume * this anyway, so we simply fake these entries. */ -struct direct * +struct dirent * readdir(DIR *p) { FINDATA *ffp; From 6ab6bcd7a3faff41012d394b2408f68cda0bfa1b Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 17 Apr 2021 20:17:49 -0300 Subject: [PATCH 4/5] Switch nvr file iteration code to the local dirent implementation --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 8a8512b64..363622c9c 100644 --- a/src/config.c +++ b/src/config.c @@ -32,7 +32,6 @@ #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -64,6 +63,7 @@ #include <86box/video.h> #include <86box/plat.h> #include <86box/plat_midi.h> +#include <86box/plat_dir.h> #include <86box/ui.h> From dfdfc7fd8e45c52f3a185830ed7627bfb22dfcd2 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 17 Apr 2021 21:04:31 -0300 Subject: [PATCH 5/5] Compile win_opendir on MSVC --- src/win/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/win/CMakeLists.txt b/src/win/CMakeLists.txt index 1588a4d7e..9f8bbea2b 100644 --- a/src/win/CMakeLists.txt +++ b/src/win/CMakeLists.txt @@ -28,6 +28,8 @@ if(MSVC) # file when using MSVC, so we might just as well do that! target_compile_definitions(ui PRIVATE NO_INCLUDE_MANIFEST) target_sources(86Box PRIVATE 86Box.manifest) + + target_sources(plat PRIVATE win_opendir.c) endif() if(DINPUT)