mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Clean up global temp, exe dir
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<string, string> 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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <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>
|
||||
/// Maximum threads to use during parallel operations
|
||||
/// </summary>
|
||||
@@ -35,12 +23,6 @@ namespace SabreTools.Core
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,18 +16,12 @@ namespace SabreTools.IO
|
||||
/// </summary>
|
||||
/// <param name="dir">Directory to check</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>
|
||||
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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current runtime directory
|
||||
/// </summary>
|
||||
public static string GetRuntimeDirectory()
|
||||
{
|
||||
string exeName = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
|
||||
return Path.GetDirectoryName(exeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
/// 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>
|
||||
/// Determines the lowest log level to output
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Local paths
|
||||
/// </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
|
||||
|
||||
|
||||
@@ -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<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 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
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace SabreTools.Features
|
||||
AddFeature(HeaderStringInput);
|
||||
AddFeature(ExtraIniListInput);
|
||||
AddFilteringFeatures();
|
||||
AddFeature(TempStringInput);
|
||||
AddFeature(OutputDirStringInput);
|
||||
AddFeature(ThreadsInt32Input);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace SabreTools.Features
|
||||
AddFeature(DatListInput);
|
||||
AddFeature(DepotFlag);
|
||||
this[DepotFlag].AddFeature(DepotDepthInt32Input);
|
||||
AddFeature(TempStringInput);
|
||||
AddFeature(OutputDirStringInput);
|
||||
AddFeature(HashOnlyFlag);
|
||||
AddFeature(QuickFlag);
|
||||
|
||||
Reference in New Issue
Block a user