Skip to content

Commit

Permalink
Fixed (hopefully) ZDBSP file renaming issue on Windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jul 28, 2021
1 parent c4f748d commit 3cc8f95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
42 changes: 10 additions & 32 deletions source_files/zdbsp_src/zdmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,6 @@ int zdmain(const char *filename, zdbsp_options options) {
// a temporary file. After everything is done, the input file is
// deleted and the output file is renamed to match the input file.

char *out = new char[strlen(OutName) + 3], *dot;

if (out == NULL) {
throw std::runtime_error(
"Could not create temporary file name.");
}

strcpy(out, OutName);
dot = strrchr(out, '.');
if (dot && (dot[1] == 'w' || dot[1] == 'W') &&
(dot[2] == 'a' || dot[2] == 'A') &&
(dot[3] == 'd' || dot[3] == 'D') && dot[4] == 0) {
// *.wad becomes *.daw
dot[1] = 'd';
dot[3] = 'w';
} else {
// * becomes *.x
strcat(out, ".x");
}
OutName = out;
fixSame = true;

FWadReader inwad(InName);
FWadWriter outwad(OutName, inwad.IsIWAD());

Expand Down Expand Up @@ -182,16 +160,16 @@ int zdmain(const char *filename, zdbsp_options options) {
}
}

outwad.Close();

if (fixSame) {
remove(InName);
if (0 != rename(OutName, InName)) {
printf(
"The output file could not be renamed to %s.\nYou can find "
"it as %s.\n",
InName, OutName);
}
outwad.Close();
inwad.Close();
remove(InName);

if (0 != rename(OutName, InName)) {
printf(
"The output file could not be renamed to %s.\nYou can find "
"it as %s.\n",
InName, OutName);
return 20;
}

END_COUNTER(t1a, t1b, t1c, "\nTotal time: %.3f seconds.\n")
Expand Down
5 changes: 5 additions & 0 deletions source_files/zdbsp_src/zdwad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ FWadReader::FWadReader(const char *filename) : Lumps(NULL), File(NULL) {
}
}

void FWadReader::Close() {
if (File) fclose(File);
if (Lumps) delete[] Lumps;
}

FWadReader::~FWadReader() {
if (File) fclose(File);
if (Lumps) delete[] Lumps;
Expand Down
1 change: 1 addition & 0 deletions source_files/zdbsp_src/zdwad.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FWadReader {
int NextMap(int startindex) const;
int LumpAfterMap(int map) const;
int NumLumps() const;
void Close();

void SafeRead(void *buffer, size_t size);

Expand Down

0 comments on commit 3cc8f95

Please sign in to comment.