From e97b65c905e04a49b0c558bb64fdbc202f12acf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0imek?= Date: Fri, 27 May 2022 12:32:14 +0200 Subject: [PATCH] Replace CopyFileA with a cross-platform function --- src/art.h | 3 --- src/audio_file.cc | 3 --- src/file_utils.cc | 18 ++++++++++++------ src/file_utils.h | 1 + 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/art.h b/src/art.h index add05d5..bfcb557 100644 --- a/src/art.h +++ b/src/art.h @@ -7,9 +7,6 @@ #include "obj_types.h" #include "proto_types.h" -#define WIN32_LEAN_AND_MEAN -#include - typedef enum Head { HEAD_INVALID, HEAD_MARCUS, diff --git a/src/audio_file.cc b/src/audio_file.cc index c6fcca9..eb9dcdc 100644 --- a/src/audio_file.cc +++ b/src/audio_file.cc @@ -9,9 +9,6 @@ #include #include -#define WIN32_LEAN_AND_MEAN -#include - static_assert(sizeof(AudioFile) == 28, "wrong size"); // 0x5108C0 diff --git a/src/file_utils.cc b/src/file_utils.cc index 52bde9f..d96012b 100644 --- a/src/file_utils.cc +++ b/src/file_utils.cc @@ -6,9 +6,7 @@ #include #include #include - -#define WIN32_LEAN_AND_MEAN -#include +#include // 0x452740 int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath) @@ -51,7 +49,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath) return -1; } } else { - CopyFileA(existingFilePath, newFilePath, FALSE); + fileCopy(existingFilePath, newFilePath); } return 0; @@ -74,7 +72,7 @@ int fileCopyCompressed(const char* existingFilePath, const char* newFilePath) // Source file is already gzipped, there is no need to do anything // besides copying. fclose(inStream); - CopyFileA(existingFilePath, newFilePath, FALSE); + fileCopy(existingFilePath, newFilePath); } else { gzFile outStream = gzopen(newFilePath, "wb"); if (outStream == NULL) { @@ -137,8 +135,16 @@ int _gzdecompress_file(const char* existingFilePath, const char* newFilePath) gzclose(gzstream); fclose(stream); } else { - CopyFileA(existingFilePath, newFilePath, FALSE); + fileCopy(existingFilePath, newFilePath); } return 0; } + +void fileCopy(const char* existingFilePath, const char* newFilePath) +{ + std::ifstream source { existingFilePath, std::ios::binary }; + std::ofstream destination { newFilePath, std::ios::binary }; + + destination << source.rdbuf(); +} diff --git a/src/file_utils.h b/src/file_utils.h index 10f626a..fd886f7 100644 --- a/src/file_utils.h +++ b/src/file_utils.h @@ -4,5 +4,6 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath); int fileCopyCompressed(const char* existingFilePath, const char* newFilePath); int _gzdecompress_file(const char* existingFilePath, const char* newFilePath); +void fileCopy(const char* existingFilePath, const char* newFilePath); #endif /* FILE_UTILS_H */