Apply var style

This commit is contained in:
Alex Barney 2019-02-05 16:45:37 -06:00
parent c1c4c6ad46
commit 9875880e32
6 changed files with 37 additions and 37 deletions

View file

@ -43,7 +43,7 @@ namespace Net
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)
{
PrintWithUsage($"Unknown option {args[i]}");
@ -74,7 +74,7 @@ namespace Net
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");
}
@ -84,7 +84,7 @@ namespace Net
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");
}

View file

@ -19,7 +19,7 @@ namespace Net
public static Database Deserialize(string filename)
{
var text = File.ReadAllText(filename);
string text = File.ReadAllText(filename);
return JsonConvert.DeserializeObject<Database>(text);
}

View file

@ -10,7 +10,7 @@ namespace Net
{
public static VersionList ReadVersionList(string filename)
{
var text = File.ReadAllText(filename);
string text = File.ReadAllText(filename);
var versionList = JsonConvert.DeserializeObject<VersionList>(text);
return versionList;
}

View file

@ -41,7 +41,7 @@ namespace Net
}
Directory.CreateDirectory(CachePath);
var databaseFile = Path.Combine(CachePath, "database.json");
string databaseFile = Path.Combine(CachePath, "database.json");
if (!File.Exists(databaseFile))
{
File.WriteAllText(databaseFile, new Database().Serialize());
@ -51,7 +51,7 @@ namespace Net
public void Save()
{
var databaseFile = Path.Combine(CachePath, "database.json");
string databaseFile = Path.Combine(CachePath, "database.json");
File.WriteAllText(databaseFile, Db.Serialize());
}
@ -63,7 +63,7 @@ namespace Net
public Cnmt GetCnmt(ulong titleId, int version)
{
using (var stream = GetCnmtFile(titleId, version))
using (IStorage stream = GetCnmtFile(titleId, version))
{
if (stream == null) return null;
@ -79,7 +79,7 @@ namespace Net
public IStorage GetCnmtFile(ulong titleId, int version)
{
var cnmt = GetCnmtFileFromCache(titleId, version);
IStorage cnmt = GetCnmtFileFromCache(titleId, version);
if (cnmt != null) return cnmt;
if (Certificate == null) return null;
@ -93,7 +93,7 @@ namespace Net
string titleDir = GetTitleDir(titleId, version);
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)
{
@ -110,11 +110,11 @@ namespace Net
public Nacp GetControl(ulong titleId, int version)
{
var cnmt = GetCnmt(titleId, version);
var controlEntry = cnmt?.ContentEntries.FirstOrDefault(x => x.Type == CnmtContentType.Control);
Cnmt cnmt = GetCnmt(titleId, version);
CnmtContentEntry controlEntry = cnmt?.ContentEntries.FirstOrDefault(x => x.Type == CnmtContentType.Control);
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;
var nca = new Nca(ToolCtx.Keyset, controlNca, true);
@ -130,7 +130,7 @@ namespace Net
string titleDir = GetTitleDir(titleId, version);
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))
{
DownloadFile(GetContentUrl(ncaId), filePath);
@ -143,7 +143,7 @@ namespace Net
public List<SuperflyInfo> GetSuperfly(ulong titleId)
{
var filename = GetSuperflyFile(titleId);
string filename = GetSuperflyFile(titleId);
return Json.ReadSuperfly(filename);
}
@ -151,7 +151,7 @@ namespace Net
{
string titleDir = GetTitleDir(titleId);
var filePath = Path.Combine(titleDir, $"{titleId:x16}.json");
string filePath = Path.Combine(titleDir, $"{titleId:x16}.json");
if (!File.Exists(filePath))
{
DownloadFile(GetSuperflyUrl(titleId), filePath);
@ -164,31 +164,31 @@ namespace Net
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)
{
Console.WriteLine($"Could not get {titleId:x16}v{version} metadata");
return;
}
var filename = $"{ncaId.ToLower()}.cnmt.nca";
var filePath = Path.Combine(titleDir, filename);
string filename = $"{ncaId.ToLower()}.cnmt.nca";
string filePath = Path.Combine(titleDir, filename);
DownloadFile(GetMetaUrl(ncaId), filePath);
}
public void DownloadFile(string url, string filePath)
{
var response = Request("GET", url);
WebResponse response = Request("GET", url);
if (response == null) return;
var dir = Path.GetDirectoryName(filePath) ?? throw new DirectoryNotFoundException();
string dir = Path.GetDirectoryName(filePath) ?? throw new DirectoryNotFoundException();
Directory.CreateDirectory(dir);
try
{
using (var responseStream = response.GetResponseStream())
using (Stream responseStream = response.GetResponseStream())
using (var outStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
{
responseStream.CopyStream(outStream, response.ContentLength, ToolCtx.Logger);
@ -245,7 +245,7 @@ namespace Net
public VersionList GetVersionList()
{
var filename = Path.Combine(CachePath, "hac_versionlist");
string filename = Path.Combine(CachePath, "hac_versionlist");
VersionList list = null;
if (Db.IsVersionListCurrent() && File.Exists(filename))
{
@ -274,7 +274,7 @@ namespace Net
public WebResponse Request(string method, string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
var request = (HttpWebRequest)WebRequest.Create(url);
request.ClientCertificates.Add(Certificate);
request.Accept = "*/*";
request.UserAgent = $"NintendoSDK Firmware/{Firmware} (platform:NX; did:{Did}; eid:{Eid})";

View file

@ -55,15 +55,15 @@ namespace Net
int ver = ctx.Options.Version;
var net = new NetContext(ctx);
var cnmt = net.GetCnmt(tid, ver);
Cnmt cnmt = net.GetCnmt(tid, ver);
if (cnmt == null) return;
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)
{
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}");
net.GetNcaFile(tid, ver, entry.NcaId.ToHexString());
@ -149,13 +149,13 @@ namespace Net
private static void OpenKeyset(Context ctx)
{
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var homeKeyFile = Path.Combine(home, ".switch", "prod.keys");
var homeTitleKeyFile = Path.Combine(home, ".switch", "title.keys");
var homeConsoleKeyFile = Path.Combine(home, ".switch", "console.keys");
var keyFile = ctx.Options.Keyfile;
var titleKeyFile = ctx.Options.TitleKeyFile;
var consoleKeyFile = ctx.Options.ConsoleKeyFile;
string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string homeKeyFile = Path.Combine(home, ".switch", "prod.keys");
string homeTitleKeyFile = Path.Combine(home, ".switch", "title.keys");
string homeConsoleKeyFile = Path.Combine(home, ".switch", "console.keys");
string keyFile = ctx.Options.Keyfile;
string titleKeyFile = ctx.Options.TitleKeyFile;
string consoleKeyFile = ctx.Options.ConsoleKeyFile;
if (keyFile == null && File.Exists(homeKeyFile))
{
@ -184,7 +184,7 @@ namespace Net
string line;
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);
}