Fix loading save game crash on Windows
This commit is contained in:
parent
42376b7172
commit
73b6a16551
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
static void fileCopy(const char* existingFilePath, const char* newFilePath);
|
||||||
|
|
||||||
// 0x452740
|
// 0x452740
|
||||||
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
|
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +53,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fileCopy(existingFilePath, newFilePath, true);
|
fileCopy(existingFilePath, newFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -74,7 +76,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);
|
||||||
fileCopy(existingFilePath, newFilePath, true);
|
fileCopy(existingFilePath, newFilePath);
|
||||||
} else {
|
} else {
|
||||||
gzFile outStream = compat_gzopen(newFilePath, "wb");
|
gzFile outStream = compat_gzopen(newFilePath, "wb");
|
||||||
if (outStream == NULL) {
|
if (outStream == NULL) {
|
||||||
|
@ -137,15 +139,13 @@ int _gzdecompress_file(const char* existingFilePath, const char* newFilePath)
|
||||||
gzclose(gzstream);
|
gzclose(gzstream);
|
||||||
fclose(stream);
|
fclose(stream);
|
||||||
} else {
|
} else {
|
||||||
fileCopy(existingFilePath, newFilePath, true);
|
fileCopy(existingFilePath, newFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modelled as replacement for `CopyFileA`, but `overwrite` is the opposite to
|
static void fileCopy(const char* existingFilePath, const char* newFilePath)
|
||||||
// `bFailIfExists` param. Update callers accordingly.
|
|
||||||
void fileCopy(const char* existingFilePath, const char* newFilePath, bool overwrite)
|
|
||||||
{
|
{
|
||||||
char nativeExistingFilePath[COMPAT_MAX_PATH];
|
char nativeExistingFilePath[COMPAT_MAX_PATH];
|
||||||
strcpy(nativeExistingFilePath, existingFilePath);
|
strcpy(nativeExistingFilePath, existingFilePath);
|
||||||
|
@ -155,16 +155,8 @@ void fileCopy(const char* existingFilePath, const char* newFilePath, bool overwr
|
||||||
strcpy(nativeNewFilePath, newFilePath);
|
strcpy(nativeNewFilePath, newFilePath);
|
||||||
compat_windows_path_to_native(nativeNewFilePath);
|
compat_windows_path_to_native(nativeNewFilePath);
|
||||||
|
|
||||||
char outMode[4];
|
|
||||||
outMode[0] = 'w';
|
|
||||||
outMode[1] = 'b';
|
|
||||||
|
|
||||||
if (!overwrite) {
|
|
||||||
outMode[2] = 'x';
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* in = fopen(nativeExistingFilePath, "rb");
|
FILE* in = fopen(nativeExistingFilePath, "rb");
|
||||||
FILE* out = fopen(nativeNewFilePath, outMode);
|
FILE* out = fopen(nativeNewFilePath, "wb");
|
||||||
if (in != NULL && out != NULL) {
|
if (in != NULL && out != NULL) {
|
||||||
std::vector<unsigned char> buffer(0xFFFF);
|
std::vector<unsigned char> buffer(0xFFFF);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,5 @@
|
||||||
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, bool overwrite);
|
|
||||||
|
|
||||||
#endif /* FILE_UTILS_H */
|
#endif /* FILE_UTILS_H */
|
||||||
|
|
Loading…
Reference in New Issue