Replace CopyFileA with a cross-platform function (#20)
Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
This commit is contained in:
parent
6714aebbad
commit
23c0d3b873
|
@ -6,8 +6,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#include <filesystem>
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
// 0x452740
|
// 0x452740
|
||||||
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
|
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
|
||||||
|
@ -50,7 +49,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CopyFileA(existingFilePath, newFilePath, FALSE);
|
fileCopy(existingFilePath, newFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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
|
// Source file is already gzipped, there is no need to do anything
|
||||||
// besides copying.
|
// besides copying.
|
||||||
fclose(inStream);
|
fclose(inStream);
|
||||||
CopyFileA(existingFilePath, newFilePath, FALSE);
|
fileCopy(existingFilePath, newFilePath);
|
||||||
} else {
|
} else {
|
||||||
gzFile outStream = gzopen(newFilePath, "wb");
|
gzFile outStream = gzopen(newFilePath, "wb");
|
||||||
if (outStream == NULL) {
|
if (outStream == NULL) {
|
||||||
|
@ -136,8 +135,14 @@ int _gzdecompress_file(const char* existingFilePath, const char* newFilePath)
|
||||||
gzclose(gzstream);
|
gzclose(gzstream);
|
||||||
fclose(stream);
|
fclose(stream);
|
||||||
} else {
|
} else {
|
||||||
CopyFileA(existingFilePath, newFilePath, FALSE);
|
fileCopy(existingFilePath, newFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -4,5 +4,6 @@
|
||||||
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath);
|
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath);
|
||||||
int fileCopyCompressed(const char* existingFilePath, const char* newFilePath);
|
int fileCopyCompressed(const char* existingFilePath, const char* newFilePath);
|
||||||
int _gzdecompress_file(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 */
|
#endif /* FILE_UTILS_H */
|
||||||
|
|
Loading…
Reference in New Issue