Add simple info check (fixes #18)

This commit is contained in:
Matt Nadareski
2025-02-19 15:47:05 -05:00
parent 383e6bdfce
commit db7c7ee273
2 changed files with 62 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Text;
using SabreTools.IO.Extensions;
using SabreTools.Models.Nitro;
using SabreTools.Serialization.Wrappers;
@@ -590,8 +591,37 @@ namespace NDecrypt.Core
/// <inheritdoc/>
public string? GetInformation(string filename)
{
// TODO: Get decryption status
return null;
try
{
// Open the file for reading
using var input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// Deserialize the cart information
var cart = Nitro.Create(input);
if (cart?.Model == null)
return "Error: Not a DS or DSi Rom!";
// Get a string builder for the status
var sb = new StringBuilder();
sb.Append("Secure Area: ");
// Get the encryption status
bool? decrypted = CheckIfDecrypted(input);
if (decrypted == null)
sb.Append("Empty");
else if (decrypted == true)
sb.Append("Decrypted");
else
sb.Append("English");
// Return the status for the secure area
return sb.ToString();
}
catch (Exception ex)
{
Console.WriteLine(ex);
return null;
}
}
#endregion

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Text;
using SabreTools.IO.Extensions;
using SabreTools.Models.N3DS;
using SabreTools.Serialization.Wrappers;
@@ -871,14 +872,40 @@ namespace NDecrypt.Core
}
#endregion
#region Info
/// <inheritdoc/>
public string? GetInformation(string filename)
{
// TODO: Get decryption status
return null;
try
{
// Open the file for reading
using var input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// Deserialize the cart information
var cart = N3DS.Create(input);
if (cart?.Model == null)
return "Error: Not a 3DS cart image!";
// Get a string builder for the status
var sb = new StringBuilder();
// Iterate over all 8 NCCH partitions
for (int p = 0; p < 8; p++)
{
bool decrypted = cart.PossiblyDecrypted(p);
sb.AppendLine($"Partition {p}: {(decrypted ? "Decrypted" : "Encrypted")}");
}
// Return the status for all partitions
return sb.ToString();
}
catch (Exception ex)
{
Console.WriteLine(ex);
return null;
}
}
#endregion