Revert "Internal: not copying all lumps manually anymore on 'Save As'. The WAD is copied with File.Copy anyway."

This reverts commit ec90554cf4.
This commit is contained in:
spherallic 2023-05-30 16:49:57 +02:00
parent 27d53481fa
commit ab4126a39f
2 changed files with 48 additions and 29 deletions

View File

@ -948,21 +948,53 @@ namespace CodeImp.DoomBuilder
if(File.Exists(settingsfile)) File.Delete(settingsfile); if(File.Exists(settingsfile)) File.Delete(settingsfile);
} }
// [ZZ] We really want to tell apart saving into current archive from saving into a new one.
// Treat "save as" into the current archive as normal save.
bool isSaveAs = (purpose == SavePurpose.AsNewFile) && (newfilepathname != filepathname);
// On Save AS we have to copy the previous file to the new file // On Save AS we have to copy the previous file to the new file
if(isSaveAs) if((purpose == SavePurpose.AsNewFile) && (!String.IsNullOrEmpty(filepathname)))
{ {
// Copy if original file still exists // Copy if original file still exists
if(File.Exists(filepathname)) File.Copy(filepathname, newfilepathname, true); if(File.Exists(filepathname)) File.Copy(filepathname, newfilepathname, true);
} }
// If the target file exists, we need to rebuild it // If the target file exists, we need to rebuild it
// [ZZ] The original code here would do some weird trickery with tempfiles. if(File.Exists(newfilepathname))
// I'm just finding the map lumps and deleting them on later stages. {
// Move the target file aside
origwadfile = newfilepathname + ".temp";
File.Move(newfilepathname, origwadfile);
// Open original file
WAD origwad = new WAD(origwadfile, true);
// Create new target file
targetwad = new WAD(newfilepathname) { IsIWAD = origwad.IsIWAD }; //mxd. Let's preserve wad type
// Copy all lumps, except the original map
GameConfiguration origcfg; //mxd
if(origmapconfigname == configinfo.Filename)
{
origcfg = config;
}
else
{
ConfigurationInfo ci = General.GetConfigurationInfo(origmapconfigname);
origcfg = new GameConfiguration(ci.Configuration);
// Needed only once!
origmapconfigname = configinfo.Filename;
}
mapheaderindex = CopyAllLumpsExceptMap(origwad, targetwad, origcfg, origmapname);
// Close original file and delete it
origwad.Dispose();
File.Delete(origwadfile);
}
else
{
// Create new target file
targetwad = new WAD(newfilepathname); targetwad = new WAD(newfilepathname);
} }
}
catch(Exception e) catch(Exception e)
{ {
General.ShowErrorMessage("Unable to write the map to target file \"" + newfilepathname + "\":\n" + e.Message, MessageBoxButtons.OK); General.ShowErrorMessage("Unable to write the map to target file \"" + newfilepathname + "\":\n" + e.Message, MessageBoxButtons.OK);
@ -1561,7 +1593,6 @@ namespace CodeImp.DoomBuilder
} }
target.WriteHeaders(); //mxd target.WriteHeaders(); //mxd
target.Compress(); // [ZZ]
} }
} }

View File

@ -280,9 +280,6 @@ namespace CodeImp.DoomBuilder.IO
// This writes the WAD header and lumps table // This writes the WAD header and lumps table
public void WriteHeaders() public void WriteHeaders()
{ {
// [ZZ] don't allow any edit actions on readonly archive
if (isreadonly) return;
// Seek to beginning // Seek to beginning
file.Seek(0, SeekOrigin.Begin); file.Seek(0, SeekOrigin.Begin);
@ -372,9 +369,6 @@ namespace CodeImp.DoomBuilder.IO
public Lump Insert(string name, int position, int datalength) { return Insert(name, position, datalength, true); } //mxd public Lump Insert(string name, int position, int datalength) { return Insert(name, position, datalength, true); } //mxd
public Lump Insert(string name, int position, int datalength, bool writeheaders) public Lump Insert(string name, int position, int datalength, bool writeheaders)
{ {
// [ZZ] don't allow any edit actions on readonly archive
if (isreadonly) return null;
// We will be adding a lump // We will be adding a lump
numlumps++; numlumps++;
@ -398,9 +392,6 @@ namespace CodeImp.DoomBuilder.IO
// This removes a lump from the WAD file by index // This removes a lump from the WAD file by index
public void RemoveAt(int index) public void RemoveAt(int index)
{ {
// [ZZ] don't allow any edit actions on readonly archive
if (isreadonly) return;
// Remove from list // Remove from list
Lump l = lumps[index]; Lump l = lumps[index];
lumps.RemoveAt(index); lumps.RemoveAt(index);
@ -414,9 +405,6 @@ namespace CodeImp.DoomBuilder.IO
// This removes a lump from the WAD file // This removes a lump from the WAD file
public void Remove(Lump lump) public void Remove(Lump lump)
{ {
// [ZZ] don't allow any edit actions on readonly archive
if (isreadonly) return;
// Remove from list // Remove from list
lumps.Remove(lump); lumps.Remove(lump);
lump.Dispose(); lump.Dispose();