mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
hactoolnet: Add an option to replace a file in save data
This commit is contained in:
parent
9e3c41ed2c
commit
1b3a0363ce
3 changed files with 45 additions and 1 deletions
|
@ -50,6 +50,12 @@ namespace hactoolnet
|
||||||
new CliOption("sign", 0, (o, a) => o.SignSave = true),
|
new CliOption("sign", 0, (o, a) => o.SignSave = true),
|
||||||
new CliOption("title", 1, (o, a) => o.TitleId = ParseTitleId(a[0])),
|
new CliOption("title", 1, (o, a) => o.TitleId = ParseTitleId(a[0])),
|
||||||
new CliOption("bench", 1, (o, a) => o.BenchType = a[0]),
|
new CliOption("bench", 1, (o, a) => o.BenchType = a[0]),
|
||||||
|
|
||||||
|
new CliOption("replacefile", 2, (o, a) =>
|
||||||
|
{
|
||||||
|
o.ReplaceFileDest = a[0];
|
||||||
|
o.ReplaceFileSource = a[1];
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Options Parse(string[] args)
|
public static Options Parse(string[] args)
|
||||||
|
@ -204,11 +210,12 @@ namespace hactoolnet
|
||||||
sb.AppendLine(" --romfsdir <dir> Specify RomFS directory path. (--title must be specified)");
|
sb.AppendLine(" --romfsdir <dir> Specify RomFS directory path. (--title must be specified)");
|
||||||
sb.AppendLine(" --savedir <dir> Specify save file directory path.");
|
sb.AppendLine(" --savedir <dir> Specify save file directory path.");
|
||||||
sb.AppendLine(" -y, --verify Verify all titles, or verify a single title if --title is set.");
|
sb.AppendLine(" -y, --verify Verify all titles, or verify a single title if --title is set.");
|
||||||
sb.AppendLine("Savefile options:");
|
sb.AppendLine("Save data options:");
|
||||||
sb.AppendLine(" --outdir <dir> Specify directory path to save contents to.");
|
sb.AppendLine(" --outdir <dir> Specify directory path to save contents to.");
|
||||||
sb.AppendLine(" --debugoutdir <dir> Specify directory path to save intermediate data to for debugging.");
|
sb.AppendLine(" --debugoutdir <dir> Specify directory path to save intermediate data to for debugging.");
|
||||||
sb.AppendLine(" --sign Sign the save file. (Requires device_key in key file)");
|
sb.AppendLine(" --sign Sign the save file. (Requires device_key in key file)");
|
||||||
sb.AppendLine(" --listfiles List files in save file.");
|
sb.AppendLine(" --listfiles List files in save file.");
|
||||||
|
sb.AppendLine(" --replacefile <filename in save> <file> Replaces a file in the save data");
|
||||||
sb.AppendLine("Keygen options:");
|
sb.AppendLine("Keygen options:");
|
||||||
sb.AppendLine(" --outdir <dir> Specify directory path to save key files to.");
|
sb.AppendLine(" --outdir <dir> Specify directory path to save key files to.");
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ namespace hactoolnet
|
||||||
public string NormalDir;
|
public string NormalDir;
|
||||||
public string SecureDir;
|
public string SecureDir;
|
||||||
public string LogoDir;
|
public string LogoDir;
|
||||||
|
public string ReplaceFileSource;
|
||||||
|
public string ReplaceFileDest;
|
||||||
public bool ListApps;
|
public bool ListApps;
|
||||||
public bool ListTitles;
|
public bool ListTitles;
|
||||||
public bool ListNcas;
|
public bool ListNcas;
|
||||||
|
|
|
@ -94,6 +94,39 @@ namespace hactoolnet
|
||||||
duplexDataB.WriteAllBytes(Path.Combine(duplexDir, "DataB"), ctx.Logger);
|
duplexDataB.WriteAllBytes(Path.Combine(duplexDir, "DataB"), ctx.Logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx.Options.ReplaceFileDest != null && ctx.Options.ReplaceFileSource != null)
|
||||||
|
{
|
||||||
|
string destFilename = ctx.Options.ReplaceFileDest;
|
||||||
|
if (!destFilename.StartsWith("/")) destFilename = '/' + destFilename;
|
||||||
|
|
||||||
|
using (IStorage inFile = new FileStream(ctx.Options.ReplaceFileSource, FileMode.Open, FileAccess.Read).AsStorage(false))
|
||||||
|
{
|
||||||
|
using (IStorage outFile = save.OpenFile(destFilename))
|
||||||
|
{
|
||||||
|
if (inFile.Length != outFile.Length)
|
||||||
|
{
|
||||||
|
ctx.Logger.LogMessage($"Replacement file must be the same size as the original file. ({outFile.Length} bytes)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inFile.CopyTo(outFile, ctx.Logger);
|
||||||
|
|
||||||
|
ctx.Logger.LogMessage($"Replaced file {destFilename}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (save.CommitHeader(ctx.Keyset))
|
||||||
|
{
|
||||||
|
ctx.Logger.LogMessage("Successfully signed save file");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ctx.Logger.LogMessage("ERROR: Unable to sign save file. Do you have all the required keys?");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx.Options.SignSave)
|
if (ctx.Options.SignSave)
|
||||||
{
|
{
|
||||||
if (save.CommitHeader(ctx.Keyset))
|
if (save.CommitHeader(ctx.Keyset))
|
||||||
|
@ -104,6 +137,8 @@ namespace hactoolnet
|
||||||
{
|
{
|
||||||
ctx.Logger.LogMessage("Unable to sign save file. Do you have all the required keys?");
|
ctx.Logger.LogMessage("Unable to sign save file. Do you have all the required keys?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.Options.ListFiles)
|
if (ctx.Options.ListFiles)
|
||||||
|
|
Loading…
Reference in a new issue