Skip to content

Commit

Permalink
Hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
simontime committed Nov 2, 2018
1 parent 15bfa5e commit 665e7c6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 68 deletions.
3 changes: 1 addition & 2 deletions Form1.Designer.cs

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

119 changes: 63 additions & 56 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,27 @@ private string[] GetTitleMeta(string TitleID = null)
}
else
{
using (var WC = new WebClient())
try
{
var Cli = WC.DownloadData($"https://gamechat.network/nucleus?title_id={TitleID}");
pictureBox1.Image = Image.FromStream(new MemoryStream(Cli));

Info[0] = Encoding.UTF8.GetString
(
WC.ResponseHeaders.Get("X-GCN-Game-Name")
.Select(b => (byte)b).ToArray()
);

Info[1] = Encoding.UTF8.GetString
(
WC.ResponseHeaders.Get("X-GCN-Game-Dev")
.Select(b => (byte)b).ToArray()
);
using (var WC = new WebClient())
{
var Cli = WC.DownloadData($"https://gamechat.network/nucleus?title_id={TitleID}");
pictureBox1.Image = Image.FromStream(new MemoryStream(Cli));

Info[0] = Encoding.UTF8.GetString
(
WC.ResponseHeaders.Get("X-GCN-Game-Name")
.Select(b => (byte)b).ToArray()
);

Info[1] = Encoding.UTF8.GetString
(
WC.ResponseHeaders.Get("X-GCN-Game-Dev")
.Select(b => (byte)b).ToArray()
);
}
}
catch { }
}
return Info;
}
Expand Down Expand Up @@ -113,7 +117,8 @@ private void Open()
var Cnmt = new Cnmt(CnmtPfs.OpenFile(CnmtPfs.Files[0]));
var Program = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Program);
var CtrlEntry = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Control);
Control = new Nca(Keys, Pfs.OpenFile($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
if (CtrlEntry != null)
Control = new Nca(Keys, Pfs.OpenFile($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
Input = Pfs.OpenFile($"{Program.NcaId.ToHexString().ToLower()}.nca");
}
else if (Ext == ".xci")
Expand All @@ -125,7 +130,8 @@ private void Open()
var Cnmt = new Cnmt(CnmtPfs.OpenFile(CnmtPfs.Files[0]));
var Program = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Program);
var CtrlEntry = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Control);
Control = new Nca(Keys, Xci.SecurePartition.OpenFile($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
if (CtrlEntry != null)
Control = new Nca(Keys, Xci.SecurePartition.OpenFile($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
Input = Xci.SecurePartition.OpenFile($"{Program.NcaId.ToHexString().ToLower()}.nca");
}
else if (FileToOpen.Split('.')[1] == "cnmt" && Ext == ".nca")
Expand All @@ -136,7 +142,8 @@ private void Open()
var Cnmt = new Cnmt(CnmtPfs.OpenFile(CnmtPfs.Files[0]));
var Program = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Program);
var CtrlEntry = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Control);
Control = new Nca(Keys, File.OpenRead($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
if (CtrlEntry != null)
Control = new Nca(Keys, File.OpenRead($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
Input = File.OpenRead($"{Program.NcaId.ToHexString().ToLower()}.nca");
}
else Input = File.OpenRead(FileToOpen);
Expand Down Expand Up @@ -201,22 +208,15 @@ private void Open()
}
}

private void panel1_Paint(object sender, PaintEventArgs e)
{
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
Open();
var Dialog = openFileDialog1.ShowDialog();
if (Dialog != DialogResult.Cancel) Open();
}

private void Form1_Load(object sender, EventArgs e)
{
if (Program.FileArg != null)
{
Open();
}
if (Program.FileArg != null)Open();
}

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
Expand Down Expand Up @@ -402,8 +402,8 @@ private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEve

private void allFilesToolStripMenuItem_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
Rom.Extract(folderBrowserDialog1.SelectedPath);
var Dialog = folderBrowserDialog1.ShowDialog();
if (Dialog != DialogResult.Cancel) Rom.Extract(folderBrowserDialog1.SelectedPath);
}

private void expandAllNodesToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -473,19 +473,22 @@ private void button3_Click(object sender, EventArgs e)

private void dToolStripMenuItem_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
bool FoundExefs = false;

for (int i = 0; i < 4; i++)
var Dialog = folderBrowserDialog1.ShowDialog();
if (Dialog != DialogResult.Cancel)
{
if (Nca.Header.ContentType == ContentType.Program && i == (int)ProgramPartitionType.Code)
bool FoundExefs = false;

for (int i = 0; i < 4; i++)
{
FoundExefs = true;
Nca.ExtractSection(i, folderBrowserDialog1.SelectedPath);
if (Nca.Header.ContentType == ContentType.Program && i == (int)ProgramPartitionType.Code)
{
FoundExefs = true;
Nca.ExtractSection(i, folderBrowserDialog1.SelectedPath);
}
}
}

if (!FoundExefs) MessageBox.Show("Error: this NCA does not contain an ExeFS partition.");
if (!FoundExefs) MessageBox.Show("Error: this NCA does not contain an ExeFS partition.");
}
}

private void listOfFilesToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -501,16 +504,18 @@ private void iconToolStripMenuItem_Click(object sender, EventArgs e)
using (var Rom = Control.OpenSection(0, false, IntegrityCheckLevel.None))
{
var Romfs = new Romfs(Rom);
folderBrowserDialog1.ShowDialog();
var Dialog = folderBrowserDialog1.ShowDialog();

using (var Icon = Romfs.OpenFile(Romfs.Files.FirstOrDefault(f => f.Name.Contains("icon"))))
Icon.WriteAllBytes($"{folderBrowserDialog1.SelectedPath}/{Control.Header.TitleId:x16}_icon.jpg");
if (Dialog != DialogResult.Cancel)
using (var Icon = Romfs.OpenFile(Romfs.Files.FirstOrDefault(f => f.Name.Contains("icon"))))
Icon.WriteAllBytes($"{folderBrowserDialog1.SelectedPath}/{Control.Header.TitleId:x16}_icon.jpg");
}
}
else if (pictureBox1.Image != null)
{
folderBrowserDialog1.ShowDialog();
pictureBox1.Image.Save($"{folderBrowserDialog1.SelectedPath}/{Nca.Header.TitleId:x16}_icon.jpg");
var Dialog = folderBrowserDialog1.ShowDialog();
if (Dialog != DialogResult.Cancel)
pictureBox1.Image.Save($"{folderBrowserDialog1.SelectedPath}/{Nca.Header.TitleId:x16}_icon.jpg");
}
else MessageBox.Show("Error: No control is present and icon is not in the database!");
}
Expand All @@ -522,9 +527,10 @@ private void rawToolStripMenuItem_Click(object sender, EventArgs e)
using (var Rom = Control.OpenSection(0, false, IntegrityCheckLevel.None))
{
var Romfs = new Romfs(Rom);
folderBrowserDialog1.ShowDialog();
using (var Nacp = Romfs.OpenFile(Romfs.Files.FirstOrDefault(f => f.Name == "control.nacp")))
Nacp.WriteAllBytes($"{folderBrowserDialog1.SelectedPath}/{Nca.Header.TitleId:x16}_control.nacp");
var Dialog = folderBrowserDialog1.ShowDialog();
if (Dialog != DialogResult.Cancel)
using (var Nacp = Romfs.OpenFile(Romfs.Files.FirstOrDefault(f => f.Name == "control.nacp")))
Nacp.WriteAllBytes($"{folderBrowserDialog1.SelectedPath}/{Nca.Header.TitleId:x16}_control.nacp");
}
}
else MessageBox.Show("Error: No control is present!");
Expand All @@ -537,17 +543,18 @@ private void jSONToolStripMenuItem_Click(object sender, EventArgs e)
using (var Rom = Control.OpenSection(0, false, IntegrityCheckLevel.None))
{
var Romfs = new Romfs(Rom);
folderBrowserDialog1.ShowDialog();
using (var InFile = Romfs.OpenFile(Romfs.Files.FirstOrDefault(f => f.Name == "control.nacp")))
using (var Read = new BinaryReader(InFile))
{
var Nacp = new Nacp(Read);
var Dialog = folderBrowserDialog1.ShowDialog();
if (Dialog != DialogResult.Cancel)
using (var InFile = Romfs.OpenFile(Romfs.Files.FirstOrDefault(f => f.Name == "control.nacp")))
using (var Read = new BinaryReader(InFile))
{
var Nacp = new Nacp(Read);

var Settings = new JsonSerializerSettings { Formatting = Formatting.Indented };
var Settings = new JsonSerializerSettings { Formatting = Formatting.Indented };

File.WriteAllText($"{folderBrowserDialog1.SelectedPath}/{Nca.Header.TitleId:x16}_control.json",
JsonConvert.SerializeObject(Nacp, Settings));
}
File.WriteAllText($"{folderBrowserDialog1.SelectedPath}/{Nca.Header.TitleId:x16}_control.json",
JsonConvert.SerializeObject(Nacp, Settings));
}
}
}
else MessageBox.Show("Error: No control is present!");
Expand Down
7 changes: 2 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ namespace SwitchExplorer
{
static class Program
{
public static string FileArg { get; set; }
public static string FileArg { get; internal set; }

[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{
FileArg = args[0];
}
if (args.Length > 0) FileArg = args[0];
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Expand Down
11 changes: 6 additions & 5 deletions SwitchExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
File renamed without changes.

0 comments on commit 665e7c6

Please sign in to comment.