mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
Removed dynamic resource reloading for resource writing
This commit is contained in:
parent
8990cc57b0
commit
12fd006c61
7 changed files with 53 additions and 98 deletions
|
@ -164,41 +164,32 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
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))
|
||||
{
|
||||
if (reader.FileExists(source.Filename, source.LumpIndex))
|
||||
using (MemoryStream ms = reader.LoadFile(source.Filename, source.LumpIndex))
|
||||
{
|
||||
using (MemoryStream ms = reader.LoadFile(source.Filename, source.LumpIndex))
|
||||
if (MD5Hash.Get(ms) != hash
|
||||
&& MessageBox.Show("Target lump was modified by another application. Do you still want to replace it?", "Warning", MessageBoxButtons.OKCancel)
|
||||
== DialogResult.Cancel)
|
||||
{
|
||||
if (MD5Hash.Get(ms) != hash
|
||||
&& MessageBox.Show("Target lump was modified by another application. Do you still want to replace it?", "Warning", MessageBoxButtons.OKCancel)
|
||||
== DialogResult.Cancel)
|
||||
{
|
||||
dosave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dosave)
|
||||
{
|
||||
// Store the lump data
|
||||
using (MemoryStream stream = new MemoryStream(editor.GetText()))
|
||||
{
|
||||
if (reader.SaveFile(stream, source.Filename, source.LumpIndex))
|
||||
{
|
||||
// Update what must be updated
|
||||
hash = MD5Hash.Get(stream);
|
||||
editor.SetSavePoint();
|
||||
UpdateTitle();
|
||||
}
|
||||
dosave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
if (dosave)
|
||||
{
|
||||
reader.Reload(wasReadOnly);
|
||||
// Store the lump data
|
||||
using (MemoryStream stream = new MemoryStream(editor.GetText()))
|
||||
{
|
||||
if (reader.SaveFile(stream, source.Filename, source.LumpIndex))
|
||||
{
|
||||
// Update what must be updated
|
||||
hash = MD5Hash.Get(stream);
|
||||
editor.SetSavePoint();
|
||||
UpdateTitle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dosave;
|
||||
|
|
|
@ -874,7 +874,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
//mxd. Release PK3 files
|
||||
foreach (DataReader reader in containers)
|
||||
{
|
||||
if (reader is PK3Reader) (reader as PK3Reader).BathMode = false;
|
||||
if (reader is PK3Reader) (reader as PK3Reader).BatchMode = false;
|
||||
}
|
||||
|
||||
loadfinishtime = Clock.CurrentTime;
|
||||
|
|
|
@ -158,12 +158,6 @@ namespace CodeImp.DoomBuilder.Data
|
|||
isreadonly = wasreadonly;
|
||||
}
|
||||
|
||||
// This reloads the resource (possibly as readonly).
|
||||
public virtual void Reload(bool newreadonly)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Palette
|
||||
|
|
|
@ -39,13 +39,28 @@ namespace CodeImp.DoomBuilder.Data
|
|||
private IArchive archive; //mxd
|
||||
private /*readonly*/ ArchiveType archivetype; //mxd
|
||||
private /*readonly*/ Dictionary<string, byte[]> sevenzipentries; //mxd
|
||||
private bool bathmode = true; //mxd
|
||||
private bool batchmode = true; //mxd
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties (mxd)
|
||||
|
||||
public bool BathMode { get { return bathmode; } set { bathmode = value; UpdateArchive(bathmode); } }
|
||||
public bool BatchMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return batchmode;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (batchmode != value)
|
||||
{
|
||||
batchmode = value;
|
||||
UpdateArchive(batchmode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -147,7 +162,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
{
|
||||
archive = ArchiveFactory.Open(location.location);
|
||||
}
|
||||
else if(!enable && !bathmode && archive != null)
|
||||
else if(!enable && !batchmode && archive != null)
|
||||
{
|
||||
archive.Dispose();
|
||||
archive = null;
|
||||
|
@ -156,19 +171,6 @@ 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
|
||||
|
|
|
@ -85,20 +85,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
Stream lumpdata = General.Map.Data.GetSpriteData(Name, ref spritelocation);
|
||||
if(lumpdata != null)
|
||||
{
|
||||
// Copy lump data to memory
|
||||
byte[] membytes = new byte[(int)lumpdata.Length];
|
||||
|
||||
lock(lumpdata) //mxd
|
||||
{
|
||||
lumpdata.Seek(0, SeekOrigin.Begin);
|
||||
lumpdata.Read(membytes, 0, (int)lumpdata.Length);
|
||||
}
|
||||
|
||||
MemoryStream mem = new MemoryStream(membytes);
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get a reader for the data
|
||||
IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
|
||||
IImageReader reader = ImageDataFormat.GetImageReader(lumpdata, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
|
||||
if(reader is UnknownImageReader)
|
||||
{
|
||||
// Data is in an unknown format!
|
||||
|
@ -107,14 +95,14 @@ namespace CodeImp.DoomBuilder.Data
|
|||
}
|
||||
else
|
||||
{
|
||||
// Read data as bitmap
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
// Read data as bitmap
|
||||
lumpdata.Seek(0, SeekOrigin.Begin);
|
||||
if(bitmap != null) bitmap.Dispose();
|
||||
bitmap = reader.ReadAsBitmap(mem, out offsetx, out offsety);
|
||||
bitmap = reader.ReadAsBitmap(lumpdata, out offsetx, out offsety);
|
||||
}
|
||||
|
||||
// Done
|
||||
mem.Dispose();
|
||||
lumpdata.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -108,26 +108,14 @@ namespace CodeImp.DoomBuilder.Data
|
|||
Stream patchdata = General.Map.Data.GetPatchData(p.LumpName, p.HasLongName, ref patchlocation);
|
||||
if(patchdata != null)
|
||||
{
|
||||
// Copy patch data to memory
|
||||
byte[] membytes = new byte[(int)patchdata.Length];
|
||||
|
||||
lock(patchdata) //mxd
|
||||
{
|
||||
patchdata.Seek(0, SeekOrigin.Begin);
|
||||
patchdata.Read(membytes, 0, (int)patchdata.Length);
|
||||
}
|
||||
|
||||
MemoryStream mem = new MemoryStream(membytes);
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get a reader for the data
|
||||
IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
|
||||
IImageReader reader = ImageDataFormat.GetImageReader(patchdata, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
|
||||
if(reader is UnknownImageReader)
|
||||
{
|
||||
//mxd. Probably that's a flat?..
|
||||
if(General.Map.Config.MixTexturesFlats)
|
||||
{
|
||||
reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette);
|
||||
reader = ImageDataFormat.GetImageReader(patchdata, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette);
|
||||
}
|
||||
if(reader is UnknownImageReader)
|
||||
{
|
||||
|
@ -139,9 +127,9 @@ namespace CodeImp.DoomBuilder.Data
|
|||
|
||||
if(!(reader is UnknownImageReader))
|
||||
{
|
||||
// Draw the patch
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
try { reader.DrawToPixelData(mem, pixels, width, height, p.X, p.Y); }
|
||||
// Draw the patch
|
||||
patchdata.Seek(0, SeekOrigin.Begin);
|
||||
try { reader.DrawToPixelData(patchdata, pixels, width, height, p.X, p.Y); }
|
||||
catch(InvalidDataException)
|
||||
{
|
||||
// Data cannot be read!
|
||||
|
@ -150,8 +138,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
mem.Dispose();
|
||||
// Done
|
||||
patchdata.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -190,7 +190,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
General.WriteLogLine("Closing WAD resource \"" + location.location + "\"");
|
||||
|
||||
// Clean up
|
||||
file.Dispose();
|
||||
if (file != null)
|
||||
file.Dispose();
|
||||
|
||||
// Done
|
||||
base.Dispose();
|
||||
|
@ -218,17 +219,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// This resumes use of this resource
|
||||
public override void Resume()
|
||||
{
|
||||
Reload(IsReadOnly);
|
||||
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);
|
||||
file = new WAD(location.location, IsReadOnly);
|
||||
}
|
||||
|
||||
// This fills a ranges list
|
||||
|
|
Loading…
Reference in a new issue