Replace CopyFileA with a cross-platform function (#20)

Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
This commit is contained in:
Jan Šimek 2022-05-28 09:38:16 +02:00 committed by GitHub
parent 6714aebbad
commit 23c0d3b873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -6,8 +6,7 @@
#include <stdio.h>
#include <zlib.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <filesystem>
// 0x452740
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
@ -50,7 +49,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
return -1;
}
} else {
CopyFileA(existingFilePath, newFilePath, FALSE);
fileCopy(existingFilePath, newFilePath);
}
return 0;
@ -73,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) {
@ -136,8 +135,14 @@ 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::error_code ec;
std::filesystem::copy_file(std::filesystem::path(existingFilePath), std::filesystem::path(newFilePath), ec);
}

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