Fixed: lump saving in script editor after editing archive with SLADE.\n Fixed: checking for concurrent modification in script editor while trying to save the lump.

This commit is contained in:
ZZYZX 2017-01-21 03:13:36 +02:00
parent a705e47fb9
commit a5a942c798
8 changed files with 164 additions and 110 deletions

View file

@ -98,6 +98,11 @@ namespace CodeImp.DoomBuilder.Controls
// Find lump, check it's hash
bool dosave = true;
DataReader reader = source.Resource;
// reload the reader
bool wasReadOnly = reader.IsReadOnly;
reader.Reload(false);
try
{
if (reader.FileExists(source.Filename, source.LumpIndex))
{
using (MemoryStream ms = reader.LoadFile(source.Filename, source.LumpIndex))
@ -124,6 +129,11 @@ namespace CodeImp.DoomBuilder.Controls
UpdateTitle();
}
}
}
}
finally
{
reader.Reload(wasReadOnly);
}
return dosave;

View file

@ -141,13 +141,25 @@ namespace CodeImp.DoomBuilder.Data
// This suspends use of this resource
public virtual void Suspend()
{
// [ZZ] validate
if (issuspended) throw new Exception("Tried to suspend already suspended resource!");
issuspended = true;
isreadonly = true;
}
// This resumes use of this resource
public virtual void Resume()
{
// [ZZ] validate
if (!issuspended) throw new Exception("Tried to resume already resumed resource!");
issuspended = false;
isreadonly = false;
}
// This reloads the resource (possibly as readonly).
public virtual void Reload(bool newreadonly)
{
}
#endregion

View file

@ -35,10 +35,10 @@ namespace CodeImp.DoomBuilder.Data
{
#region ================== Variables
private readonly DirectoryFilesList files;
private /*readonly*/ DirectoryFilesList files;
private IArchive archive; //mxd
private readonly ArchiveType archivetype; //mxd
private readonly Dictionary<string, byte[]> sevenzipentries; //mxd
private /*readonly*/ ArchiveType archivetype; //mxd
private /*readonly*/ Dictionary<string, byte[]> sevenzipentries; //mxd
private bool bathmode = true; //mxd
#endregion
@ -53,6 +53,11 @@ namespace CodeImp.DoomBuilder.Data
// Constructor
public PK3Reader(DataLocation dl, bool asreadonly) : base(dl, asreadonly)
{
LoadFrom(dl, asreadonly);
}
private void LoadFrom(DataLocation dl, bool asreadonly)
{
General.WriteLogLine("Opening " + Path.GetExtension(location.location).ToUpper().Replace(".", "") + " resource \"" + location.location + "\"");
@ -151,6 +156,19 @@ namespace CodeImp.DoomBuilder.Data
#endregion
#region ================== Management
// [ZZ]
// This reloads the resource
public override void Reload(bool newreadonly)
{
if (archive != null)
archive.Dispose();
LoadFrom(location, newreadonly);
}
#endregion
#region ================== Textures
// This finds and returns a patch stream

View file

@ -72,6 +72,8 @@ namespace CodeImp.DoomBuilder.Data
// Call this to initialize this class
protected virtual void Initialize()
{
// [ZZ] we can have wad files already. dispose if any.
if (wads != null) foreach (WADReader wr in wads) wr.Dispose();
// Load all WAD files in the root as WAD resources
string[] wadfiles = GetWadFiles();
wads = new List<WADReader>(wadfiles.Length);

View file

@ -211,17 +211,26 @@ namespace CodeImp.DoomBuilder.Data
public override void Suspend()
{
file.Dispose();
file = null;
base.Suspend();
}
// This resumes use of this resource
public override void Resume()
{
file = new WAD(location.location, true);
is_iwad = file.IsIWAD;
Reload(true);
base.Resume();
}
// This reloads the resource
public override void Reload(bool newreadonly)
{
if (file != null) file.Dispose();
file = new WAD(location.location, newreadonly);
is_iwad = file.IsIWAD;
base.Reload(newreadonly);
}
// This fills a ranges list
private void FindRanges(List<LumpRange> ranges, IDictionary rangeinfos, string rangename, string elementname)
{

View file

@ -30,6 +30,6 @@ using CodeImp.DoomBuilder;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.3.0.2837")]
[assembly: AssemblyVersion("2.3.0.2839")]
[assembly: NeutralResourcesLanguageAttribute("en")]
[assembly: AssemblyHash("30a5edf")]
[assembly: AssemblyHash("a705e47")]

View file

@ -212,6 +212,9 @@ namespace CodeImp.DoomBuilder.Windows
}
}
// [ZZ] dispose of wadfile
wadfile.Dispose();
//mxd. Bail out if still no dice...
if (config.SelectedIndex == -1 || mapslist.Items.Count == 0)
{

View file

@ -29,5 +29,5 @@ using System.Resources;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.3.0.2837")]
[assembly: AssemblyVersion("2.3.0.2839")]
[assembly: NeutralResourcesLanguageAttribute("en")]