diff --git a/RombaSharp/Features/BaseFeature.cs b/RombaSharp/Features/BaseFeature.cs index 598e4ef9..8931f8fd 100644 --- a/RombaSharp/Features/BaseFeature.cs +++ b/RombaSharp/Features/BaseFeature.cs @@ -353,6 +353,7 @@ namespace RombaSharp.Features // General settings internal static string _logdir; // Log folder location + internal static string _tmpdir; // Temp folder location internal static string _webdir; // Web frontend location internal static string _baddir; // Fail-to-unpack file folder location internal static int _verbosity; // Verbosity of the output @@ -682,7 +683,7 @@ CREATE TABLE IF NOT EXISTS dat ( // Finally set all of the fields Globals.MaxThreads = workers; _logdir = logdir; - Globals.TempDir = tmpdir; + _tmpdir = tmpdir; _webdir = webdir; _baddir = baddir; _verbosity = verbosity; diff --git a/RombaSharp/Features/Miss.cs b/RombaSharp/Features/Miss.cs index b7c1398f..2b0eba55 100644 --- a/RombaSharp/Features/Miss.cs +++ b/RombaSharp/Features/Miss.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.IO; -using SabreTools.Core; using SabreTools.DatFiles; using SabreTools.DatTools; using SabreTools.Help; @@ -32,7 +31,7 @@ namespace RombaSharp.Features Dictionary foundDats = GetValidDats(Inputs); // Create the new output directory if it doesn't exist - Path.Combine(Globals.ExeDir, "out").Ensure(create: true); + Path.Combine(PathTool.GetRuntimeDirectory(), "out").Ensure(create: true); // Now that we have the dictionary, we can loop through and output to a new folder for each foreach (string key in foundDats.Keys) diff --git a/RombaSharp/Features/RefreshDats.cs b/RombaSharp/Features/RefreshDats.cs index 4b0dba82..6cb07222 100644 --- a/RombaSharp/Features/RefreshDats.cs +++ b/RombaSharp/Features/RefreshDats.cs @@ -6,6 +6,7 @@ using SabreTools.DatFiles; using SabreTools.DatItems; using SabreTools.DatTools; using SabreTools.Help; +using SabreTools.IO; using SabreTools.Logging; using Microsoft.Data.Sqlite; @@ -54,7 +55,7 @@ contents of any changed dats."; if (string.IsNullOrWhiteSpace(_dats)) _dats = "dats"; - _dats = Path.Combine(Globals.ExeDir, _dats); + _dats = Path.Combine(PathTool.GetRuntimeDirectory(), _dats); // Make sure the folder exists if (!Directory.Exists(_dats)) diff --git a/SabreTools.Core/Globals.cs b/SabreTools.Core/Globals.cs index 9206765a..d99bcbcf 100644 --- a/SabreTools.Core/Globals.cs +++ b/SabreTools.Core/Globals.cs @@ -1,6 +1,4 @@ using System; -using System.IO; -using System.Reflection; using System.Threading.Tasks; namespace SabreTools.Core @@ -12,16 +10,6 @@ namespace SabreTools.Core { #region Public accessors - /// - /// Directory path for the current executable - /// - public static string ExeDir => Path.GetDirectoryName(ExeName); - - /// - /// File path for the current executable - /// - public static string ExeName => new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; - /// /// Maximum threads to use during parallel operations /// @@ -35,12 +23,6 @@ namespace SabreTools.Core MaxDegreeOfParallelism = MaxThreads }; - /// - /// Temporary directory location - /// - /// TODO: Find a way to get rid of this as a global variable and put it in DatFile - public static string TempDir { get; set; } = Path.GetTempPath(); - #endregion } } diff --git a/SabreTools.Core/README.1ST b/SabreTools.Core/README.1ST index fec76727..964c4da8 100644 --- a/SabreTools.Core/README.1ST +++ b/SabreTools.Core/README.1ST @@ -416,10 +416,6 @@ Options: This can allow for more advanced set-building, especially in arcade-based sets. - -t=, --temp= Set the temporary directory to use - Optionally, a temp folder can be supplied in the case the default - temp directory is not preferred. - -out=, --output-dir= Set output directory This sets an output folder to be used when the files are created. If a path is not defined, the runtime directory is used instead. @@ -1183,10 +1179,6 @@ Options: Optionally, set the depth of input depots. Defaults to 4 deep otherwise. - -t=, --temp= Set the temporary directory to use - Optionally, a temp folder can be supplied in the case the default - temp directory is not preferred. - -out=, --output-dir= Set output directory This sets an output folder to be used when the files are created. If a path is not defined, the runtime directory is used instead. diff --git a/SabreTools.DatTools/DatFromDir.cs b/SabreTools.DatTools/DatFromDir.cs index 05f1fac8..6b96e4bb 100644 --- a/SabreTools.DatTools/DatFromDir.cs +++ b/SabreTools.DatTools/DatFromDir.cs @@ -46,9 +46,6 @@ namespace SabreTools.DatTools bool addBlanks = false, Hash hashes = Hash.Standard) { - // Clean the temp directory path - Globals.TempDir = Globals.TempDir.Ensure(temp: true); - // Set the progress variables long totalSize = 0; long currentSize = 0; @@ -92,14 +89,6 @@ namespace SabreTools.DatTools logger.User(totalSize, totalSize, basePath); } - // Now that we're done, delete the temp folder (if it's not the default) - logger.User("Cleaning temp folder"); - if (Globals.TempDir != Path.GetTempPath()) - { - if (Directory.Exists(Globals.TempDir)) - Directory.Delete(Globals.TempDir, true); - } - return true; } diff --git a/SabreTools.IO/IOExtensions.cs b/SabreTools.IO/IOExtensions.cs index 8328ec43..8af96416 100644 --- a/SabreTools.IO/IOExtensions.cs +++ b/SabreTools.IO/IOExtensions.cs @@ -16,18 +16,12 @@ namespace SabreTools.IO /// /// Directory to check /// True if the directory should be created, false otherwise (default) - /// True if this is a temp directory, false otherwise /// Full path to the directory - public static string Ensure(this string dir, bool create = false, bool temp = false) + public static string Ensure(this string dir, bool create = false) { // If the output directory is invalid if (string.IsNullOrWhiteSpace(dir)) - { - if (temp) - dir = Path.GetTempPath(); - else - dir = Environment.CurrentDirectory; - } + dir = PathTool.GetRuntimeDirectory(); // Get the full path for the output directory dir = Path.GetFullPath(dir); diff --git a/SabreTools.IO/PathTool.cs b/SabreTools.IO/PathTool.cs index 37ca2bf6..51d3f997 100644 --- a/SabreTools.IO/PathTool.cs +++ b/SabreTools.IO/PathTool.cs @@ -1,6 +1,8 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using NaturalSort; @@ -166,5 +168,14 @@ namespace SabreTools.IO // Return the new list return infiles; } + + /// + /// Get the current runtime directory + /// + public static string GetRuntimeDirectory() + { + string exeName = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; + return Path.GetDirectoryName(exeName); + } } } diff --git a/SabreTools.Logging/LoggerImpl.cs b/SabreTools.Logging/LoggerImpl.cs index 47b03e22..0ff36c1a 100644 --- a/SabreTools.Logging/LoggerImpl.cs +++ b/SabreTools.Logging/LoggerImpl.cs @@ -2,7 +2,6 @@ using System.IO; using System.Text; -using SabreTools.Core; using SabreTools.IO; namespace SabreTools.Logging @@ -28,7 +27,7 @@ namespace SabreTools.Logging /// Optional output log directory /// /// TODO: Make this either passed in or optional - public static string LogDirectory { get; set; } = Path.Combine(Globals.ExeDir, "logs") + Path.DirectorySeparatorChar; + public static string LogDirectory { get; set; } = Path.Combine(PathTool.GetRuntimeDirectory(), "logs") + Path.DirectorySeparatorChar; /// /// Determines the lowest log level to output diff --git a/SabreTools.Skippers/SkipperMatch.cs b/SabreTools.Skippers/SkipperMatch.cs index 3c4f6c5e..80a2cfd2 100644 --- a/SabreTools.Skippers/SkipperMatch.cs +++ b/SabreTools.Skippers/SkipperMatch.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.IO; -using SabreTools.Core; +using SabreTools.IO; using SabreTools.Logging; namespace SabreTools.Skippers @@ -31,7 +31,7 @@ namespace SabreTools.Skippers /// /// Local paths /// - private static readonly string LocalPath = Path.Combine(Globals.ExeDir, "Skippers") + Path.DirectorySeparatorChar; + private static readonly string LocalPath = Path.Combine(PathTool.GetRuntimeDirectory(), "Skippers") + Path.DirectorySeparatorChar; #region Logging diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index e02f4bf0..5c3446b0 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -7,6 +7,7 @@ using SabreTools.Core.Tools; using SabreTools.DatFiles; using SabreTools.Filtering; using SabreTools.Help; +using SabreTools.IO; using SabreTools.Logging; using Microsoft.Data.Sqlite; @@ -73,7 +74,7 @@ namespace SabreTools.Features #region Constants - public static string HeadererFileName = Path.Combine(Globals.ExeDir, "Headerer.sqlite"); + public static string HeadererFileName = Path.Combine(PathTool.GetRuntimeDirectory(), "Headerer.sqlite"); public static string HeadererConnectionString = $"Data Source={HeadererFileName};Version = 3;"; #region Byte (1000-based) size comparisons @@ -2297,20 +2298,6 @@ Some special strings that can be used: } } - internal const string TempStringValue = "temp"; - internal static Feature TempStringInput - { - get - { - return new Feature( - TempStringValue, - new List() { "-t", "--temp" }, - "Set the temporary directory to use", - ParameterType.String, - longDescription: "Optionally, a temp folder can be supplied in the case the default temp directory is not preferred."); - } - } - internal const string UrlStringValue = "url"; internal static Feature UrlStringInput { @@ -2476,10 +2463,6 @@ Some special strings that can be used: // Set threading flag, if necessary if (features.ContainsKey(ThreadsInt32Value)) Globals.MaxThreads = GetInt32(features, ThreadsInt32Value); - - // Set temp path, if necessary - if (features.ContainsKey(TempStringValue)) - Globals.TempDir = GetString(features, TempStringValue); } #region Protected Specific Extraction diff --git a/SabreTools/Features/DatFromDir.cs b/SabreTools/Features/DatFromDir.cs index d936eac0..2e192805 100644 --- a/SabreTools/Features/DatFromDir.cs +++ b/SabreTools/Features/DatFromDir.cs @@ -49,7 +49,6 @@ namespace SabreTools.Features AddFeature(HeaderStringInput); AddFeature(ExtraIniListInput); AddFilteringFeatures(); - AddFeature(TempStringInput); AddFeature(OutputDirStringInput); AddFeature(ThreadsInt32Input); } diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index 0f680ced..4acb0ec9 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -25,7 +25,6 @@ namespace SabreTools.Features AddFeature(DatListInput); AddFeature(DepotFlag); this[DepotFlag].AddFeature(DepotDepthInt32Input); - AddFeature(TempStringInput); AddFeature(OutputDirStringInput); AddFeature(HashOnlyFlag); AddFeature(QuickFlag);