From 36c81f24fbbc3473a3b1bbb214b8234a52740a1a Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 28 Mar 2024 13:11:36 -0700 Subject: [PATCH] Add a WT_SETTINGS_DIR env variable that portable profiles can use (#16949) Basically, title. It'd be a neat idea for portable installs of the Terminal to reference files that are right there in the portable install. This PR adds a `WT_SETTINGS_DIR` var to Terminal's own env block. This allows us to resolve profiles relative to our own settings folder. Closes #16295 --- src/cascadia/TerminalApp/AppLogic.cpp | 15 +++++++++++++++ src/cascadia/TerminalApp/AppLogic.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 29c13fdb13f..0b3ada01efa 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -149,6 +149,11 @@ namespace winrt::TerminalApp::implementation _languageProfileNotifier = winrt::make_self([this]() { _reloadSettings->Run(); }); + + // Do this here, rather than at the top of main. This will prevent us from + // including this variable in the vars we serialize in the + // Remoting::CommandlineArgs up in HandleCommandlineArgs. + _setupFolderPathEnvVar(); } // Method Description: @@ -720,4 +725,14 @@ namespace winrt::TerminalApp::implementation return TerminalApp::ParseCommandlineResult{ winrt::to_hstring(_appArgs.GetExitMessage()), r }; } + // Function Description + // * Adds a `WT_SETTINGS_DIR` env var to our own environment block, that + // points at our settings directory. This allows portable installs to + // refer to files in the portable install using %WT_SETTINGS_DIR% + void AppLogic::_setupFolderPathEnvVar() + { + std::wstring path{ CascadiaSettings::SettingsPath() }; + auto folderPath = path.substr(0, path.find_last_of(L"\\")); + SetEnvironmentVariableW(L"WT_SETTINGS_DIR", folderPath.c_str()); + } } diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index 4f735dc9b29..3c14a4bca41 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -112,6 +112,8 @@ namespace winrt::TerminalApp::implementation void _RegisterSettingsChange(); fire_and_forget _DispatchReloadSettings(); + void _setupFolderPathEnvVar(); + #ifdef UNIT_TESTING friend class TerminalAppLocalTests::CommandlineTest; #endif