Add info to interface; add start of implementations

This commit is contained in:
Matt Nadareski
2025-02-19 15:36:36 -05:00
parent 169bd48762
commit 383e6bdfce
4 changed files with 70 additions and 38 deletions

View File

@@ -585,6 +585,17 @@ namespace NDecrypt.Core
#endregion
#region Info
/// <inheritdoc/>
public string? GetInformation(string filename)
{
// TODO: Get decryption status
return null;
}
#endregion
#region Common
/// <summary>

View File

@@ -17,5 +17,12 @@
/// <param name="force">Indicates if the operation should be forced</param>
/// <returns>True if the file could be decrypted, false otherwise</returns>
bool DecryptFile(string filename, bool force);
/// <summary>
/// Attempts to get information on an input file
/// </summary>
/// <param name="filename">Name of the file get information on</param>
/// <returns>String representing the info, null on error</returns>
string? GetInformation(string filename);
}
}

View File

@@ -31,41 +31,7 @@ namespace NDecrypt.Core
_decryptArgs = decryptArgs;
}
/// <inheritdoc/>
public bool EncryptFile(string filename, bool force)
{
// Ensure the constants are all set
if (_decryptArgs.IsReady != true)
{
Console.WriteLine("Could not read keys. Please make sure the file exists and try again.");
return false;
}
try
{
// Open the read and write on the same file for inplace processing
using var input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var output = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
// Deserialize the cart information
var cart = N3DS.Create(input);
if (cart?.Model == null)
{
Console.WriteLine("Error: Not a 3DS cart image!");
return false;
}
// Encrypt all 8 NCCH partitions
EncryptAllPartitions(cart, force, input, output);
return true;
}
catch
{
Console.WriteLine($"An error has occurred. {filename} may be corrupted if it was partially processed.");
Console.WriteLine("Please check that the file was a valid 3DS or New 3DS cart image and try again.");
return false;
}
}
#region Decrypt
/// <inheritdoc/>
public bool DecryptFile(string filename, bool force)
@@ -103,8 +69,6 @@ namespace NDecrypt.Core
}
}
#region Decrypt
/// <summary>
/// Decrypt all partitions in the partition table of an NCSD header
/// </summary>
@@ -478,6 +442,42 @@ namespace NDecrypt.Core
#region Encrypt
/// <inheritdoc/>
public bool EncryptFile(string filename, bool force)
{
// Ensure the constants are all set
if (_decryptArgs.IsReady != true)
{
Console.WriteLine("Could not read keys. Please make sure the file exists and try again.");
return false;
}
try
{
// Open the read and write on the same file for inplace processing
using var input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var output = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
// Deserialize the cart information
var cart = N3DS.Create(input);
if (cart?.Model == null)
{
Console.WriteLine("Error: Not a 3DS cart image!");
return false;
}
// Encrypt all 8 NCCH partitions
EncryptAllPartitions(cart, force, input, output);
return true;
}
catch
{
Console.WriteLine($"An error has occurred. {filename} may be corrupted if it was partially processed.");
Console.WriteLine("Please check that the file was a valid 3DS or New 3DS cart image and try again.");
return false;
}
}
/// <summary>
/// Encrypt all partitions in the partition table of an NCSD header
/// </summary>
@@ -871,5 +871,16 @@ namespace NDecrypt.Core
}
#endregion
#region Info
/// <inheritdoc/>
public string? GetInformation(string filename)
{
// TODO: Get decryption status
return null;
}
#endregion
}
}

View File

@@ -152,7 +152,10 @@ namespace NDecrypt
}
else if (feature == Feature.Info)
{
Console.WriteLine("Feature 'INFO' is not implemented");
string? infoString = tool.GetInformation(path);
infoString ??= "There was a problem getting file information!";
Console.WriteLine(infoString);
return;
}