Add native Win32 version of the nvr directory iteration code for MSVC

This commit is contained in:
RichardG867
2021-04-17 20:02:37 -03:00
parent 0051a5fbe6
commit af22ff9e62
2 changed files with 24 additions and 5 deletions

View File

@@ -32,7 +32,11 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h> #include <wchar.h>
#ifdef _WIN32
# include <windows.h>
#else
# include <dirent.h> # include <dirent.h>
#endif
#define HAVE_STDARG_H #define HAVE_STDARG_H
#include <86box/86box.h> #include <86box/86box.h>
#include "cpu.h" #include "cpu.h"
@@ -621,21 +625,32 @@ load_machine(void)
i = strlen(new_fn); i = strlen(new_fn);
/* Iterate through NVR files. */ /* 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(".")); DIR *dirp = opendir(nvr_path("."));
if (dirp) { if (dirp) {
struct dirent *entry; struct dirent *entry;
while ((entry = readdir(dirp))) { while ((entry = readdir(dirp))) {
p = entry->d_name;
/* Check if this file corresponds to the old 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; continue;
#endif
/* Add extension to the new name. */ /* 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. */ /* Only copy if a file with the new name doesn't already exist. */
FILE *g = nvr_fopen(new_fn, "rb"); FILE *g = nvr_fopen(new_fn, "rb");
if (!g) { if (!g) {
FILE *f = nvr_fopen(entry->d_name, "rb"); FILE *f = nvr_fopen(p, "rb");
g = nvr_fopen(new_fn, "wb"); g = nvr_fopen(new_fn, "wb");
uint8_t buf[4096]; uint8_t buf[4096];
@@ -645,7 +660,11 @@ load_machine(void)
fclose(f); fclose(f);
} }
fclose(g); fclose(g);
#ifdef _WIN32
} while (FindNextFile(search, &find_data));
#else
} }
#endif
} }
} }

View File

@@ -259,6 +259,7 @@ g_strv_length(gchar **str_array)
#define g_rand_new() calloc(1, sizeof(GRand)) #define g_rand_new() calloc(1, sizeof(GRand))
#define g_return_val_if_fail(e, v) if (!(e)) return (v) #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_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_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_warn_if_reached() pclog("TinyGLib g_warn_if_reached()\n")
#define g_warning(s, ...) tinyglib_pclog("g_warning", s, ##__VA_ARGS__) #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_rand_free free
#define g_realloc realloc #define g_realloc realloc
#define g_snprintf snprintf #define g_snprintf snprintf
#define g_strdup(str) str ? strdup(str) : NULL
#define g_strerror strerror #define g_strerror strerror
#define g_strfreev free #define g_strfreev free
#define g_string_append_printf sprintf /* unimplemented */ #define g_string_append_printf sprintf /* unimplemented */