Reduce unnecessary library calls

This commit is contained in:
Matt Nadareski
2024-10-23 22:10:55 -04:00
parent 1f0637cc91
commit a1b59eb2f3
3 changed files with 4 additions and 32 deletions

View File

@@ -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<string>() { "-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<string, Feature?> 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;
}

View File

@@ -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;

View File

@@ -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<string> headers = RetrieveHeadersFromDatabase(TextHelper.ByteArrayToString(baseFile!.SHA1)!);
List<string> headers = RetrieveHeadersFromDatabase(sha1);
// If we have nothing retrieved, we return false
if (headers.Count == 0)