mirror of
https://github.com/SabreTools/NDecrypt.git
synced 2026-07-08 18:06:38 +00:00
Copy inputs to outputs for processing, optionally
This commit is contained in:
@@ -25,8 +25,14 @@ namespace NDecrypt.Core
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open the read and write on the same file for inplace processing
|
||||
using var reader = File.Open(input, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
// If the output is provided, copy the input file
|
||||
if (output != null)
|
||||
File.Copy(input, output);
|
||||
else
|
||||
output = input;
|
||||
|
||||
// Open the output file for processing
|
||||
using var reader = File.Open(output, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Deserialize the cart information
|
||||
var nitro = Nitro.Create(reader);
|
||||
@@ -47,7 +53,7 @@ namespace NDecrypt.Core
|
||||
nitro.EncryptSecureArea(_decryptArgs.NitroEncryptionData, force);
|
||||
|
||||
// Write the encrypted secure area
|
||||
using var writer = File.Open(input, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
using var writer = File.Open(output, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
writer.Seek(0x4000, SeekOrigin.Begin);
|
||||
writer.Write(nitro.SecureArea);
|
||||
writer.Flush();
|
||||
@@ -56,7 +62,7 @@ namespace NDecrypt.Core
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"An error has occurred. {input} may be corrupted if it was partially processed.");
|
||||
Console.WriteLine($"An error has occurred. {output} may be corrupted if it was partially processed.");
|
||||
Console.WriteLine("Please check that the file was a valid DS or DSi file and try again.");
|
||||
return false;
|
||||
}
|
||||
@@ -71,8 +77,14 @@ namespace NDecrypt.Core
|
||||
{
|
||||
try
|
||||
{
|
||||
// If the output is provided, copy the input file
|
||||
if (output != null)
|
||||
File.Copy(input, output);
|
||||
else
|
||||
output = input;
|
||||
|
||||
// Open the read and write on the same file for inplace processing
|
||||
using var reader = File.Open(input, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using var reader = File.Open(output, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Deserialize the cart information
|
||||
var nitro = Nitro.Create(reader);
|
||||
@@ -93,7 +105,7 @@ namespace NDecrypt.Core
|
||||
nitro.DecryptSecureArea(_decryptArgs.NitroEncryptionData, force);
|
||||
|
||||
// Write the decrypted secure area
|
||||
using var writer = File.Open(input, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
using var writer = File.Open(output, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
writer.Seek(0x4000, SeekOrigin.Begin);
|
||||
writer.Write(nitro.SecureArea);
|
||||
writer.Flush();
|
||||
@@ -102,7 +114,7 @@ namespace NDecrypt.Core
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"An error has occurred. {input} may be corrupted if it was partially processed.");
|
||||
Console.WriteLine($"An error has occurred. {output} may be corrupted if it was partially processed.");
|
||||
Console.WriteLine("Please check that the file was a valid DS or DSi file and try again.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -46,9 +46,15 @@ namespace NDecrypt.Core
|
||||
|
||||
try
|
||||
{
|
||||
// Open the read and write on the same file for inplace processing
|
||||
using var reader = File.Open(input, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using var writer = File.Open(input, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
// If the output is provided, copy the input file
|
||||
if (output != null)
|
||||
File.Copy(input, output);
|
||||
else
|
||||
output = input;
|
||||
|
||||
// Open the output file for processing
|
||||
using var reader = File.Open(output, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using var writer = File.Open(output, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
|
||||
// Deserialize the cart information
|
||||
var cart = N3DS.Create(reader);
|
||||
@@ -64,7 +70,7 @@ namespace NDecrypt.Core
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"An error has occurred. {input} may be corrupted if it was partially processed.");
|
||||
Console.WriteLine($"An error has occurred. {output} 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;
|
||||
}
|
||||
@@ -459,9 +465,15 @@ namespace NDecrypt.Core
|
||||
|
||||
try
|
||||
{
|
||||
// Open the read and write on the same file for inplace processing
|
||||
using var reader = File.Open(input, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using var writer = File.Open(input, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
// If the output is provided, copy the input file
|
||||
if (output != null)
|
||||
File.Copy(input, output);
|
||||
else
|
||||
output = input;
|
||||
|
||||
// Open the output file for processing
|
||||
using var reader = File.Open(output, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using var writer = File.Open(output, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
|
||||
// Deserialize the cart information
|
||||
var cart = N3DS.Create(reader);
|
||||
@@ -477,7 +489,7 @@ namespace NDecrypt.Core
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"An error has occurred. {input} may be corrupted if it was partially processed.");
|
||||
Console.WriteLine($"An error has occurred. {output} 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user