Skip to content

Commit

Permalink
Add environment variable resolution to reporting and skipping filepaths.
Browse files Browse the repository at this point in the history
  • Loading branch information
algernon-A committed Jul 2, 2023
1 parent 7266436 commit 058a8a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Version 1.1.8 -

- Add environment variable resolution to reporting and skipping filepaths
- Exclude BOB and Procedural Objects templates from being reported as unused assets


Expand Down
7 changes: 4 additions & 3 deletions Code/Legacy/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ internal static DateTime LoadSkipFile()
{
if (LoadingScreenModRevisited.LSMRSettings.SkipPrefabs)
{
bool flag = File.Exists(LoadingScreenModRevisited.LSMRSettings.SkipFile);
string skipFile = Environment.ExpandEnvironmentVariables(LoadingScreenModRevisited.LSMRSettings.SkipFile);
bool flag = File.Exists(skipFile);
DateTime lastWriteTimeUtc;
if (flag && LoadingScreenModRevisited.LSMRSettings.SkipFileTimestamp != (lastWriteTimeUtc = File.GetLastWriteTimeUtc(LoadingScreenModRevisited.LSMRSettings.SkipFile)))
if (flag && LoadingScreenModRevisited.LSMRSettings.SkipFileTimestamp != (lastWriteTimeUtc = File.GetLastWriteTimeUtc(skipFile)))
{
LoadingScreenModRevisited.Skipping[] array = LoadingScreenModRevisited.Skipping.Load(LoadingScreenModRevisited.LSMRSettings.SkipFile);
LoadingScreenModRevisited.Skipping[] array = LoadingScreenModRevisited.Skipping.Load(skipFile);
SkipMatcher = array[0];
ExceptMatcher = array[1];
LoadingScreenModRevisited.LSMRSettings.SkipFileTimestamp = lastWriteTimeUtc;
Expand Down
9 changes: 5 additions & 4 deletions Code/Settings/LSMRSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ internal static string EnsureReportDirectory()
Directory.CreateDirectory(s_reportsDirectory);
}

return s_reportsDirectory;
return Environment.ExpandEnvironmentVariables(s_reportsDirectory);
}
catch (Exception e)
{
Expand Down Expand Up @@ -423,16 +423,17 @@ internal static void OpenHideFile()
internal static void OpenReportDirectory()
{
// Check to see if the directory already exists.
if (Directory.Exists(s_reportsDirectory))
string reportsDirectory = Environment.ExpandEnvironmentVariables(s_reportsDirectory);
if (Directory.Exists(reportsDirectory))
{
// Open it.
try
{
Process.Start(s_reportsDirectory);
Process.Start(reportsDirectory);
}
catch (Exception e)
{
Logging.LogException(e, "exception opening reports directory ", s_reportsDirectory ?? "null");
Logging.LogException(e, "exception opening reports directory ", reportsDirectory ?? "null");
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions Code/Settings/OptionsPanelTabs/GeneralOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ internal GeneralOptions(UITabstrip tabStrip, int tabIndex)
/// </summary>
private void OpenSkipFile()
{
string skipFile;

try
{
// If string is null, reset it.
Expand All @@ -151,17 +153,20 @@ private void OpenSkipFile()
_skipFileTextField.text = LSMRSettings.SkipFile;
}

// Resolve environment variabiles.
skipFile = Environment.ExpandEnvironmentVariables(LSMRSettings.SkipFile);

// Create directory if it doesn't already exist.
string directoryName = Path.GetDirectoryName(LSMRSettings.SkipFile);
string directoryName = Path.GetDirectoryName(skipFile);
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}

// Create file if it doesn't already exist.
if (!File.Exists(LSMRSettings.SkipFile))
if (!File.Exists(skipFile))
{
using (StreamWriter writer = new StreamWriter(LSMRSettings.SkipFile))
using (StreamWriter writer = new StreamWriter(skipFile))
{
writer.Write("# Loading Screen Mod skip file");
}
Expand All @@ -170,12 +175,13 @@ private void OpenSkipFile()
catch (Exception e)
{
Logging.LogException(e, "exception creating skip file ", LSMRSettings.SkipFile);
return;
}

// Open the file.
try
{
Process.Start(LSMRSettings.SkipFile);
Process.Start(skipFile);
}
catch (Exception e)
{
Expand Down

0 comments on commit 058a8a6

Please sign in to comment.