Replace CopyFileA with a cross-platform function

This commit is contained in:
Jan Šimek 2022-05-27 12:32:14 +02:00
parent b467198f16
commit e97b65c905
4 changed files with 13 additions and 12 deletions

View File

@ -7,9 +7,6 @@
#include "obj_types.h"
#include "proto_types.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef enum Head {
HEAD_INVALID,
HEAD_MARCUS,

View File

@ -9,9 +9,6 @@
#include <stdio.h>
#include <string.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
static_assert(sizeof(AudioFile) == 28, "wrong size");
// 0x5108C0

View File

@ -6,9 +6,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <zlib.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <fstream>
// 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();
}

View File

@ -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 */