Add option for copy protection file output (fixes #372)

This commit is contained in:
Matt Nadareski
2022-04-10 22:12:20 -07:00
parent 87c441887a
commit 58c53ff5e2
7 changed files with 75 additions and 4 deletions

View File

@@ -45,6 +45,7 @@
- Explicitly sanitize '?' from path
- Combine cases in protection scan
- Convert status label to TextBlock
- Add option for copy protection file output
### 2.3 (2022-02-05)
- Start overhauling Redump information pulling, again

View File

@@ -69,7 +69,7 @@ namespace MPF.Check
string username = null, password = null;
string internalProgram = "DiscImageCreator";
string path = string.Empty;
bool scan = false, compress = false, json = false;
bool scan = false, protectFile = false, compress = false, json = false;
// Loop through and process options
int startIndex = 2;
@@ -117,6 +117,12 @@ namespace MPF.Check
scan = true;
}
// Output protection to separate file (requires scan for protection)
else if (args[startIndex].Equals("-f") || args[startIndex].Equals("--protect-file"))
{
protectFile = true;
}
// Output submission JSON
else if (args[startIndex].Equals("-j") || args[startIndex].Equals("--json"))
{
@@ -175,6 +181,7 @@ namespace MPF.Check
{
InternalProgram = EnumConverter.ToInternalProgram(internalProgram),
ScanForProtection = scan && !string.IsNullOrWhiteSpace(path),
OutputSeparateProtectionFile = scan && protectFile && !string.IsNullOrWhiteSpace(path),
PromptForDiscInformation = false,
ShowDiscEjectReminder = false,
OutputSubmissionJSON = json,
@@ -219,6 +226,7 @@ namespace MPF.Check
Console.WriteLine("-u, --use <program> Dumping program output type");
Console.WriteLine("-p, --path <drivepath> Physical drive path for additional checks");
Console.WriteLine("-s, --scan Enable copy protection scan (requires --path)");
Console.WriteLine("-f, --protect-file Output protection to separate file (requires --scan)");
Console.WriteLine("-j, --json Enable submission JSON output");
Console.WriteLine("-z, --zip Enable log file compression");
Console.WriteLine();

View File

@@ -288,6 +288,15 @@ namespace MPF.Core.Data
set { _settings["ScanForProtection"] = value.ToString(); }
}
/// <summary>
/// Output all found protections to a separate file in the directory
/// </summary>
public bool OutputSeparateProtectionFile
{
get { return GetBooleanSetting(_settings, "OutputSeparateProtectionFile", false); }
set { _settings["OutputSeparateProtectionFile"] = value.ToString(); }
}
/// <summary>
/// Add placeholder values in the submission info
/// </summary>

View File

@@ -373,6 +373,17 @@ namespace MPF.Library
else
resultProgress?.Report(Result.Failure("Writing could not complete!"));
// Write the copy protection output
if (Options.ScanForProtection && Options.OutputSeparateProtectionFile)
{
resultProgress?.Report(Result.Success("Writing protection to !protectionInfo.txt..."));
success = InfoTool.WriteProtectionData(this.OutputDirectory, submissionInfo);
if (success)
resultProgress?.Report(Result.Success("Writing complete!"));
else
resultProgress?.Report(Result.Failure("Writing could not complete!"));
}
// Write the JSON output, if required
if (Options.OutputSubmissionJSON)
{

View File

@@ -234,8 +234,9 @@ namespace MPF.Library
case RedumpSystem.PocketPC:
case RedumpSystem.RainbowDisc:
resultProgress?.Report(Result.Success("Running copy protection scan... this might take a while!"));
(string protectionString, Dictionary<string, List<string>> _) = await GetCopyProtection(drive, options, protectionProgress);
(string protectionString, Dictionary<string, List<string>> fullProtections) = await GetCopyProtection(drive, options, protectionProgress);
info.CopyProtection.Protection = protectionString;
info.CopyProtection.FullProtections = fullProtections;
resultProgress?.Report(Result.Success("Copy protection scan complete!"));
break;
@@ -1009,6 +1010,38 @@ namespace MPF.Library
return true;
}
/// <summary>
/// Write the protection data to the output folder
/// </summary>
/// <param name="outputDirectory">Output folder to write to</param>
/// <param name="info">SubmissionInfo object containing the protection information</param>
/// <returns>True on success, false on error</returns>
public static bool WriteProtectionData(string outputDirectory, SubmissionInfo info)
{
// Check to see if the inputs are valid
if (info?.CopyProtection?.FullProtections == null || !info.CopyProtection.FullProtections.Any())
return true;
// Now write out to a generic file
try
{
using (StreamWriter sw = new StreamWriter(File.Open(Path.Combine(outputDirectory, "!protectionInfo.txt"), FileMode.Create, FileAccess.Write)))
{
foreach (var kvp in info.CopyProtection.FullProtections)
{
sw.WriteLine($"{kvp.Key}: {string.Join(", ", kvp.Value)}");
}
}
}
catch (Exception ex)
{
// We don't care what the error is right now
return false;
}
return true;
}
/// <summary>
/// Add the properly formatted key and value, if possible
/// </summary>

View File

@@ -123,7 +123,7 @@
<TabItem Header="Dumping" Style="{DynamicResource CustomTabItemStyle}">
<StackPanel>
<GroupBox Margin="5,5,5,5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Header="Dumping">
<UniformGrid Columns="2" Rows="8">
<UniformGrid Columns="2" Rows="9">
<CheckBox VerticalAlignment="Center" Content="Skip Type Detect"
IsChecked="{Binding Options.SkipMediaTypeDetection}"
ToolTip="Disable trying to guess media type inserted (may improve performance at startup)" Margin="0,4"
@@ -162,6 +162,11 @@
ToolTip="Enable automatic checking for copy protection on dumped media" Margin="0,4,0,0"
/>
<CheckBox VerticalAlignment="Center" Content="Protection File"
IsChecked="{Binding Options.OutputSeparateProtectionFile}" IsEnabled="{Binding Options.ScanForProtection}"
ToolTip="Output protection information to a separate file" Margin="0,4,0,0"
/>
<CheckBox VerticalAlignment="Center" Content="Eject After Dump"
IsChecked="{Binding Options.EjectAfterDump}"
ToolTip="Eject the disc from the drive after dumping has completed" Margin="0,4"
@@ -198,7 +203,7 @@
/>
<CheckBox VerticalAlignment="Center" Content="Include Artifacts"
IsChecked="{Binding Options.IncludeArtifacts}" IsEnabled="{Binding Options.OutputSubmissionJSON}"
IsChecked="{Binding Options.IncludeArtifacts}" IsEnabled="{Binding Options.OutputSubmissionJSON}"
ToolTip="Include log files in serialized JSON data" Margin="0,4"
/>

View File

@@ -402,6 +402,9 @@ namespace RedumpLib.Data
[JsonProperty(PropertyName = "d_protection", NullValueHandling = NullValueHandling.Ignore)]
public string Protection { get; set; }
[JsonIgnore]
public Dictionary<string, List<string>> FullProtections { get; set; }
[JsonProperty(PropertyName = "d_securom", NullValueHandling = NullValueHandling.Ignore)]
public string SecuROMData { get; set; }
@@ -413,6 +416,7 @@ namespace RedumpLib.Data
LibCrypt = this.LibCrypt,
LibCryptData = this.LibCryptData,
Protection = this.Protection,
FullProtections = this.FullProtections.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
SecuROMData = this.SecuROMData,
};
}