Skip to content

Commit

Permalink
Add Debug Log and restructure methods
Browse files Browse the repository at this point in the history
  • Loading branch information
garoxas committed Jan 11, 2019
1 parent 774e303 commit 22559ae
Show file tree
Hide file tree
Showing 10 changed files with 594 additions and 589 deletions.
16 changes: 10 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
@@ -1,6 +1,6 @@
---
name: Bug report
about: Create a report to help us improve
about: Create a bug report
title: ''
labels: bug
assignees: ''
Expand All @@ -19,11 +19,15 @@ A clear description of the bug
4.

**Application information**
- OS:
- Version: (macOS: Menu > About, Windows: Right-click in Explorer > Properties > Details)
- Application Path:
- prod.keys Path:
- OS name and version:
- Version:
- Application path:
- prod.keys path:
- Game filename:
- Game source (scene release, CDN rip, converted from other formats):

**Error log (if any)**
**Debug log**

**Crash log (if any)**

**Other information**
14 changes: 13 additions & 1 deletion NX_Game_Info/Common.cs
Expand Up @@ -6,11 +6,16 @@
using System.Text;
using LibHac;

#pragma warning disable IDE1006 // Naming rule violation: These words must begin with upper case characters

namespace NX_Game_Info
{
class Common
{
public static readonly string PATH_PREFIX = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.switch/";
public static readonly string APPLICATION_DIRECTORY_PATH_PREFIX = "";
public static readonly string USER_PROFILE_PATH_PREFIX = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.switch/";

public static readonly string LOG_FILE = "debug.log";

public static readonly string PROD_KEYS = "prod.keys";
public static readonly string TITLE_KEYS = "title.keys";
Expand Down Expand Up @@ -39,6 +44,13 @@ public string SDCardDirectory
set { this["SDCardDirectory"] = value; }
}

[UserScopedSettingAttribute()]
public bool DebugLog
{
get { return (bool)this["DebugLog"]; }
set { this["DebugLog"] = value; }
}

public static Settings Default = new Settings();
}

Expand Down
1,010 changes: 439 additions & 571 deletions NX_Game_Info/Process.cs

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion README.md
@@ -1,4 +1,12 @@
# NX Game Info

# Features
- NSP, XCI and installed titles on Switch SD card
- Game files structure (Scene Release, CDN Rip, Authoring Tool, Converted from other formats)
- NCA signature to verify official Nintendo titles. Unmodified titles should pass this verification, although titles converted from other formats will not
- Filesystem services permissions. Game titles should not have excessive permissions, and only trust titles with `Unsafe` and `Dangerous` from reliable source

# Information
- Title ID
- Title Name
- Display Version
Expand Down Expand Up @@ -44,7 +52,10 @@ NX Game Info uses `prod.keys`, `title.keys` and `console.keys` in the format as
- *console.keys*: Optional, but `sd_seed` key required for `Open SD Card` feature
- *hac_versionlist.json*: Optional, but required for `Latest Version` feature

These files should be put in the same directory as the executable for Windows or in $HOME/.switch
The application will look for these files at the following locations (other file locations will follow wherever `prod.keys` file was found)

- Directory of the executable file (.exe) for Windows or the application bundle (.app) for macOS
- `$HOME/.switch` e.g. C:\\Users\\_yourname_\\.switch for Windows or /Users/_yourname_/.switch for macOS

# macOS
### Open File/Directory
Expand Down
3 changes: 3 additions & 0 deletions Windows/App.config
Expand Up @@ -32,6 +32,9 @@
<setting name="SDCardDirectory" serializeAs="String">
<value />
</setting>
<setting name="DebugLog" serializeAs="String">
<value>False</value>
</setting>
</NX_Game_Info.Properties.Settings>
</userSettings>
</configuration>
41 changes: 40 additions & 1 deletion Windows/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 58 additions & 5 deletions Windows/Main.cs
Expand Up @@ -11,6 +11,8 @@
using BrightIdeasSoftware;
using Title = NX_Game_Info.Common.Title;

#pragma warning disable IDE1006 // Naming rule violation: These words must begin with upper case characters

namespace NX_Game_Info
{
public partial class Main : Form
Expand All @@ -21,6 +23,8 @@ public Main()
{
InitializeComponent();

debugLogToolStripMenuItem.Checked = Properties.Settings.Default.DebugLog;

bool init = Process.initialize(out List<string> messages);

foreach (var message in messages)
Expand Down Expand Up @@ -49,6 +53,8 @@ private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
openFileDialog.RestoreDirectory = true;
openFileDialog.InitialDirectory = Properties.Settings.Default.InitialDirectory;

Process.log?.WriteLine("Open File");

if (openFileDialog.ShowDialog() == DialogResult.OK)
{
objectListView.Items.Clear();
Expand All @@ -60,8 +66,10 @@ private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
Properties.Settings.Default.InitialDirectory = Path.GetDirectoryName(filenames.First());
Properties.Settings.Default.Save();

Process.log?.WriteLine("{0} file{1} selected", filenames.Count, filenames.Count == 1 ? "" : "s");

progressDialog = (IProgressDialog)new ProgressDialog();
progressDialog.StartProgressDialog(Handle, "Opening " + filenames.Count + " file" + (filenames.Count == 1 ? "" : "s"));
progressDialog.StartProgressDialog(Handle, String.Format("Opening {0} file{1}", filenames.Count, filenames.Count == 1 ? "" : "s"));

backgroundWorkerProcess.RunWorkerAsync(filenames);
}
Expand All @@ -78,6 +86,8 @@ private void openDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.SelectedPath = Properties.Settings.Default.InitialDirectory;

Process.log?.WriteLine("Open Directory");

if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
objectListView.Items.Clear();
Expand All @@ -90,23 +100,32 @@ private void openDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
Properties.Settings.Default.InitialDirectory = folderBrowserDialog.SelectedPath;
Properties.Settings.Default.Save();

Process.log?.WriteLine("{0} file{1} selected", filenames.Count, filenames.Count == 1 ? "" : "s");

progressDialog = (IProgressDialog)new ProgressDialog();
progressDialog.StartProgressDialog(Handle, "Opening " + filenames.Count + " file" + (filenames.Count == 1 ? "" : "s") + " from directory " + folderBrowserDialog.SelectedPath);
progressDialog.StartProgressDialog(Handle, String.Format("Opening {0} file{1} from directory {2}", filenames.Count, filenames.Count == 1 ? "" : "s", folderBrowserDialog.SelectedPath));

backgroundWorkerProcess.RunWorkerAsync(filenames);
}
}

private void openSDCardToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Process.keyset?.SdSeed.All(b => b == 0) ?? true)
if (Process.keyset?.SdSeed?.All(b => b == 0) ?? true)
{
MessageBox.Show("sd_seed is missing from Console Keys.\nOpen SD Card will not be available.", Application.ProductName);
string error = "sd_seed is missing from Console Keys";
Process.log?.WriteLine(error);

MessageBox.Show(String.Format("{0}.\nOpen SD Card will not be available.", error), Application.ProductName);
return;
}

if ((Process.keyset?.SdCardKekSource.All(b => b == 0) ?? true) || (Process.keyset?.SdCardKeySources[1].All(b => b == 0) ?? true))
if ((Process.keyset?.SdCardKekSource?.All(b => b == 0) ?? true) || (Process.keyset?.SdCardKeySources?[1]?.All(b => b == 0) ?? true))
{
Process.log?.WriteLine("Keyfile missing required keys");
Process.log?.WriteLine(" - {0} ({1}exists)", "sd_card_kek_source", (bool)Process.keyset?.SdCardKekSource?.Any(b => b != 0) ? "" : "not ");
Process.log?.WriteLine(" - {0} ({1}exists)", "sd_card_nca_key_source", (bool)Process.keyset?.SdCardKeySources?[1]?.Any(b => b != 0) ? "" : "not ");

MessageBox.Show("sd_card_kek_source and sd_card_nca_key_source are missing from Keyfile.\nOpen SD Card will not be available.", Application.ProductName);
return;
}
Expand All @@ -120,6 +139,8 @@ private void openSDCardToolStripMenuItem_Click(object sender, EventArgs e)
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.SelectedPath = String.IsNullOrEmpty(Properties.Settings.Default.SDCardDirectory) ? Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()) : Properties.Settings.Default.SDCardDirectory;

Process.log?.WriteLine("Open SD Card");

if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
objectListView.Items.Clear();
Expand All @@ -128,6 +149,8 @@ private void openSDCardToolStripMenuItem_Click(object sender, EventArgs e)
Properties.Settings.Default.SDCardDirectory = folderBrowserDialog.SelectedPath;
Properties.Settings.Default.Save();

Process.log?.WriteLine("SD card selected");

progressDialog = (IProgressDialog)new ProgressDialog();
progressDialog.StartProgressDialog(Handle, "Opening SD card on " + folderBrowserDialog.SelectedPath);

Expand All @@ -140,6 +163,32 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e)
Environment.Exit(-1);
}

private void debugLogToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.DebugLog = debugLogToolStripMenuItem.Checked;
Properties.Settings.Default.Save();

if (Properties.Settings.Default.DebugLog)
{
try
{
Process.log = File.AppendText(Process.path_prefix + Common.LOG_FILE);
Process.log.AutoFlush = true;
}
catch { }
}
else
{
Process.log?.Close();
Process.log = null;
}
}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show(String.Format("{0}\n{1}", Application.ProductName, Application.ProductVersion), "About");
}

private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
Expand Down Expand Up @@ -167,6 +216,8 @@ private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel
{
worker.ReportProgress(100, "");
}

Process.log?.WriteLine("\n{0} titles processed", titles.Count);
}
else if (e.Argument is string sdpath)
{
Expand All @@ -190,6 +241,8 @@ private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel
{
worker.ReportProgress(100, "");
}

Process.log?.WriteLine("\n{0} titles processed", titles.Count);
}

e.Result = titles;
Expand Down
8 changes: 4 additions & 4 deletions Windows/Properties/AssemblyInfo.cs
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NX Game Info")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Tool to read information from Nintendo Switch game files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Garoxas")]
[assembly: AssemblyProduct("NX Game Info")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyCopyright("Copyright © 2018 Garoxas")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("0.3.*")]
[assembly: AssemblyVersion("0.3.1.0")]
[assembly: AssemblyFileVersion("0.3.1.0")]
[assembly: AssemblyVersion("0.3.2.0")]
[assembly: AssemblyFileVersion("0.3.2.0")]
12 changes: 12 additions & 0 deletions Windows/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Windows/Properties/Settings.settings
Expand Up @@ -8,5 +8,8 @@
<Setting Name="SDCardDirectory" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="DebugLog" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 22559ae

Please sign in to comment.