2025-10-18 13:08:32 -04:00
using System ;
2025-10-06 15:54:14 -04:00
using MPF.Frontend ;
2025-10-07 15:19:50 -04:00
using MPF.Frontend.Tools ;
2025-10-06 15:54:14 -04:00
using SabreTools.CommandLine.Inputs ;
using SabreTools.RedumpLib ;
2025-10-06 16:06:23 -04:00
using SabreTools.RedumpLib.Data ;
2025-10-07 18:07:46 -04:00
using LogCompression = MPF . Processors . LogCompression ;
2025-10-06 15:54:14 -04:00
namespace MPF.Check.Features
{
2025-10-06 16:06:23 -04:00
internal sealed class MainFeature : BaseFeature
2025-10-06 15:54:14 -04:00
{
#region Feature Definition
public const string DisplayName = "main" ;
/// <remarks>Flags are unused</remarks>
private static readonly string [ ] _flags = [ ] ;
/// <remarks>Description is unused</remarks>
2025-10-06 16:34:19 -04:00
private const string _description = "" ;
2025-10-06 15:54:14 -04:00
#endregion
#region Inputs
2025-10-06 16:34:19 -04:00
private const string _createIrdName = "create-ird" ;
internal readonly FlagInput CreateIrdInput = new ( _createIrdName , "--create-ird" , "Create IRD from output files (PS3 only)" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _deleteName = "delete" ;
internal readonly FlagInput DeleteInput = new ( _deleteName , [ "-d" , "--delete" ] , "Enable unnecessary file deletion" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _disableArchivesName = "disable-archives" ;
internal readonly FlagInput DisableArchivesInput = new ( _disableArchivesName , "--disable-archives" , "Disable scanning archives (requires --scan)" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _enableDebugName = "enable-debug" ;
internal readonly FlagInput EnableDebugInput = new ( _enableDebugName , "--enable-debug" , "Enable debug protection information (requires --scan)" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _hideDriveLettersName = "hide-drive-letters" ;
internal readonly FlagInput HideDriveLettersInput = new ( _hideDriveLettersName , "--hide-drive-letters" , "Hide drive letters from scan output (requires --scan)" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _includeArtifactsName = "include-artifacts" ;
internal readonly FlagInput IncludeArtifactsInput = new ( _includeArtifactsName , "--include-artifacts" , "Include artifacts in JSON (requires --json)" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _jsonName = "json" ;
internal readonly FlagInput JsonInput = new ( _jsonName , [ "-j" , "--json" ] , "Enable submission JSON output" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _loadSeedName = "load-seed" ;
internal readonly StringInput LoadSeedInput = new ( _loadSeedName , "--load-seed" , "Load a seed submission JSON for user information" ) ;
2025-10-06 15:54:14 -04:00
2025-10-07 19:43:34 -04:00
private const string _logCompressionName = "log-compression" ;
2025-10-18 12:03:37 -04:00
internal readonly StringInput LogCompressionInput = new ( _logCompressionName , "--log-compression" , "Set the log compression type (requires compression enabled)" ) ;
2025-10-07 19:43:34 -04:00
2025-10-06 16:34:19 -04:00
private const string _noPlaceholdersName = "no-placeholders" ;
internal readonly FlagInput NoPlaceholdersInput = new ( _noPlaceholdersName , "--no-placeholders" , "Disable placeholder values in submission info" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _noRetrieveName = "no-retrieve" ;
internal readonly FlagInput NoRetrieveInput = new ( _noRetrieveName , "--no-retrieve" , "Disable retrieving match information from Redump" ) ;
2025-10-06 15:54:14 -04:00
2025-10-07 20:37:11 -04:00
private const string _passwordName = "password" ;
internal readonly StringInput PasswordInput = new ( _passwordName , [ "-P" , "--password" ] , "Redump password (incompatible with --no-retrieve)" ) ;
2025-10-06 16:34:19 -04:00
private const string _pathName = "path" ;
internal readonly StringInput PathInput = new ( _pathName , [ "-p" , "--path" ] , "Physical drive path for additional checks" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _pullAllName = "pull-all" ;
2025-10-07 20:37:11 -04:00
internal readonly FlagInput PullAllInput = new ( _pullAllName , "--pull-all" , "Pull all information from Redump (requires --username and --password)" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _scanName = "scan" ;
internal readonly FlagInput ScanInput = new ( _scanName , [ "-s" , "--scan" ] , "Enable copy protection scan (requires --path)" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _suffixName = "suffix" ;
internal readonly FlagInput SuffixInput = new ( _suffixName , [ "-x" , "--suffix" ] , "Enable adding filename suffix" ) ;
2025-10-06 15:54:14 -04:00
2025-10-06 16:34:19 -04:00
private const string _useName = "use" ;
internal readonly StringInput UseInput = new ( _useName , [ "-u" , "--use" ] , "Override configured dumping program name" ) ;
2025-10-06 15:54:14 -04:00
2025-10-07 20:37:11 -04:00
private const string _usernameName = "username" ;
internal readonly StringInput UsernameInput = new ( _usernameName , [ "-U" , "--username" ] , "Redump username (incompatible with --no-retrieve)" ) ;
2025-10-06 16:34:19 -04:00
private const string _zipName = "zip" ;
internal readonly FlagInput ZipInput = new ( _zipName , [ "-z" , "--zip" ] , "Enable log file compression" ) ;
2025-10-06 15:54:14 -04:00
#endregion
public MainFeature ( )
: base ( DisplayName , _flags , _description )
{
2025-10-06 16:34:19 -04:00
Add ( UseInput ) ;
Add ( LoadSeedInput ) ;
Add ( NoPlaceholdersInput ) ;
Add ( CreateIrdInput ) ;
Add ( NoRetrieveInput ) ;
2025-10-06 15:54:14 -04:00
// TODO: Figure out how to work with the credentials input
2025-10-06 16:34:19 -04:00
Add ( PullAllInput ) ;
Add ( PathInput ) ;
Add ( ScanInput ) ;
Add ( DisableArchivesInput ) ;
Add ( EnableDebugInput ) ;
Add ( HideDriveLettersInput ) ;
Add ( SuffixInput ) ;
Add ( JsonInput ) ;
Add ( IncludeArtifactsInput ) ;
Add ( ZipInput ) ;
2025-10-07 19:43:34 -04:00
Add ( LogCompressionInput ) ;
2025-10-06 16:34:19 -04:00
Add ( DeleteInput ) ;
2025-10-06 15:54:14 -04:00
}
/// <inheritdoc/>
public override bool ProcessArgs ( string [ ] args , int index )
{
// These values require multiple parts to be active
bool scan = false ,
enableArchives = true ,
enableDebug = false ,
hideDriveLetters = false ;
// If we have no arguments, just return
2026-01-25 18:09:00 -05:00
if ( args is null | | args . Length = = 0 )
2025-10-06 15:54:14 -04:00
return true ;
2025-10-07 15:19:50 -04:00
// Read the options from config, if possible
Options = OptionsLoader . LoadFromConfig ( ) ;
if ( Options . FirstRun )
{
2026-02-07 15:11:46 -05:00
Options = new Options ( ) ;
2026-02-07 13:23:57 -05:00
// Internal Program
2026-02-07 13:59:03 -05:00
Options . InternalProgram = InternalProgram . NONE ;
2026-02-07 13:23:57 -05:00
// Protection Scanning Options
Options . Processing . ProtectionScanning . ScanForProtection = false ;
Options . Processing . ProtectionScanning . ScanArchivesForProtection = true ;
Options . Processing . ProtectionScanning . IncludeDebugProtectionInformation = false ;
Options . Processing . ProtectionScanning . HideDriveLetters = false ;
// Redump Login Information
2026-02-07 20:24:39 -05:00
Options . Processing . Login . PullAllInformation = false ;
2026-02-07 13:23:57 -05:00
Options . Processing . Login . RedumpUsername = null ;
Options . Processing . Login . RedumpPassword = null ;
2026-02-07 20:24:39 -05:00
Options . Processing . Login . RetrieveMatchInformation = true ;
2026-02-07 13:23:57 -05:00
// Media Information
Options . Processing . MediaInformation . AddPlaceholders = true ;
// Post-Information Options
Options . Processing . AddFilenameSuffix = false ;
Options . Processing . CreateIRDAfterDumping = false ;
Options . Processing . OutputSubmissionJSON = false ;
Options . Processing . IncludeArtifacts = false ;
Options . Processing . CompressLogFiles = false ;
Options . Processing . LogCompression = LogCompression . DeflateMaximum ;
Options . Processing . DeleteUnnecessaryFiles = false ;
2025-10-07 15:19:50 -04:00
}
2025-10-18 13:08:32 -04:00
else
{
Console . WriteLine ( "Options will be loaded from found configuration file!" ) ;
}
2025-10-07 15:19:50 -04:00
2025-10-06 16:06:23 -04:00
// The first argument is the system type
2025-10-06 16:37:28 -04:00
System = args [ 0 ] . Trim ( '"' ) . ToRedumpSystem ( ) ;
2025-10-06 15:54:14 -04:00
// Loop through the arguments and parse out values
2025-10-06 16:06:23 -04:00
for ( index = 1 ; index < args . Length ; index + + )
2025-10-06 15:54:14 -04:00
{
// Use specific program
2025-10-06 16:34:19 -04:00
if ( UseInput . ProcessInput ( args , ref index ) )
2026-02-07 13:59:03 -05:00
Options . InternalProgram = UseInput . Value . ToInternalProgram ( ) ;
2025-10-06 15:54:14 -04:00
// Include seed info file
2025-10-06 16:34:19 -04:00
else if ( LoadSeedInput . ProcessInput ( args , ref index ) )
2025-10-06 17:49:16 -04:00
Seed = Builder . CreateFromFile ( LoadSeedInput . Value ) ;
2025-10-06 15:54:14 -04:00
// Disable placeholder values in submission info
2025-10-06 16:34:19 -04:00
else if ( NoPlaceholdersInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . MediaInformation . AddPlaceholders = ! Options . Processing . MediaInformation . AddPlaceholders ;
2025-10-06 15:54:14 -04:00
// Create IRD from output files (PS3 only)
2025-10-06 16:34:19 -04:00
else if ( CreateIrdInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . CreateIRDAfterDumping = ! Options . Processing . CreateIRDAfterDumping ;
2025-10-06 15:54:14 -04:00
2025-10-18 12:03:37 -04:00
// Set the log compression type (requires compression enabled)
2025-10-07 19:43:34 -04:00
else if ( LogCompressionInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . LogCompression = LogCompressionInput . Value . ToLogCompression ( ) ;
2025-10-07 19:43:34 -04:00
2025-10-06 15:54:14 -04:00
// Retrieve Redump match information
2025-10-06 16:34:19 -04:00
else if ( NoRetrieveInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . Login . RetrieveMatchInformation = ! Options . Processing . Login . RetrieveMatchInformation ;
2025-10-06 15:54:14 -04:00
// Redump login
else if ( args [ index ] . StartsWith ( "-c=" ) | | args [ index ] . StartsWith ( "--credentials=" ) )
{
string [ ] credentials = args [ index ] . Split ( '=' ) [ 1 ] . Split ( ';' ) ;
2026-02-07 13:23:57 -05:00
Options . Processing . Login . RedumpUsername = credentials [ 0 ] ;
Options . Processing . Login . RedumpPassword = credentials [ 1 ] ;
2025-10-06 15:54:14 -04:00
}
else if ( args [ index ] = = "-c" | | args [ index ] = = "--credentials" )
{
2026-02-07 13:23:57 -05:00
Options . Processing . Login . RedumpUsername = args [ index + 1 ] ;
Options . Processing . Login . RedumpPassword = args [ index + 2 ] ;
2025-10-06 15:54:14 -04:00
index + = 2 ;
}
2025-10-07 20:37:11 -04:00
// Redump username
else if ( UsernameInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . Login . RedumpUsername = UsernameInput . Value ;
2025-10-07 20:37:11 -04:00
// Redump password
else if ( PasswordInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . Login . RedumpPassword = PasswordInput . Value ;
2025-10-07 20:37:11 -04:00
2025-10-06 15:54:14 -04:00
// Pull all information (requires Redump login)
2025-10-06 16:34:19 -04:00
else if ( PullAllInput . ProcessInput ( args , ref index ) )
2026-02-07 20:24:39 -05:00
Options . Processing . Login . PullAllInformation = ! Options . Processing . Login . PullAllInformation ;
2025-10-06 15:54:14 -04:00
// Use a device path for physical checks
2025-10-06 16:34:19 -04:00
else if ( PathInput . ProcessInput ( args , ref index ) )
2025-10-06 17:49:16 -04:00
DevicePath = PathInput . Value ;
2025-10-06 15:54:14 -04:00
// Scan for protection (requires device path)
2025-10-06 16:34:19 -04:00
else if ( ScanInput . ProcessInput ( args , ref index ) )
2025-10-06 15:54:14 -04:00
scan = true ;
// Disable scanning archives (requires --scan)
2025-10-06 16:34:19 -04:00
else if ( ScanInput . ProcessInput ( args , ref index ) )
2025-10-06 15:54:14 -04:00
enableArchives = false ;
// Enable debug protection information (requires --scan)
2025-10-06 16:34:19 -04:00
else if ( EnableDebugInput . ProcessInput ( args , ref index ) )
2025-10-06 15:54:14 -04:00
enableDebug = true ;
// Hide drive letters from scan output (requires --scan)
2025-10-06 16:34:19 -04:00
else if ( HideDriveLettersInput . ProcessInput ( args , ref index ) )
2025-10-06 15:54:14 -04:00
hideDriveLetters = true ;
// Add filename suffix
2025-10-06 16:34:19 -04:00
else if ( SuffixInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . AddFilenameSuffix = ! Options . Processing . AddFilenameSuffix ;
2025-10-06 15:54:14 -04:00
// Output submission JSON
2025-10-06 16:34:19 -04:00
else if ( JsonInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . OutputSubmissionJSON = ! Options . Processing . OutputSubmissionJSON ;
2025-10-06 15:54:14 -04:00
// Include JSON artifacts
2025-10-06 16:34:19 -04:00
else if ( IncludeArtifactsInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . IncludeArtifacts = ! Options . Processing . IncludeArtifacts ;
2025-10-06 15:54:14 -04:00
// Compress log and extraneous files
2025-10-06 16:34:19 -04:00
else if ( ZipInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . CompressLogFiles = ! Options . Processing . CompressLogFiles ;
2025-10-06 15:54:14 -04:00
// Delete unnecessary files
2025-10-06 16:34:19 -04:00
else if ( DeleteInput . ProcessInput ( args , ref index ) )
2026-02-07 13:23:57 -05:00
Options . Processing . DeleteUnnecessaryFiles = ! Options . Processing . DeleteUnnecessaryFiles ;
2025-10-06 15:54:14 -04:00
// Default, add to inputs
else
Inputs . Add ( args [ index ] ) ;
}
// Now deal with the complex options
2026-02-07 13:23:57 -05:00
Options . Processing . ProtectionScanning . ScanForProtection = scan & & ! string . IsNullOrEmpty ( DevicePath ) ;
Options . Processing . ProtectionScanning . ScanArchivesForProtection = enableArchives & & scan & & ! string . IsNullOrEmpty ( DevicePath ) ;
Options . Processing . ProtectionScanning . IncludeDebugProtectionInformation = enableDebug & & scan & & ! string . IsNullOrEmpty ( DevicePath ) ;
Options . Processing . ProtectionScanning . HideDriveLetters = hideDriveLetters & & scan & & ! string . IsNullOrEmpty ( DevicePath ) ;
2025-10-06 15:54:14 -04:00
return true ;
}
/// <inheritdoc/>
2025-10-06 16:06:23 -04:00
public override bool VerifyInputs ( ) = > Inputs . Count > 0 ;
2025-10-06 15:54:14 -04:00
}
}