Files

87 lines
2.7 KiB
C#
Raw Permalink Normal View History

2024-11-04 14:38:23 -05:00
using System;
using System.Collections.Generic;
2025-10-07 13:44:27 -04:00
using ProtectionScan.Features;
2025-10-06 09:43:15 -04:00
using SabreTools.CommandLine;
2025-10-07 13:44:27 -04:00
using SabreTools.CommandLine.Features;
2024-11-04 14:38:23 -05:00
namespace ProtectionScan
{
2025-10-07 13:44:27 -04:00
public static class Program
2024-11-04 14:38:23 -05:00
{
2025-10-07 13:44:27 -04:00
public static void Main(string[] args)
2024-11-04 14:38:23 -05:00
{
2025-09-06 15:38:36 -04:00
#if NET462_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER
2024-11-04 14:38:23 -05:00
// Register the codepages
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
2025-10-06 09:43:15 -04:00
// Create the command set
2025-10-07 13:44:27 -04:00
var mainFeature = new MainFeature();
var commandSet = CreateCommands(mainFeature);
2025-10-06 09:43:15 -04:00
// If we have no args, show the help and quit
2026-01-25 17:27:42 -05:00
if (args is null || args.Length == 0)
2025-10-06 09:43:15 -04:00
{
commandSet.OutputAllHelp();
return;
}
2025-10-07 13:44:27 -04:00
// Cache the first argument and starting index
string featureName = args[0];
2024-11-04 14:38:23 -05:00
2025-10-07 13:44:27 -04:00
// Try processing the standalone arguments
var topLevel = commandSet.GetTopLevel(featureName);
switch (topLevel)
2024-11-04 14:38:23 -05:00
{
2025-10-07 13:44:27 -04:00
// Standalone Options
case Help help: help.ProcessArgs(args, 0, commandSet); return;
// Default Behavior
default:
if (!mainFeature.ProcessArgs(args, 0))
{
commandSet.OutputAllHelp();
return;
}
else if (!mainFeature.VerifyInputs())
{
Console.Error.WriteLine("At least one input is required");
commandSet.OutputAllHelp();
return;
}
mainFeature.Execute();
break;
2024-11-04 14:38:23 -05:00
}
}
2025-10-06 09:43:15 -04:00
/// <summary>
/// Create the command set for the program
/// </summary>
2025-10-07 13:44:27 -04:00
private static CommandSet CreateCommands(MainFeature mainFeature)
2025-10-06 09:43:15 -04:00
{
List<string> header = [
"Protection Scanner",
string.Empty,
"ProtectionScan <options> file|directory ...",
string.Empty,
];
var commandSet = new CommandSet(header);
2025-10-07 13:44:27 -04:00
commandSet.Add(new Help(["-?", "-h", "--help"]));
commandSet.Add(mainFeature.DebugInput);
2025-11-13 13:59:25 -05:00
#if NETCOREAPP
commandSet.Add(mainFeature.JsonInput);
commandSet.Add(mainFeature.NestedInput);
#endif
2025-10-07 13:44:27 -04:00
commandSet.Add(mainFeature.NoContentsInput);
commandSet.Add(mainFeature.NoArchivesInput);
commandSet.Add(mainFeature.NoPathsInput);
commandSet.Add(mainFeature.NoSubdirsInput);
2025-10-06 09:43:15 -04:00
return commandSet;
}
2024-11-04 14:38:23 -05:00
}
}