hactoolnet: Savefile fixes

Only open as writable if needed
Only commit if needed
This commit is contained in:
Alex Barney 2019-07-19 19:50:42 -05:00
parent 7b8c3f0b4f
commit b03973dc48

View file

@ -14,7 +14,15 @@ namespace hactoolnet
{
public static void Process(Context ctx)
{
using (var file = new LocalStorage(ctx.Options.InFile, FileAccess.ReadWrite))
FileAccess accessNeeded = FileAccess.Read;
if (ctx.Options.SignSave || ctx.Options.ReplaceFileDest != null && ctx.Options.ReplaceFileSource != null ||
ctx.Options.RepackSource != null || ctx.Options.TrimSave)
{
accessNeeded = FileAccess.ReadWrite;
}
using (var file = new LocalStorage(ctx.Options.InFile, accessNeeded))
{
bool signNeeded = ctx.Options.SignSave;
@ -85,8 +93,12 @@ namespace hactoolnet
}
}
finally
{
if (signNeeded)
{
save.Commit(ctx.Keyset);
signNeeded = false;
}
}
if (ctx.Options.TrimSave)