Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add User Setting controlling Path Tokenization #3209

Merged
merged 3 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions doc/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,29 @@ To manually update the source use `winget source update`

The `visual` settings involve visual elements that are displayed by WinGet

### progressBar

Color of the progress bar that WinGet displays when not specified by arguments.

- accent (default)
- retro
- rainbow

```json
"visual": {
"progressBar": "accent"
},
```

### progressBar
### anonymizeDisplayedPaths

Color of the progress bar that WinGet displays when not specified by arguments.
Replaces some known folder paths with their respective environment variable. Defaults to true.

- accent (default)
- retro
- rainbow
```json
"visual": {
"anonymizeDisplayedPaths": true
},
```

## Install Behavior

Expand Down
5 changes: 5 additions & 0 deletions schemas/JSON/settings/settings.schema.0.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"rainbow",
"retro"
]
},
"anonymizeDisplayedPaths": {
"description": "Replaces some known folder paths with their respective environment variable",
"type": "boolean",
"default": true
}
}
},
Expand Down
40 changes: 40 additions & 0 deletions src/AppInstallerCLITests/UserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,46 @@ TEST_CASE("SettingProgressBar", "[settings]")
}
}

TEST_CASE("SettingsAnonymizePathForDisplay", "[settings]")
{
auto again = DeleteUserSettingsFiles();

SECTION("Default")
{
UserSettingsTest userSettingTest;

REQUIRE(userSettingTest.Get<Setting::AnonymizePathForDisplay>() == true);
REQUIRE(userSettingTest.GetWarnings().size() == 0);
}
SECTION("True")
{
std::string_view json = R"({ "visual": { "anonymizeDisplayedPaths": true } })";
SetSetting(Stream::PrimaryUserSettings, json);
UserSettingsTest userSettingTest;

REQUIRE(userSettingTest.Get<Setting::AnonymizePathForDisplay>() == true);
REQUIRE(userSettingTest.GetWarnings().size() == 0);
}
SECTION("False")
{
std::string_view json = R"({ "visual": { "anonymizeDisplayedPaths": false } })";
SetSetting(Stream::PrimaryUserSettings, json);
UserSettingsTest userSettingTest;

REQUIRE(userSettingTest.Get<Setting::AnonymizePathForDisplay>() == false);
REQUIRE(userSettingTest.GetWarnings().size() == 0);
}
SECTION("Invalid Value")
{
std::string_view json = R"({ "visual": { "anonymizeDisplayedPaths": "notBoolean" } })";
SetSetting(Stream::PrimaryUserSettings, json);
UserSettingsTest userSettingTest;

REQUIRE(userSettingTest.Get<Setting::AnonymizePathForDisplay>() == true);
REQUIRE(userSettingTest.GetWarnings().size() == 1);
}
}

TEST_CASE("SettingLoggingLevelPreference", "[settings]")
{
auto again = DeleteUserSettingsFiles();
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCommonCore/Public/winget/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace AppInstaller::Settings
{
// Visual
ProgressBarVisualStyle,
AnonymizePathForDisplay,
// Source
AutoUpdateTimeInMinutes,
// Experimental
Expand Down Expand Up @@ -135,6 +136,7 @@ namespace AppInstaller::Settings

// Visual
SETTINGMAPPING_SPECIALIZATION(Setting::ProgressBarVisualStyle, std::string, VisualStyle, VisualStyle::Accent, ".visual.progressBar"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::AnonymizePathForDisplay, bool, bool, true, ".visual.anonymizeDisplayedPaths"sv);
// Source
SETTINGMAPPING_SPECIALIZATION_POLICY(Setting::AutoUpdateTimeInMinutes, uint32_t, std::chrono::minutes, 5min, ".source.autoUpdateIntervalInMinutes"sv, ValuePolicy::SourceAutoUpdateIntervalInMinutes);
// Experimental
Expand Down
10 changes: 5 additions & 5 deletions src/AppInstallerCommonCore/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace AppInstaller::Runtime
// Gets the user's temp path
std::filesystem::path GetPathToUserTemp(bool forDisplay)
{
if (forDisplay)
if (forDisplay && Settings::User().Get<Setting::AnonymizePathForDisplay>())
{
return "%TEMP%";
}
Expand All @@ -133,7 +133,7 @@ namespace AppInstaller::Runtime
{
THROW_HR_IF(E_NOT_VALID_STATE, IsRunningInPackagedContext());

std::filesystem::path result = forDisplay ? s_LocalAppDataEnvironmentVariable : GetKnownFolderPath(FOLDERID_LocalAppData);
std::filesystem::path result = (forDisplay && Settings::User().Get<Setting::AnonymizePathForDisplay>()) ? s_LocalAppDataEnvironmentVariable : GetKnownFolderPath(FOLDERID_LocalAppData);
result /= "Microsoft/WinGet";

return result;
Expand Down Expand Up @@ -338,7 +338,7 @@ namespace AppInstaller::Runtime
switch (path)
{
case PathName::UserProfile:
result.Path = forDisplay ? s_UserProfileEnvironmentVariable : GetKnownFolderPath(FOLDERID_Profile);
result.Path = (forDisplay && Settings::User().Get<Setting::AnonymizePathForDisplay>()) ? s_UserProfileEnvironmentVariable : GetKnownFolderPath(FOLDERID_Profile);
result.Create = false;
break;
case PathName::PortablePackageUserRoot:
Expand Down Expand Up @@ -386,7 +386,7 @@ namespace AppInstaller::Runtime
THROW_HR(E_UNEXPECTED);
}

if (mayBeInProfilePath && forDisplay)
if (mayBeInProfilePath && forDisplay && Settings::User().Get<Setting::AnonymizePathForDisplay>())
{
ReplaceProfilePathsWithEnvironmentVariable(result.Path);
}
Expand Down Expand Up @@ -462,7 +462,7 @@ namespace AppInstaller::Runtime
THROW_HR(E_UNEXPECTED);
}

if (mayBeInProfilePath && forDisplay)
if (mayBeInProfilePath && forDisplay && Settings::User().Get<Setting::AnonymizePathForDisplay>())
{
ReplaceProfilePathsWithEnvironmentVariable(result.Path);
}
Expand Down
3 changes: 2 additions & 1 deletion src/AppInstallerCommonCore/UserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ namespace AppInstaller::Settings
WINGET_VALIDATE_PASS_THROUGH(EFUninstallPreviousArgument)
WINGET_VALIDATE_PASS_THROUGH(EFConfiguration)
WINGET_VALIDATE_PASS_THROUGH(EFWindowsFeature)
WINGET_VALIDATE_PASS_THROUGH(AnonymizePathForDisplay)
WINGET_VALIDATE_PASS_THROUGH(TelemetryDisable)
WINGET_VALIDATE_PASS_THROUGH(InteractivityDisable)
WINGET_VALIDATE_PASS_THROUGH(EnableSelfInitiatedMinidump)
Expand Down Expand Up @@ -572,7 +573,7 @@ namespace AppInstaller::Settings
{
auto path = Stream{ Stream::PrimaryUserSettings }.GetPath();

if (forDisplay)
if (forDisplay && Settings::User().Get<Setting::AnonymizePathForDisplay>())
{
ReplaceCommonPathPrefix(path, GetKnownFolderPath(FOLDERID_LocalAppData), "%LOCALAPPDATA%");
}
Expand Down