From a1b59eb2f3b11d625c3127eafcf144d41b83f0a0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 23 Oct 2024 22:10:55 -0400 Subject: [PATCH] Reduce unnecessary library calls --- Headerer/Features/BaseFeature.cs | 26 -------------------------- Headerer/Features/Extract.cs | 5 ++--- Headerer/Features/Restore.cs | 5 ++--- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/Headerer/Features/BaseFeature.cs b/Headerer/Features/BaseFeature.cs index 05e10958..b984eb3f 100644 --- a/Headerer/Features/BaseFeature.cs +++ b/Headerer/Features/BaseFeature.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.IO; using Microsoft.Data.Sqlite; -using SabreTools.Core; using SabreTools.Core.Tools; using SabreTools.Help; using SabreTools.IO; @@ -61,24 +60,6 @@ namespace Headerer.Features #endregion - #region Int32 features - - internal const string ThreadsInt32Value = "threads"; - internal static Feature ThreadsInt32Input - { - get - { - return new Feature( - ThreadsInt32Value, - new List() { "-mt", "--threads" }, - "Amount of threads to use (default = # cores)", - ParameterType.Int32, - longDescription: "Optionally, set the number of threads to use for the multithreaded operations. The default is the number of available machine threads; -1 means unlimited threads created."); - } - } - - #endregion - #region String features internal const string LogLevelStringValue = "log-level"; @@ -142,22 +123,15 @@ Possible values are: Verbose, User, Warning, Error"); { AddFeature(ScriptFlag); AddFeature(LogLevelStringInput); - AddFeature(ThreadsInt32Input); } #endregion public override bool ProcessFeatures(Dictionary features) { - // Generic feature flags LogLevel = GetString(features, LogLevelStringValue).AsLogLevel(); OutputDir = GetString(features, OutputDirStringValue)?.Trim('"'); ScriptMode = GetBoolean(features, ScriptValue); - - // Set threading flag, if necessary - if (features.ContainsKey(ThreadsInt32Value)) - Globals.MaxThreads = GetInt32(features, ThreadsInt32Value); - return true; } diff --git a/Headerer/Features/Extract.cs b/Headerer/Features/Extract.cs index 203fdd15..2533e80e 100644 --- a/Headerer/Features/Extract.cs +++ b/Headerer/Features/Extract.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using Microsoft.Data.Sqlite; using SabreTools.Core.Tools; -using SabreTools.FileTypes; using SabreTools.Hashing; using SabreTools.Help; using SabreTools.IO; @@ -110,8 +109,8 @@ The following systems have headers that this program can work with: // Now add the information to the database if it's not already there if (!nostore) { - BaseFile? baseFile = BaseFile.GetInfo(newfile, hashes: [HashType.SHA1], asFiles: TreatAsFile.NonArchive); - AddHeaderToDatabase(hstr, TextHelper.ByteArrayToString(baseFile!.SHA1)!, rule.SourceFile!); + string sha1 = HashTool.GetFileHash(newfile, HashType.SHA1) ?? string.Empty; + AddHeaderToDatabase(hstr, sha1, rule.SourceFile!); } return true; diff --git a/Headerer/Features/Restore.cs b/Headerer/Features/Restore.cs index 9019b7a6..10356078 100644 --- a/Headerer/Features/Restore.cs +++ b/Headerer/Features/Restore.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using Microsoft.Data.Sqlite; using SabreTools.Core.Tools; -using SabreTools.FileTypes; using SabreTools.Hashing; using SabreTools.Help; using SabreTools.IO; @@ -66,10 +65,10 @@ The following systems have headers that this program can work with: Directory.CreateDirectory(outDir); // First, get the SHA-1 hash of the file - BaseFile? baseFile = BaseFile.GetInfo(file, hashes: [HashType.SHA1], asFiles: TreatAsFile.NonArchive); + string sha1 = HashTool.GetFileHash(file, HashType.SHA1) ?? string.Empty; // Retrieve a list of all related headers from the database - List headers = RetrieveHeadersFromDatabase(TextHelper.ByteArrayToString(baseFile!.SHA1)!); + List headers = RetrieveHeadersFromDatabase(sha1); // If we have nothing retrieved, we return false if (headers.Count == 0)