mirror of
https://github.com/alexbatalov/fallout2-ce.git
synced 2024-11-01 23:26:57 +00:00
Add overwrite param (#20)
This commit is contained in:
parent
23c0d3b873
commit
e1cf71eac7
@ -49,7 +49,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
fileCopy(existingFilePath, newFilePath);
|
||||
fileCopy(existingFilePath, newFilePath, true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -72,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);
|
||||
fileCopy(existingFilePath, newFilePath);
|
||||
fileCopy(existingFilePath, newFilePath, true);
|
||||
} else {
|
||||
gzFile outStream = gzopen(newFilePath, "wb");
|
||||
if (outStream == NULL) {
|
||||
@ -135,14 +135,19 @@ int _gzdecompress_file(const char* existingFilePath, const char* newFilePath)
|
||||
gzclose(gzstream);
|
||||
fclose(stream);
|
||||
} else {
|
||||
fileCopy(existingFilePath, newFilePath);
|
||||
fileCopy(existingFilePath, newFilePath, true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fileCopy(const char* existingFilePath, const char* newFilePath)
|
||||
// Modelled as replacement for `CopyFileA`, but `overwrite` is the opposite to
|
||||
// `bFailIfExists` param. Update callers accordingly.
|
||||
void fileCopy(const char* existingFilePath, const char* newFilePath, bool overwrite)
|
||||
{
|
||||
std::error_code ec;
|
||||
std::filesystem::copy_file(std::filesystem::path(existingFilePath), std::filesystem::path(newFilePath), ec);
|
||||
std::filesystem::copy_options options = overwrite
|
||||
? std::filesystem::copy_options::overwrite_existing
|
||||
: std::filesystem::copy_options::none;
|
||||
std::filesystem::copy_file(std::filesystem::path(existingFilePath), std::filesystem::path(newFilePath), options, ec);
|
||||
}
|
||||
|
@ -4,6 +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);
|
||||
void fileCopy(const char* existingFilePath, const char* newFilePath, bool overwrite);
|
||||
|
||||
#endif /* FILE_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user