mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-05-06 20:43:44 +00:00
Make the test executable a bit nicer
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BurnOutSharp;
|
||||
@@ -22,45 +23,72 @@ namespace Test
|
||||
ScanPackers = true,
|
||||
};
|
||||
|
||||
// Loop through the input paths
|
||||
foreach (string arg in args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var protections = scanner.GetProtections(arg);
|
||||
if (protections != null)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
|
||||
{
|
||||
foreach (string key in protections.Keys)
|
||||
{
|
||||
// Skip over files with no protection
|
||||
if (protections[key] == null || !protections[key].Any())
|
||||
continue;
|
||||
|
||||
string line = $"{key}: {string.Join(", ", protections[key])}";
|
||||
Console.WriteLine(line);
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"No protections found for {arg}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}-exception.txt")))
|
||||
{
|
||||
sw.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
GetAndWriteProtections(scanner, arg);
|
||||
}
|
||||
|
||||
Console.WriteLine("Press any button to close...");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper to get and log protections for a single path
|
||||
/// </summary>
|
||||
/// <param name="scanner">Scanner object to use</param>
|
||||
/// <param name="path">File or directory path</param>
|
||||
private static void GetAndWriteProtections(Scanner scanner, string path)
|
||||
{
|
||||
// An invalid path can't be scanned
|
||||
if (!Directory.Exists(path) && !File.Exists(path))
|
||||
{
|
||||
Console.WriteLine($"{path} does not exist, skipping...");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var protections = scanner.GetProtections(path);
|
||||
WriteProtectionResultFile(path, protections);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}-exception.txt")))
|
||||
{
|
||||
sw.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write the protection results from a single path to file, if possible
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
/// <param name="protections">Dictionary of protections found, if any</param>
|
||||
private static void WriteProtectionResultFile(string path, Dictionary<string, List<string>> protections)
|
||||
{
|
||||
if (protections == null)
|
||||
{
|
||||
Console.WriteLine($"No protections found for {path}");
|
||||
return;
|
||||
}
|
||||
|
||||
using (var sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
|
||||
{
|
||||
foreach (string key in protections.Keys)
|
||||
{
|
||||
// Skip over files with no protection
|
||||
if (protections[key] == null || !protections[key].Any())
|
||||
continue;
|
||||
|
||||
string line = $"{key}: {string.Join(", ", protections[key])}";
|
||||
Console.WriteLine(line);
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Changed(object source, ProtectionProgress value)
|
||||
{
|
||||
Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}");
|
||||
|
||||
Reference in New Issue
Block a user