mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Apply var style
This commit is contained in:
parent
c1c4c6ad46
commit
9875880e32
6 changed files with 37 additions and 37 deletions
|
@ -43,7 +43,7 @@ namespace Net
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var option = CliOptions.FirstOrDefault(x => x.Long == arg || x.Short == arg);
|
CliOption option = CliOptions.FirstOrDefault(x => x.Long == arg || x.Short == arg);
|
||||||
if (option == null)
|
if (option == null)
|
||||||
{
|
{
|
||||||
PrintWithUsage($"Unknown option {args[i]}");
|
PrintWithUsage($"Unknown option {args[i]}");
|
||||||
|
@ -74,7 +74,7 @@ namespace Net
|
||||||
PrintWithUsage("Title ID must be 16 hex characters long");
|
PrintWithUsage("Title ID must be 16 hex characters long");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ulong.TryParse(input, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var id))
|
if (!ulong.TryParse(input, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong id))
|
||||||
{
|
{
|
||||||
PrintWithUsage("Could not parse title ID");
|
PrintWithUsage("Could not parse title ID");
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ namespace Net
|
||||||
|
|
||||||
private static int ParseVersion(string input)
|
private static int ParseVersion(string input)
|
||||||
{
|
{
|
||||||
if (!int.TryParse(input, out var version))
|
if (!int.TryParse(input, out int version))
|
||||||
{
|
{
|
||||||
PrintWithUsage("Could not parse version");
|
PrintWithUsage("Could not parse version");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Net
|
||||||
|
|
||||||
public static Database Deserialize(string filename)
|
public static Database Deserialize(string filename)
|
||||||
{
|
{
|
||||||
var text = File.ReadAllText(filename);
|
string text = File.ReadAllText(filename);
|
||||||
return JsonConvert.DeserializeObject<Database>(text);
|
return JsonConvert.DeserializeObject<Database>(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace Net
|
||||||
{
|
{
|
||||||
public static VersionList ReadVersionList(string filename)
|
public static VersionList ReadVersionList(string filename)
|
||||||
{
|
{
|
||||||
var text = File.ReadAllText(filename);
|
string text = File.ReadAllText(filename);
|
||||||
var versionList = JsonConvert.DeserializeObject<VersionList>(text);
|
var versionList = JsonConvert.DeserializeObject<VersionList>(text);
|
||||||
return versionList;
|
return versionList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,4 @@
|
||||||
<ProjectReference Include="..\libhac\libhac.csproj" />
|
<ProjectReference Include="..\libhac\libhac.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
|
@ -41,7 +41,7 @@ namespace Net
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(CachePath);
|
Directory.CreateDirectory(CachePath);
|
||||||
var databaseFile = Path.Combine(CachePath, "database.json");
|
string databaseFile = Path.Combine(CachePath, "database.json");
|
||||||
if (!File.Exists(databaseFile))
|
if (!File.Exists(databaseFile))
|
||||||
{
|
{
|
||||||
File.WriteAllText(databaseFile, new Database().Serialize());
|
File.WriteAllText(databaseFile, new Database().Serialize());
|
||||||
|
@ -51,7 +51,7 @@ namespace Net
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
var databaseFile = Path.Combine(CachePath, "database.json");
|
string databaseFile = Path.Combine(CachePath, "database.json");
|
||||||
|
|
||||||
File.WriteAllText(databaseFile, Db.Serialize());
|
File.WriteAllText(databaseFile, Db.Serialize());
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ namespace Net
|
||||||
|
|
||||||
public Cnmt GetCnmt(ulong titleId, int version)
|
public Cnmt GetCnmt(ulong titleId, int version)
|
||||||
{
|
{
|
||||||
using (var stream = GetCnmtFile(titleId, version))
|
using (IStorage stream = GetCnmtFile(titleId, version))
|
||||||
{
|
{
|
||||||
if (stream == null) return null;
|
if (stream == null) return null;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ namespace Net
|
||||||
|
|
||||||
public IStorage GetCnmtFile(ulong titleId, int version)
|
public IStorage GetCnmtFile(ulong titleId, int version)
|
||||||
{
|
{
|
||||||
var cnmt = GetCnmtFileFromCache(titleId, version);
|
IStorage cnmt = GetCnmtFileFromCache(titleId, version);
|
||||||
if (cnmt != null) return cnmt;
|
if (cnmt != null) return cnmt;
|
||||||
|
|
||||||
if (Certificate == null) return null;
|
if (Certificate == null) return null;
|
||||||
|
@ -93,7 +93,7 @@ namespace Net
|
||||||
string titleDir = GetTitleDir(titleId, version);
|
string titleDir = GetTitleDir(titleId, version);
|
||||||
if (!Directory.Exists(titleDir)) return null;
|
if (!Directory.Exists(titleDir)) return null;
|
||||||
|
|
||||||
var cnmtFiles = Directory.GetFiles(titleDir, "*.cnmt.nca").ToArray();
|
string[] cnmtFiles = Directory.GetFiles(titleDir, "*.cnmt.nca").ToArray();
|
||||||
|
|
||||||
if (cnmtFiles.Length == 1)
|
if (cnmtFiles.Length == 1)
|
||||||
{
|
{
|
||||||
|
@ -110,11 +110,11 @@ namespace Net
|
||||||
|
|
||||||
public Nacp GetControl(ulong titleId, int version)
|
public Nacp GetControl(ulong titleId, int version)
|
||||||
{
|
{
|
||||||
var cnmt = GetCnmt(titleId, version);
|
Cnmt cnmt = GetCnmt(titleId, version);
|
||||||
var controlEntry = cnmt?.ContentEntries.FirstOrDefault(x => x.Type == CnmtContentType.Control);
|
CnmtContentEntry controlEntry = cnmt?.ContentEntries.FirstOrDefault(x => x.Type == CnmtContentType.Control);
|
||||||
if (controlEntry == null) return null;
|
if (controlEntry == null) return null;
|
||||||
|
|
||||||
var controlNca = GetNcaFile(titleId, version, controlEntry.NcaId.ToHexString());
|
IStorage controlNca = GetNcaFile(titleId, version, controlEntry.NcaId.ToHexString());
|
||||||
if (controlNca == null) return null;
|
if (controlNca == null) return null;
|
||||||
|
|
||||||
var nca = new Nca(ToolCtx.Keyset, controlNca, true);
|
var nca = new Nca(ToolCtx.Keyset, controlNca, true);
|
||||||
|
@ -130,7 +130,7 @@ namespace Net
|
||||||
string titleDir = GetTitleDir(titleId, version);
|
string titleDir = GetTitleDir(titleId, version);
|
||||||
if (!Directory.Exists(titleDir)) return null;
|
if (!Directory.Exists(titleDir)) return null;
|
||||||
|
|
||||||
var filePath = Path.Combine(titleDir, $"{ncaId.ToLower()}.nca");
|
string filePath = Path.Combine(titleDir, $"{ncaId.ToLower()}.nca");
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
{
|
{
|
||||||
DownloadFile(GetContentUrl(ncaId), filePath);
|
DownloadFile(GetContentUrl(ncaId), filePath);
|
||||||
|
@ -143,7 +143,7 @@ namespace Net
|
||||||
|
|
||||||
public List<SuperflyInfo> GetSuperfly(ulong titleId)
|
public List<SuperflyInfo> GetSuperfly(ulong titleId)
|
||||||
{
|
{
|
||||||
var filename = GetSuperflyFile(titleId);
|
string filename = GetSuperflyFile(titleId);
|
||||||
return Json.ReadSuperfly(filename);
|
return Json.ReadSuperfly(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ namespace Net
|
||||||
{
|
{
|
||||||
string titleDir = GetTitleDir(titleId);
|
string titleDir = GetTitleDir(titleId);
|
||||||
|
|
||||||
var filePath = Path.Combine(titleDir, $"{titleId:x16}.json");
|
string filePath = Path.Combine(titleDir, $"{titleId:x16}.json");
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
{
|
{
|
||||||
DownloadFile(GetSuperflyUrl(titleId), filePath);
|
DownloadFile(GetSuperflyUrl(titleId), filePath);
|
||||||
|
@ -164,31 +164,31 @@ namespace Net
|
||||||
|
|
||||||
private void DownloadCnmt(ulong titleId, int version)
|
private void DownloadCnmt(ulong titleId, int version)
|
||||||
{
|
{
|
||||||
var titleDir = GetTitleDir(titleId, version);
|
string titleDir = GetTitleDir(titleId, version);
|
||||||
|
|
||||||
var ncaId = GetMetadataNcaId(titleId, version);
|
string ncaId = GetMetadataNcaId(titleId, version);
|
||||||
if (ncaId == null)
|
if (ncaId == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Could not get {titleId:x16}v{version} metadata");
|
Console.WriteLine($"Could not get {titleId:x16}v{version} metadata");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var filename = $"{ncaId.ToLower()}.cnmt.nca";
|
string filename = $"{ncaId.ToLower()}.cnmt.nca";
|
||||||
var filePath = Path.Combine(titleDir, filename);
|
string filePath = Path.Combine(titleDir, filename);
|
||||||
DownloadFile(GetMetaUrl(ncaId), filePath);
|
DownloadFile(GetMetaUrl(ncaId), filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DownloadFile(string url, string filePath)
|
public void DownloadFile(string url, string filePath)
|
||||||
{
|
{
|
||||||
var response = Request("GET", url);
|
WebResponse response = Request("GET", url);
|
||||||
if (response == null) return;
|
if (response == null) return;
|
||||||
|
|
||||||
var dir = Path.GetDirectoryName(filePath) ?? throw new DirectoryNotFoundException();
|
string dir = Path.GetDirectoryName(filePath) ?? throw new DirectoryNotFoundException();
|
||||||
Directory.CreateDirectory(dir);
|
Directory.CreateDirectory(dir);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var responseStream = response.GetResponseStream())
|
using (Stream responseStream = response.GetResponseStream())
|
||||||
using (var outStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
|
using (var outStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
|
||||||
{
|
{
|
||||||
responseStream.CopyStream(outStream, response.ContentLength, ToolCtx.Logger);
|
responseStream.CopyStream(outStream, response.ContentLength, ToolCtx.Logger);
|
||||||
|
@ -245,7 +245,7 @@ namespace Net
|
||||||
|
|
||||||
public VersionList GetVersionList()
|
public VersionList GetVersionList()
|
||||||
{
|
{
|
||||||
var filename = Path.Combine(CachePath, "hac_versionlist");
|
string filename = Path.Combine(CachePath, "hac_versionlist");
|
||||||
VersionList list = null;
|
VersionList list = null;
|
||||||
if (Db.IsVersionListCurrent() && File.Exists(filename))
|
if (Db.IsVersionListCurrent() && File.Exists(filename))
|
||||||
{
|
{
|
||||||
|
@ -274,7 +274,7 @@ namespace Net
|
||||||
|
|
||||||
public WebResponse Request(string method, string url)
|
public WebResponse Request(string method, string url)
|
||||||
{
|
{
|
||||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
var request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
request.ClientCertificates.Add(Certificate);
|
request.ClientCertificates.Add(Certificate);
|
||||||
request.Accept = "*/*";
|
request.Accept = "*/*";
|
||||||
request.UserAgent = $"NintendoSDK Firmware/{Firmware} (platform:NX; did:{Did}; eid:{Eid})";
|
request.UserAgent = $"NintendoSDK Firmware/{Firmware} (platform:NX; did:{Did}; eid:{Eid})";
|
||||||
|
|
|
@ -55,15 +55,15 @@ namespace Net
|
||||||
int ver = ctx.Options.Version;
|
int ver = ctx.Options.Version;
|
||||||
|
|
||||||
var net = new NetContext(ctx);
|
var net = new NetContext(ctx);
|
||||||
var cnmt = net.GetCnmt(tid, ver);
|
Cnmt cnmt = net.GetCnmt(tid, ver);
|
||||||
if (cnmt == null) return;
|
if (cnmt == null) return;
|
||||||
ctx.Logger.LogMessage($"Title is of type {cnmt.Type} and has {cnmt.ContentEntries.Length} content entries");
|
ctx.Logger.LogMessage($"Title is of type {cnmt.Type} and has {cnmt.ContentEntries.Length} content entries");
|
||||||
var control = net.GetControl(tid, ver);
|
Nacp control = net.GetControl(tid, ver);
|
||||||
if (control != null)
|
if (control != null)
|
||||||
{
|
{
|
||||||
ctx.Logger.LogMessage($"Title has name {control.Descriptions[0].Title}");
|
ctx.Logger.LogMessage($"Title has name {control.Descriptions[0].Title}");
|
||||||
}
|
}
|
||||||
foreach (var entry in cnmt.ContentEntries)
|
foreach (CnmtContentEntry entry in cnmt.ContentEntries)
|
||||||
{
|
{
|
||||||
ctx.Logger.LogMessage($"{entry.NcaId.ToHexString()} {entry.Type}");
|
ctx.Logger.LogMessage($"{entry.NcaId.ToHexString()} {entry.Type}");
|
||||||
net.GetNcaFile(tid, ver, entry.NcaId.ToHexString());
|
net.GetNcaFile(tid, ver, entry.NcaId.ToHexString());
|
||||||
|
@ -149,13 +149,13 @@ namespace Net
|
||||||
|
|
||||||
private static void OpenKeyset(Context ctx)
|
private static void OpenKeyset(Context ctx)
|
||||||
{
|
{
|
||||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
var homeKeyFile = Path.Combine(home, ".switch", "prod.keys");
|
string homeKeyFile = Path.Combine(home, ".switch", "prod.keys");
|
||||||
var homeTitleKeyFile = Path.Combine(home, ".switch", "title.keys");
|
string homeTitleKeyFile = Path.Combine(home, ".switch", "title.keys");
|
||||||
var homeConsoleKeyFile = Path.Combine(home, ".switch", "console.keys");
|
string homeConsoleKeyFile = Path.Combine(home, ".switch", "console.keys");
|
||||||
var keyFile = ctx.Options.Keyfile;
|
string keyFile = ctx.Options.Keyfile;
|
||||||
var titleKeyFile = ctx.Options.TitleKeyFile;
|
string titleKeyFile = ctx.Options.TitleKeyFile;
|
||||||
var consoleKeyFile = ctx.Options.ConsoleKeyFile;
|
string consoleKeyFile = ctx.Options.ConsoleKeyFile;
|
||||||
|
|
||||||
if (keyFile == null && File.Exists(homeKeyFile))
|
if (keyFile == null && File.Exists(homeKeyFile))
|
||||||
{
|
{
|
||||||
|
@ -184,7 +184,7 @@ namespace Net
|
||||||
string line;
|
string line;
|
||||||
while ((line = reader.ReadLine()) != null)
|
while ((line = reader.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
if (ulong.TryParse(line, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var id))
|
if (ulong.TryParse(line, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong id))
|
||||||
{
|
{
|
||||||
titles.Add(id);
|
titles.Add(id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue