Skip to content

Commit 6d21911

Browse files
committed
Patching support for same source and target added.
1 parent f1594b7 commit 6d21911

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

LibIPS.NET/Patcher.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void PatchStudy(string patch, Studier.IpsStudy study, string source, stri
2222
public void PatchStudy(Stream patch, Studier.IpsStudy study, Stream source, Stream target)
2323
{
2424
source.CopyTo(target);
25+
long sourceLength = source.Length;
2526
if (study.Error == Studier.IpsError.IpsInvalid) throw new Exceptions.IpsInvalidException();
2627
int outlen = (int)Clamp(target.Length, study.OutlenMin, study.OutlenMax);
2728
// Set target file length to new size.
@@ -52,12 +53,12 @@ public void PatchStudy(Stream patch, Studier.IpsStudy study, Stream source, Stre
5253
}
5354
offset = Reader.Read24(patch);
5455
}
55-
if (study.OutlenMax != 0xFFFFFFFF && source.Length <= study.OutlenMax) throw new Exceptions.IpsNotThisException(); // Truncate data without this being needed is a poor idea.
56+
if (study.OutlenMax != 0xFFFFFFFF && sourceLength <= study.OutlenMax) throw new Exceptions.IpsNotThisException(); // Truncate data without this being needed is a poor idea.
5657
}
5758

5859
public void Patch(string patch, string source, string target)
5960
{
60-
using (FileStream patchStream = File.OpenRead(patch), sourceStream = File.OpenRead(source), targetStream = File.Open(target, FileMode.Create))
61+
using (FileStream patchStream = File.Open(patch, FileMode.Open, FileAccess.Read, FileShare.None), sourceStream = File.Open(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), targetStream = File.Open(target, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
6162
{
6263
Patch(patchStream, sourceStream, targetStream);
6364
}

0 commit comments

Comments
 (0)