From 058a8a62182bf940d482113d55a15e90178144fc Mon Sep 17 00:00:00 2001 From: algernon-A Date: Sun, 2 Jul 2023 11:51:22 +1000 Subject: [PATCH] Add environment variable resolution to reporting and skipping filepaths. --- Changelog.txt | 1 + Code/Legacy/Settings.cs | 7 ++++--- Code/Settings/LSMRSettings.cs | 9 +++++---- Code/Settings/OptionsPanelTabs/GeneralOptions.cs | 14 ++++++++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 674a772..c41ba00 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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 diff --git a/Code/Legacy/Settings.cs b/Code/Legacy/Settings.cs index 520ed02..ab1ab4e 100644 --- a/Code/Legacy/Settings.cs +++ b/Code/Legacy/Settings.cs @@ -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; diff --git a/Code/Settings/LSMRSettings.cs b/Code/Settings/LSMRSettings.cs index 50dd1b3..97ef8f3 100644 --- a/Code/Settings/LSMRSettings.cs +++ b/Code/Settings/LSMRSettings.cs @@ -373,7 +373,7 @@ internal static string EnsureReportDirectory() Directory.CreateDirectory(s_reportsDirectory); } - return s_reportsDirectory; + return Environment.ExpandEnvironmentVariables(s_reportsDirectory); } catch (Exception e) { @@ -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"); } } } diff --git a/Code/Settings/OptionsPanelTabs/GeneralOptions.cs b/Code/Settings/OptionsPanelTabs/GeneralOptions.cs index 1e8b054..e7a5fe0 100644 --- a/Code/Settings/OptionsPanelTabs/GeneralOptions.cs +++ b/Code/Settings/OptionsPanelTabs/GeneralOptions.cs @@ -140,6 +140,8 @@ internal GeneralOptions(UITabstrip tabStrip, int tabIndex) /// private void OpenSkipFile() { + string skipFile; + try { // If string is null, reset it. @@ -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"); } @@ -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) {