- Added some error handling for invalid wad files

- Fixed bug that allowed pasting geometry in visual mode (and the geometry becomes erroneous)
This commit is contained in:
codeimp 2009-07-10 08:25:04 +00:00
parent 5b58693a71
commit 89f8b3542e
6 changed files with 93 additions and 32 deletions

View file

@ -179,8 +179,8 @@ namespace CodeImp.DoomBuilder.Editing
// Called when the marked geometry has been copied.
public virtual void OnCopyEnd() { }
// Called before pasting. Return false when paste should be cancelled.
public virtual bool OnPasteBegin(PasteOptions options) { return true; }
// Called before pasting. Override this and return true to indicate that paste is allowed to contiue.
public virtual bool OnPasteBegin(PasteOptions options) { return false; }
// Called after new geometry has been pasted in. The new geometry is marked.
public virtual void OnPasteEnd(PasteOptions options) { }

View file

@ -252,7 +252,16 @@ namespace CodeImp.DoomBuilder
// Create temp wadfile
tempfile = General.MakeTempFilename(temppath);
General.WriteLogLine("Creating temporary file: " + tempfile);
#if DEBUG
tempwad = new WAD(tempfile);
#else
try { tempwad = new WAD(tempfile); }
catch(Exception e)
{
General.ShowErrorMessage("Error while creating a temporary wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK);
return false;
}
#endif
// Read the map from temp file
General.WriteLogLine("Initializing map format interface " + config.FormatInterface + "...");
@ -329,11 +338,29 @@ namespace CodeImp.DoomBuilder
// Create temp wadfile
tempfile = General.MakeTempFilename(temppath);
General.WriteLogLine("Creating temporary file: " + tempfile);
#if DEBUG
tempwad = new WAD(tempfile);
#else
try { tempwad = new WAD(tempfile); }
catch(Exception e)
{
General.ShowErrorMessage("Error while creating a temporary wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK);
return false;
}
#endif
// Now open the map file
General.WriteLogLine("Opening source file: " + filepathname);
#if DEBUG
mapwad = new WAD(filepathname, true);
#else
try { mapwad = new WAD(filepathname, true); }
catch(Exception e)
{
General.ShowErrorMessage("Error while opening source wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK);
return false;
}
#endif
// Copy the map lumps to the temp file
General.WriteLogLine("Copying map lumps to temporary file...");
@ -678,7 +705,16 @@ namespace CodeImp.DoomBuilder
// Make the temporary WAD file
General.WriteLogLine("Creating temporary build file: " + tempfile1);
#if DEBUG
buildwad = new WAD(tempfile1);
#else
try { buildwad = new WAD(tempfile1); }
catch(Exception e)
{
General.ShowErrorMessage("Error while creating a temporary wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK);
return false;
}
#endif
// Determine source file
if(filepathname.Length > 0)
@ -715,10 +751,19 @@ namespace CodeImp.DoomBuilder
if(compiler.Run())
{
// Open the output file
buildwad = new WAD(tempfile2);
try { buildwad = new WAD(tempfile2); }
catch(Exception e)
{
General.WriteLogLine(e.GetType().Name + " while reading build wad file: " + e.Message);
buildwad = null;
}
if(buildwad != null)
{
// Output lumps complete?
lumpscomplete = VerifyNodebuilderLumps(buildwad, BUILD_MAP_HEADER);
}
if(lumpscomplete)
{
// Copy nodebuilder lumps to temp file
@ -735,7 +780,7 @@ namespace CodeImp.DoomBuilder
}
// Done with the build wad
buildwad.Dispose();
if(buildwad != null) buildwad.Dispose();
}
// Clean up

View file

@ -196,9 +196,11 @@ namespace CodeImp.DoomBuilder.IO
// Number of lumps
numlumps = reader.ReadInt32();
if(numlumps < 0) throw new IOException("Invalid number of lumps in wad file.");
// Lumps table offset
lumpsoffset = reader.ReadInt32();
if(lumpsoffset < 0) throw new IOException("Invalid lumps offset in wad file.");
// Seek to the lumps table
file.Seek(lumpsoffset, SeekOrigin.Begin);

View file

@ -2488,6 +2488,8 @@ namespace CodeImp.DoomBuilder.Map
public List<int> GetMultipleNewTags(int count)
{
List<int> newtags = new List<int>(count);
if(count > 0)
{
Dictionary<int, bool> usedtags = new Dictionary<int, bool>();
ForAllTags(NewTagHandler, false, usedtags);
ForAllTags(NewTagHandler, true, usedtags);
@ -2501,6 +2503,7 @@ namespace CodeImp.DoomBuilder.Map
if(newtags.Count == count) break;
}
}
}
return newtags;
}
@ -2509,6 +2512,8 @@ namespace CodeImp.DoomBuilder.Map
public List<int> GetMultipleNewTags(int count, bool marked)
{
List<int> newtags = new List<int>(count);
if(count > 0)
{
Dictionary<int, bool> usedtags = new Dictionary<int, bool>();
ForAllTags(NewTagHandler, marked, usedtags);
@ -2521,6 +2526,7 @@ namespace CodeImp.DoomBuilder.Map
if(newtags.Count == count) break;
}
}
}
return newtags;
}

View file

@ -92,6 +92,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
(General.Map.Map.GetMarkedThings(true).Count > 0);
}
// This is called when pasting begins
public override bool OnPasteBegin(PasteOptions options)
{
// These modes support pasting
return true;
}
// This is called when something was pasted.
public override void OnPasteEnd(PasteOptions options)
{

View file

@ -32,6 +32,7 @@ using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.VisualModes;
using CodeImp.DoomBuilder.Config;
#endregion