Skip to content

Commit e9d77e9

Browse files
committed
Add template
1 parent 3e66324 commit e9d77e9

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

src/AppInstallerCommonCore/Public/winget/UserSettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ namespace AppInstaller::Settings
205205

206206
// Experiments
207207
using Experiments_t = std::map<std::string, bool>;
208-
SETTINGMAPPING_SPECIALIZATION(Setting::Experiments, std::string, Experiments_t, {}, ".experiments"sv);
208+
SETTINGMAPPING_SPECIALIZATION(Setting::Experiments, Experiments_t, Experiments_t, {}, ".experiments"sv);
209209

210210
// Used to deduce the SettingVariant type; making a variant that includes std::monostate and all SettingMapping types.
211211
template <size_t... I>

src/AppInstallerCommonCore/UserSettings.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,32 @@ namespace AppInstaller::Settings
7575
return convertedValue;
7676
}
7777

78+
template<>
79+
std::string GetValueString(std::map<std::string, bool> value)
80+
{
81+
std::stringstream convertedValue;
82+
convertedValue << "{";
83+
84+
bool first = true;
85+
for (auto const& entry : value)
86+
{
87+
if (first)
88+
{
89+
first = false;
90+
}
91+
else
92+
{
93+
convertedValue << ", ";
94+
}
95+
96+
convertedValue << "'" << entry.first << "' = " << entry.second;
97+
}
98+
99+
convertedValue << "}";
100+
101+
return convertedValue.str();
102+
}
103+
78104
std::optional<Json::Value> ParseSettingsContent(const std::string& content, std::string_view settingName, std::vector<UserSettings::Warning>& warnings)
79105
{
80106
Json::Value root;
@@ -278,6 +304,7 @@ namespace AppInstaller::Settings
278304
WINGET_VALIDATE_PASS_THROUGH(UninstallPurgePortablePackage)
279305
WINGET_VALIDATE_PASS_THROUGH(NetworkWingetAlternateSourceURL)
280306
WINGET_VALIDATE_PASS_THROUGH(MaxResumes)
307+
WINGET_VALIDATE_PASS_THROUGH(Experiments)
281308

282309
#ifndef AICLI_DISABLE_TEST_HOOKS
283310
WINGET_VALIDATE_PASS_THROUGH(EnableSelfInitiatedMinidump)

src/AppInstallerSharedLib/JsonUtil.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ namespace AppInstaller::JSON
6767

6868
return std::nullopt;
6969
}
70+
71+
template<>
72+
std::optional<std::map<std::string, bool>> GetValue(const Json::Value& node)
73+
{
74+
std::map<std::string, bool> result;
75+
76+
if (node.isObject())
77+
{
78+
for (const auto& entry : node.getMemberNames())
79+
{
80+
if (node[entry].isBool())
81+
{
82+
result[entry] = node[entry].asBool();
83+
}
84+
}
85+
86+
return result;
87+
}
88+
89+
return std::nullopt;
90+
}
7091

7192
#ifndef WINGET_DISABLE_FOR_FUZZING
7293
utility::string_t GetUtilityString(std::string_view nodeName)

src/AppInstallerSharedLib/Public/winget/JsonUtil.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ namespace AppInstaller::JSON
3333

3434
template<>
3535
std::optional<std::vector<std::string>> GetValue<std::vector<std::string>>(const Json::Value& node);
36+
37+
template<>
38+
std::optional<std::map<std::string, bool>> GetValue(const Json::Value& node);
3639

3740
#ifndef WINGET_DISABLE_FOR_FUZZING
3841
// For cpprestsdk JSON

0 commit comments

Comments
 (0)