Skip to content

Commit

Permalink
Fixed empty subfile bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bbepis committed May 22, 2016
1 parent 07dfa59 commit ddb30db
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
3 changes: 3 additions & 0 deletions AA2Install/formMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public partial class formMain : Form
#warning replace 7z handling, reload mod metadata everytime it's selected
#warning investigate filter issues
#warning display which .pps are going to get changed
#warning add the ability to cancel during an install by uninstalling using the temp folder
#warning check 7z integrity before un/install
#warning run tests on .pp files before un/install


#region Preferences
Expand Down
17 changes: 9 additions & 8 deletions SB3UtilityPP/MemSubFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ public MemSubfile(byte[] data, string name)
public void WriteTo(Stream stream)
{
using (BinaryReader reader = new BinaryReader(CreateReadStream()))
{
BinaryWriter writer = new BinaryWriter(stream);
byte[] buf;
int bufsize = Utility.EstBufSize(reader.BaseStream.Length);
while ((buf = reader.ReadBytes(bufsize)).Length == bufsize)
{
if (reader.BaseStream.Length > 0)
{
BinaryWriter writer = new BinaryWriter(stream);
byte[] buf;
int bufsize = Utility.EstBufSize(reader.BaseStream.Length);
while ((buf = reader.ReadBytes(bufsize)).Length == bufsize)
{
writer.Write(buf);
}
writer.Write(buf);
}
writer.Write(buf);
}
}

public Stream CreateReadStream()
Expand Down
1 change: 1 addition & 0 deletions SB3UtilityPP/Subfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Subfile(string filepath)
public void WriteTo(Stream stream)
{
using (BinaryReader reader = new BinaryReader(CreateReadStream()))
if (reader.BaseStream.Length > 0)
{
BinaryWriter writer = new BinaryWriter(stream);
byte[] buf;
Expand Down
41 changes: 25 additions & 16 deletions SB3UtilityPP/ppParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void writeArchiveWorker_DoWork(object sender, DoWorkEventArgs e)

worker.ReportProgress(i * 100 / Subfiles.Count);

System.Diagnostics.Trace.WriteLine(Subfiles[i].Name);

ppSubfile subfile = Subfiles[i] as ppSubfile;
if ((subfile != null) && (subfile.ppFormat == this.Format))
{
Expand All @@ -119,28 +121,35 @@ void writeArchiveWorker_DoWork(object sender, DoWorkEventArgs e)

int bufsize = Utility.EstBufSize(subfile.size);

uint readSteps = subfile.size / (uint)bufsize;

byte[] buf;
uint hash = 0;

for (int j = 0; j < readSteps; j++)
if (bufsize > 0)
{
buf = reader.ReadBytes(bufsize);
uint readSteps = subfile.size / (uint)bufsize;

if (enableRLE)
md5.TransformBlock(buf, 0, bufsize, buf, 0);

byte[] buf;

for (int j = 0; j < readSteps; j++)
{
buf = reader.ReadBytes(bufsize);

if (enableRLE)
md5.TransformBlock(buf, 0, bufsize, buf, 0);

mem.WriteBytes(buf);
}
int remaining = (int)(subfile.size % bufsize);

buf = reader.ReadBytes(remaining);
mem.WriteBytes(buf);
}
int remaining = (int)(subfile.size % bufsize);

buf = reader.ReadBytes(remaining);
mem.WriteBytes(buf);
md5.TransformFinalBlock(buf, 0, remaining);
hash = BitConverter.ToUInt32(md5.Hash, 0);
}

if (enableRLE)
{
md5.TransformFinalBlock(buf, 0, remaining);
uint hash = BitConverter.ToUInt32(md5.Hash, 0);


if (!Hashes.Any(x => x.Item2 == hash))
{
Expand Down Expand Up @@ -264,10 +273,10 @@ void writeArchiveWorker_DoWork(object sender, DoWorkEventArgs e)
if (iw is IDisposable)
((IDisposable)iw).Dispose();
}
catch (Exception)
catch (Exception ex)
{
RestoreBackup(destPath, backup);
throw;
throw new Exception("PP Parser has encountered an error.", ex);
}
}

Expand Down

0 comments on commit ddb30db

Please sign in to comment.