Clean up global temp, exe dir

This commit is contained in:
Matt Nadareski
2020-12-11 22:52:28 -08:00
parent fd3f28eb7c
commit 056b0634f0
13 changed files with 23 additions and 74 deletions

View File

@@ -353,6 +353,7 @@ namespace RombaSharp.Features
// General settings // General settings
internal static string _logdir; // Log folder location internal static string _logdir; // Log folder location
internal static string _tmpdir; // Temp folder location
internal static string _webdir; // Web frontend location internal static string _webdir; // Web frontend location
internal static string _baddir; // Fail-to-unpack file folder location internal static string _baddir; // Fail-to-unpack file folder location
internal static int _verbosity; // Verbosity of the output internal static int _verbosity; // Verbosity of the output
@@ -682,7 +683,7 @@ CREATE TABLE IF NOT EXISTS dat (
// Finally set all of the fields // Finally set all of the fields
Globals.MaxThreads = workers; Globals.MaxThreads = workers;
_logdir = logdir; _logdir = logdir;
Globals.TempDir = tmpdir; _tmpdir = tmpdir;
_webdir = webdir; _webdir = webdir;
_baddir = baddir; _baddir = baddir;
_verbosity = verbosity; _verbosity = verbosity;

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using SabreTools.Core;
using SabreTools.DatFiles; using SabreTools.DatFiles;
using SabreTools.DatTools; using SabreTools.DatTools;
using SabreTools.Help; using SabreTools.Help;
@@ -32,7 +31,7 @@ namespace RombaSharp.Features
Dictionary<string, string> foundDats = GetValidDats(Inputs); Dictionary<string, string> foundDats = GetValidDats(Inputs);
// Create the new output directory if it doesn't exist // 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 // Now that we have the dictionary, we can loop through and output to a new folder for each
foreach (string key in foundDats.Keys) foreach (string key in foundDats.Keys)

View File

@@ -6,6 +6,7 @@ using SabreTools.DatFiles;
using SabreTools.DatItems; using SabreTools.DatItems;
using SabreTools.DatTools; using SabreTools.DatTools;
using SabreTools.Help; using SabreTools.Help;
using SabreTools.IO;
using SabreTools.Logging; using SabreTools.Logging;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
@@ -54,7 +55,7 @@ contents of any changed dats.";
if (string.IsNullOrWhiteSpace(_dats)) if (string.IsNullOrWhiteSpace(_dats))
_dats = "dats"; _dats = "dats";
_dats = Path.Combine(Globals.ExeDir, _dats); _dats = Path.Combine(PathTool.GetRuntimeDirectory(), _dats);
// Make sure the folder exists // Make sure the folder exists
if (!Directory.Exists(_dats)) if (!Directory.Exists(_dats))

View File

@@ -1,6 +1,4 @@
using System; using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SabreTools.Core namespace SabreTools.Core
@@ -12,16 +10,6 @@ namespace SabreTools.Core
{ {
#region Public accessors #region Public accessors
/// <summary>
/// Directory path for the current executable
/// </summary>
public static string ExeDir => Path.GetDirectoryName(ExeName);
/// <summary>
/// File path for the current executable
/// </summary>
public static string ExeName => new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
/// <summary> /// <summary>
/// Maximum threads to use during parallel operations /// Maximum threads to use during parallel operations
/// </summary> /// </summary>
@@ -35,12 +23,6 @@ namespace SabreTools.Core
MaxDegreeOfParallelism = MaxThreads MaxDegreeOfParallelism = MaxThreads
}; };
/// <summary>
/// Temporary directory location
/// </summary>
/// <remarks>TODO: Find a way to get rid of this as a global variable and put it in DatFile</remarks>
public static string TempDir { get; set; } = Path.GetTempPath();
#endregion #endregion
} }
} }

View File

@@ -416,10 +416,6 @@ Options:
This can allow for more advanced set-building, especially in This can allow for more advanced set-building, especially in
arcade-based sets. 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 -out=, --output-dir= Set output directory
This sets an output folder to be used when the files are created. If 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. 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 Optionally, set the depth of input depots. Defaults to 4 deep
otherwise. 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 -out=, --output-dir= Set output directory
This sets an output folder to be used when the files are created. If 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. a path is not defined, the runtime directory is used instead.

View File

@@ -46,9 +46,6 @@ namespace SabreTools.DatTools
bool addBlanks = false, bool addBlanks = false,
Hash hashes = Hash.Standard) Hash hashes = Hash.Standard)
{ {
// Clean the temp directory path
Globals.TempDir = Globals.TempDir.Ensure(temp: true);
// Set the progress variables // Set the progress variables
long totalSize = 0; long totalSize = 0;
long currentSize = 0; long currentSize = 0;
@@ -92,14 +89,6 @@ namespace SabreTools.DatTools
logger.User(totalSize, totalSize, basePath); 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; return true;
} }

View File

@@ -16,18 +16,12 @@ namespace SabreTools.IO
/// </summary> /// </summary>
/// <param name="dir">Directory to check</param> /// <param name="dir">Directory to check</param>
/// <param name="create">True if the directory should be created, false otherwise (default)</param> /// <param name="create">True if the directory should be created, false otherwise (default)</param>
/// <param name="temp">True if this is a temp directory, false otherwise</param>
/// <returns>Full path to the directory</returns> /// <returns>Full path to the directory</returns>
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 the output directory is invalid
if (string.IsNullOrWhiteSpace(dir)) if (string.IsNullOrWhiteSpace(dir))
{ dir = PathTool.GetRuntimeDirectory();
if (temp)
dir = Path.GetTempPath();
else
dir = Environment.CurrentDirectory;
}
// Get the full path for the output directory // Get the full path for the output directory
dir = Path.GetFullPath(dir); dir = Path.GetFullPath(dir);

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using NaturalSort; using NaturalSort;
@@ -166,5 +168,14 @@ namespace SabreTools.IO
// Return the new list // Return the new list
return infiles; return infiles;
} }
/// <summary>
/// Get the current runtime directory
/// </summary>
public static string GetRuntimeDirectory()
{
string exeName = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
return Path.GetDirectoryName(exeName);
}
} }
} }

View File

@@ -2,7 +2,6 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
using SabreTools.Core;
using SabreTools.IO; using SabreTools.IO;
namespace SabreTools.Logging namespace SabreTools.Logging
@@ -28,7 +27,7 @@ namespace SabreTools.Logging
/// Optional output log directory /// Optional output log directory
/// </summary> /// </summary>
/// TODO: Make this either passed in or optional /// 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;
/// <summary> /// <summary>
/// Determines the lowest log level to output /// Determines the lowest log level to output

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using SabreTools.Core; using SabreTools.IO;
using SabreTools.Logging; using SabreTools.Logging;
namespace SabreTools.Skippers namespace SabreTools.Skippers
@@ -31,7 +31,7 @@ namespace SabreTools.Skippers
/// <summary> /// <summary>
/// Local paths /// Local paths
/// </summary> /// </summary>
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 #region Logging

View File

@@ -7,6 +7,7 @@ using SabreTools.Core.Tools;
using SabreTools.DatFiles; using SabreTools.DatFiles;
using SabreTools.Filtering; using SabreTools.Filtering;
using SabreTools.Help; using SabreTools.Help;
using SabreTools.IO;
using SabreTools.Logging; using SabreTools.Logging;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
@@ -73,7 +74,7 @@ namespace SabreTools.Features
#region Constants #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;"; public static string HeadererConnectionString = $"Data Source={HeadererFileName};Version = 3;";
#region Byte (1000-based) size comparisons #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<string>() { "-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 const string UrlStringValue = "url";
internal static Feature UrlStringInput internal static Feature UrlStringInput
{ {
@@ -2476,10 +2463,6 @@ Some special strings that can be used:
// Set threading flag, if necessary // Set threading flag, if necessary
if (features.ContainsKey(ThreadsInt32Value)) if (features.ContainsKey(ThreadsInt32Value))
Globals.MaxThreads = GetInt32(features, ThreadsInt32Value); Globals.MaxThreads = GetInt32(features, ThreadsInt32Value);
// Set temp path, if necessary
if (features.ContainsKey(TempStringValue))
Globals.TempDir = GetString(features, TempStringValue);
} }
#region Protected Specific Extraction #region Protected Specific Extraction

View File

@@ -49,7 +49,6 @@ namespace SabreTools.Features
AddFeature(HeaderStringInput); AddFeature(HeaderStringInput);
AddFeature(ExtraIniListInput); AddFeature(ExtraIniListInput);
AddFilteringFeatures(); AddFilteringFeatures();
AddFeature(TempStringInput);
AddFeature(OutputDirStringInput); AddFeature(OutputDirStringInput);
AddFeature(ThreadsInt32Input); AddFeature(ThreadsInt32Input);
} }

View File

@@ -25,7 +25,6 @@ namespace SabreTools.Features
AddFeature(DatListInput); AddFeature(DatListInput);
AddFeature(DepotFlag); AddFeature(DepotFlag);
this[DepotFlag].AddFeature(DepotDepthInt32Input); this[DepotFlag].AddFeature(DepotDepthInt32Input);
AddFeature(TempStringInput);
AddFeature(OutputDirStringInput); AddFeature(OutputDirStringInput);
AddFeature(HashOnlyFlag); AddFeature(HashOnlyFlag);
AddFeature(QuickFlag); AddFeature(QuickFlag);