Skip to content

Commit 73b6a16

Browse files
committed
Fix loading save game crash on Windows
1 parent 42376b7 commit 73b6a16

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/file_utils.cc

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <vector>
1212

13+
static void fileCopy(const char* existingFilePath, const char* newFilePath);
14+
1315
// 0x452740
1416
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
1517
{
@@ -51,7 +53,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
5153
return -1;
5254
}
5355
} else {
54-
fileCopy(existingFilePath, newFilePath, true);
56+
fileCopy(existingFilePath, newFilePath);
5557
}
5658

5759
return 0;
@@ -74,7 +76,7 @@ int fileCopyCompressed(const char* existingFilePath, const char* newFilePath)
7476
// Source file is already gzipped, there is no need to do anything
7577
// besides copying.
7678
fclose(inStream);
77-
fileCopy(existingFilePath, newFilePath, true);
79+
fileCopy(existingFilePath, newFilePath);
7880
} else {
7981
gzFile outStream = compat_gzopen(newFilePath, "wb");
8082
if (outStream == NULL) {
@@ -137,15 +139,13 @@ int _gzdecompress_file(const char* existingFilePath, const char* newFilePath)
137139
gzclose(gzstream);
138140
fclose(stream);
139141
} else {
140-
fileCopy(existingFilePath, newFilePath, true);
142+
fileCopy(existingFilePath, newFilePath);
141143
}
142144

143145
return 0;
144146
}
145147

146-
// Modelled as replacement for `CopyFileA`, but `overwrite` is the opposite to
147-
// `bFailIfExists` param. Update callers accordingly.
148-
void fileCopy(const char* existingFilePath, const char* newFilePath, bool overwrite)
148+
static void fileCopy(const char* existingFilePath, const char* newFilePath)
149149
{
150150
char nativeExistingFilePath[COMPAT_MAX_PATH];
151151
strcpy(nativeExistingFilePath, existingFilePath);
@@ -155,16 +155,8 @@ void fileCopy(const char* existingFilePath, const char* newFilePath, bool overwr
155155
strcpy(nativeNewFilePath, newFilePath);
156156
compat_windows_path_to_native(nativeNewFilePath);
157157

158-
char outMode[4];
159-
outMode[0] = 'w';
160-
outMode[1] = 'b';
161-
162-
if (!overwrite) {
163-
outMode[2] = 'x';
164-
}
165-
166158
FILE* in = fopen(nativeExistingFilePath, "rb");
167-
FILE* out = fopen(nativeNewFilePath, outMode);
159+
FILE* out = fopen(nativeNewFilePath, "wb");
168160
if (in != NULL && out != NULL) {
169161
std::vector<unsigned char> buffer(0xFFFF);
170162

src/file_utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath);
55
int fileCopyCompressed(const char* existingFilePath, const char* newFilePath);
66
int _gzdecompress_file(const char* existingFilePath, const char* newFilePath);
7-
void fileCopy(const char* existingFilePath, const char* newFilePath, bool overwrite);
87

98
#endif /* FILE_UTILS_H */

0 commit comments

Comments
 (0)