Skip to content

Commit

Permalink
I had the thought it was broken but I think I fixed it?
Browse files Browse the repository at this point in the history
  • Loading branch information
BuilderDemo7 committed Jun 23, 2024
1 parent 215c05b commit 3f621b1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DSCript/Spooling/ChunkSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public bool Process(SpoolableResource<SpoolablePackage> resource)
throw new Exception("Cannot process an empty schema!");

var success = false;
var spooler = (SpoolablePackage)resource;
var spooler = resource.GetInterface().Spooler as SpoolablePackage;

if (spooler == null)
throw new Exception("Cannot process a schema on a spoolable resource that has an invalid spooler.");
Expand Down
6 changes: 0 additions & 6 deletions DSCript/Spooling/FileChunker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ private void ReadChunk(SpoolablePackage parent)
if (version != Chunk.Version)
throw new Exception("Unsupported version - cannot load chunk file!");

parent.SetSizeInternal(size);

DSC.Update($"Processing {count} chunks...");

for (int i = 0, idx = 1; i < count; i++, idx++)
Expand Down Expand Up @@ -496,10 +494,6 @@ public bool Save()
/// <returns>True if the chunker saved the file; otherwise, false.</returns>
public bool Save(string filename, bool updateStream = true)
{
// user requested an overwrite?
if (filename == FileName)
return Save();

if (CanSave)
{
OnFileSaveBegin();
Expand Down
2 changes: 1 addition & 1 deletion DSCript/Spooling/SpoolableBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public byte[] GetBuffer()
var localBuf = new byte[m_size];

// copy from existing buffer
Buffer.BlockCopy(m_buffer, 0, localBuf, 0, m_size);
Array.Copy(m_buffer, localBuf, m_size);

return localBuf;
}
Expand Down
42 changes: 19 additions & 23 deletions DSCript/Spooling/SpoolablePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,43 @@ public override int Size

if (count > 0)
{
// helps to recompute sizes when needed
int dirtyIndex = -1;

// Check if any of the spoolers are dirty or need calculating
for (int i = 0; i < count; i++)
// Check to see if the size needs to be (re)calculated
if (!IsDirty && _size > 0)
{
var s = Children[i];

if (s.AreChangesPending || (s.Offset == 0))
// Check if any of the spoolers are dirty
// If not, we'll use the existing size
for (int i = 0; i < count; i++)
{
dirtyIndex = i;
break;
var s = Children[i];

if (s.AreChangesPending)
{
dirtyIndex = i;
break;
}
}
}

if (dirtyIndex == -1)
else
{
// if we need to calculate the size,
// and assuming all of the children are valid,
// we can start calculating at the very end
if (IsDirty || (_size < size))
dirtyIndex = count;
// we need to calculate the size
dirtyIndex = 0;
}


// dirtyIndex is set when a dirty spooler is found (or if _size is not computed)
if (dirtyIndex > -1)
{
if (dirtyIndex > 0)
{
// use the spooler just before the dirty one
// in some cases, we use the very last one
// use the last clean spooler as a starting point (if applicable)
var cleanSpooler = Children[dirtyIndex - 1];

size = (cleanSpooler.Offset + cleanSpooler.Size + cleanSpooler.Description.Length);
}

// start at our dirty spooler and recalculate all spoolers onwards
// if all spoolers are clean, we won't waste any time ;)
for (int s = dirtyIndex; s < count; s++)
{
var spooler = Children[s];
Expand All @@ -129,11 +130,6 @@ public override int Size
}
}

internal void SetSizeInternal(int size)
{
_size = size;
}

public SpoolablePackage() { }
public SpoolablePackage(int size)
{
Expand Down
7 changes: 1 addition & 6 deletions DSCript/Spooling/SpoolableResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ void ISpoolableResource.Save()
this.VerifyAccess();
this.Save();
}

protected T Spooler { get; set; }

protected abstract void Load();
protected abstract void Save();

public static explicit operator T(SpoolableResource<T> resource)
{
return resource.Spooler;
}

internal void VerifyAccess()
{
if (Spooler == null)
Expand Down
2 changes: 1 addition & 1 deletion DSCript/Spooling/SpoolableResourceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static T Create<T>(Spooler spooler, bool loadSpooler)
}

public static void Load<T>(T resource)
where T : ISpoolableResource
where T : ISpoolableResource
{
resource.Load();
}
Expand Down

0 comments on commit 3f621b1

Please sign in to comment.