Skip to content

Commit e0d4256

Browse files
committed
Improve file setting stream handling
1 parent 0d8e4bb commit e0d4256

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

src/AppInstallerCLITests/Settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ TEST_CASE("SetAndReadSettingEncrypted", "[settings]")
297297
REQUIRE(value == settingValue);
298298

299299
// Ensure that the data is encrypted
300-
name.Type = Type::Standard;
300+
name.Type = Type::StandardFile;
301301

302302
Stream streamDirect{ name };
303303

src/AppInstallerCommonCore/Public/AppInstallerRuntime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ namespace AppInstaller::Runtime
6464
FontsUserInstallLocation,
6565
// The location where fonts are installed with machine scope.
6666
FontsMachineInstallLocation,
67-
// The temporary file location; only valid when running packaged.
68-
PackagedTemp,
67+
// The location that standard type settings are stored in files.
68+
StandardFileSettings,
6969
// Always one more than the last path; for being able to iterate paths in tests.
7070
Max
7171
};

src/AppInstallerCommonCore/Public/winget/Settings.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ namespace AppInstaller::Settings
3636
// Names should still be unique, as there is no guarantee made about types mapping to unique roots.
3737
enum class Type
3838
{
39-
// A Standard setting stream has no special requirements.
39+
// A Standard setting stream has no special requirements (limited to 8K contents and no embedded null characters).
4040
Standard,
4141
// A UserFile setting stream should be located in a file that is easily editable by the user.
4242
UserFile,
4343
// A settings stream that should not be modified except by admin privileges.
4444
Secure,
4545
// A settings stream that is encrypted. It does not require admin privileges to write to.
4646
Encrypted,
47+
// A setting stream has should be stored in a file, removing the limitations of the Standard type.
48+
StandardFile,
4749
};
4850

4951
// Converts the Type enum to a string.

src/AppInstallerCommonCore/Runtime.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace AppInstaller::Runtime
2222
{
2323
using namespace std::string_view_literals;
2424
constexpr std::string_view s_DefaultTempDirectory = "WinGet"sv;
25+
constexpr std::string_view s_SettingsFile_Relative = "Settings"sv;
2526
constexpr std::string_view s_SecureSettings_Base = "Microsoft\\WinGet"sv;
2627
constexpr std::string_view s_SecureSettings_UserRelative = "settings"sv;
2728
constexpr std::string_view s_SecureSettings_Relative_Unpackaged = "win"sv;
@@ -288,9 +289,9 @@ namespace AppInstaller::Runtime
288289
result.Path.assign(appStorage.LocalFolder().Path().c_str());
289290
mayBeInProfilePath = true;
290291
break;
291-
case PathName::PackagedTemp:
292-
result.Path.assign(appStorage.TemporaryFolder().Path().c_str());
293-
result.Path /= s_DefaultTempDirectory;
292+
case PathName::StandardFileSettings:
293+
result.Path.assign(appStorage.LocalFolder().Path().c_str());
294+
result.Path /= s_SettingsFile_Relative;
294295
mayBeInProfilePath = true;
295296
break;
296297
case PathName::DefaultLogLocation:
@@ -399,7 +400,6 @@ namespace AppInstaller::Runtime
399400
switch (path)
400401
{
401402
case PathName::Temp:
402-
case PathName::PackagedTemp:
403403
case PathName::DefaultLogLocation:
404404
{
405405
result.Path = GetPathToUserTemp(forDisplay);
@@ -419,6 +419,7 @@ namespace AppInstaller::Runtime
419419
result.Path /= GetRuntimePathStateName();
420420
break;
421421
case PathName::StandardSettings:
422+
case PathName::StandardFileSettings:
422423
case PathName::UserFileSettings:
423424
result = Filesystem::GetPathDetailsFor(Filesystem::PathName::UnpackagedSettingsRoot, anonymize);
424425
result.Create = !forDisplay;

src/AppInstallerCommonCore/Settings.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ namespace AppInstaller::Settings
420420
ApplicationDataSettingsContainer::GetRelativeContainer(
421421
winrt::Windows::Storage::ApplicationData::Current().LocalSettings(), GetPathTo(PathName::StandardSettings)),
422422
name);
423-
case Type::Encrypted:
424-
return std::make_unique<FileSettingsContainer>(GetPathTo(PathName::PackagedTemp), name);
423+
case Type::StandardFile:
424+
return std::make_unique<FileSettingsContainer>(GetPathTo(PathName::StandardFileSettings), name);
425425
default:
426426
THROW_HR(E_UNEXPECTED);
427427
}
@@ -432,7 +432,7 @@ namespace AppInstaller::Settings
432432
switch (type)
433433
{
434434
case Type::Standard:
435-
case Type::Encrypted:
435+
case Type::StandardFile:
436436
return std::make_unique<FileSettingsContainer>(GetPathTo(PathName::StandardSettings), name);
437437
default:
438438
THROW_HR(E_UNEXPECTED);
@@ -459,7 +459,11 @@ namespace AppInstaller::Settings
459459

460460
case Type::Encrypted:
461461
// Encrypted settings add encryption on top of exchange semantics
462-
return std::make_unique<EncryptedSettingsContainer>(GetRawSettingsContainer(Type::Encrypted, name), name);
462+
return std::make_unique<EncryptedSettingsContainer>(GetRawSettingsContainer(Type::StandardFile, name), name);
463+
464+
case Type::StandardFile:
465+
// Standard settings should use exchange semantics to prevent overwrites
466+
return std::make_unique<ExchangeSettingsContainer>(GetRawSettingsContainer(type, name), name);
463467

464468
default:
465469
THROW_HR(E_UNEXPECTED);
@@ -484,6 +488,8 @@ namespace AppInstaller::Settings
484488
return "Secure"sv;
485489
case Type::Encrypted:
486490
return "Encrypted"sv;
491+
case Type::StandardFile:
492+
return "StandardFile"sv;
487493
default:
488494
THROW_HR(E_UNEXPECTED);
489495
}

0 commit comments

Comments
 (0)