using System; using System.Collections.Concurrent; using System.IO; using System.Linq; using BurnOutSharp; namespace Test { class Program { static void Main(string[] args) { // Create progress indicator var p = new Progress(); p.ProgressChanged += Changed; // Create scanner for all paths var scanner = new Scanner(p) { IncludeDebug = true, ScanAllFiles = false, ScanArchives = true, ScanPackers = true, }; // Loop through the input paths foreach (string arg in args) { GetAndWriteProtections(scanner, arg); } Console.WriteLine("Press enter to close the program..."); Console.ReadLine(); } /// /// Wrapper to get and log protections for a single path /// /// Scanner object to use /// File or directory path 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); } } } /// /// Write the protection results from a single path to file, if possible /// /// File or directory path /// Dictionary of protections found, if any private static void WriteProtectionResultFile(string path, ConcurrentDictionary> 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.OrderBy(k => k)) { // Skip over files with no protection if (protections[key] == null || !protections[key].Any()) continue; string line = $"{key}: {string.Join(", ", protections[key].OrderBy(p => p))}"; Console.WriteLine(line); sw.WriteLine(line); } } } /// /// Protection progress changed handler /// private static void Changed(object source, ProtectionProgress value) { Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}"); } } }