diff --git a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp index f317ba1fb35..956881facd9 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -177,9 +177,9 @@ namespace TerminalAppLocalTests { settings->_ValidateProfilesExist(); } - catch (const ::TerminalApp::SettingsException& ex) + catch (const winrt::TerminalApp::implementation::SettingsException& ex) { - VERIFY_IS_TRUE(ex.Error() == ::TerminalApp::SettingsLoadErrors::NoProfiles); + VERIFY_IS_TRUE(ex.Error() == winrt::TerminalApp::SettingsLoadErrors::NoProfiles); caughtExpectedException = true; } VERIFY_IS_TRUE(caughtExpectedException); @@ -193,9 +193,9 @@ namespace TerminalAppLocalTests { settings->_ValidateProfilesExist(); } - catch (const ::TerminalApp::SettingsException& ex) + catch (const winrt::TerminalApp::implementation::SettingsException& ex) { - VERIFY_IS_TRUE(ex.Error() == ::TerminalApp::SettingsLoadErrors::NoProfiles); + VERIFY_IS_TRUE(ex.Error() == winrt::TerminalApp::SettingsLoadErrors::NoProfiles); caughtExpectedException = true; } VERIFY_IS_TRUE(caughtExpectedException); @@ -272,7 +272,7 @@ namespace TerminalAppLocalTests auto settings = implementation::CascadiaSettings::FromJson(settingsObject); settings->_ResolveDefaultProfile(); settings->_ValidateDefaultProfileExists(); - VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.size()); + VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.Size()); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.Size()); VERIFY_ARE_EQUAL(settings->_globals->DefaultProfile(), settings->_profiles.GetAt(0).Guid()); } @@ -284,8 +284,8 @@ namespace TerminalAppLocalTests auto settings = implementation::CascadiaSettings::FromJson(settingsObject); settings->_ResolveDefaultProfile(); settings->_ValidateDefaultProfileExists(); - VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.at(0)); + VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.GetAt(0)); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.Size()); VERIFY_ARE_EQUAL(settings->_globals->DefaultProfile(), settings->_profiles.GetAt(0).Guid()); @@ -298,8 +298,8 @@ namespace TerminalAppLocalTests auto settings = implementation::CascadiaSettings::FromJson(settingsObject); settings->_ResolveDefaultProfile(); settings->_ValidateDefaultProfileExists(); - VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.at(0)); + VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.GetAt(0)); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.Size()); VERIFY_ARE_EQUAL(settings->_globals->DefaultProfile(), settings->_profiles.GetAt(0).Guid()); @@ -312,7 +312,7 @@ namespace TerminalAppLocalTests auto settings = implementation::CascadiaSettings::FromJson(settingsObject); settings->_ResolveDefaultProfile(); settings->_ValidateDefaultProfileExists(); - VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.size()); + VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.Size()); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.Size()); VERIFY_ARE_EQUAL(settings->_globals->DefaultProfile(), settings->_profiles.GetAt(1).Guid()); } @@ -407,7 +407,7 @@ namespace TerminalAppLocalTests settings->_ValidateNoDuplicateProfiles(); - VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.size()); + VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.Size()); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.Size()); } { @@ -421,8 +421,8 @@ namespace TerminalAppLocalTests settings->_ValidateNoDuplicateProfiles(); - VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings->_warnings.at(0)); + VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings->_warnings.GetAt(0)); VERIFY_ARE_EQUAL(static_cast(1), settings->_profiles.Size()); VERIFY_ARE_EQUAL(L"profile2", settings->_profiles.GetAt(0).Name()); @@ -443,8 +443,8 @@ namespace TerminalAppLocalTests settings->_ValidateNoDuplicateProfiles(); - VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings->_warnings.at(0)); + VERIFY_ARE_EQUAL(static_cast(1), settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings->_warnings.GetAt(0)); VERIFY_ARE_EQUAL(static_cast(4), settings->_profiles.Size()); VERIFY_ARE_EQUAL(L"profile0", settings->_profiles.GetAt(0).Name()); @@ -490,10 +490,10 @@ namespace TerminalAppLocalTests settings->_ValidateSettings(); - VERIFY_ARE_EQUAL(3u, settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings->_warnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::UnknownColorScheme, settings->_warnings.at(2)); + VERIFY_ARE_EQUAL(3u, settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings->_warnings.GetAt(0)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.GetAt(1)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::UnknownColorScheme, settings->_warnings.GetAt(2)); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); VERIFY_ARE_EQUAL(settings->_globals->DefaultProfile(), settings->_profiles.GetAt(0).Guid()); @@ -905,7 +905,7 @@ namespace TerminalAppLocalTests VERIFY_IS_FALSE(settings->_profiles.GetAt(1).HasGuid()); settings->_ValidateSettings(); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(2u, settings->_profiles.Size()); VERIFY_IS_TRUE(settings->_profiles.GetAt(0).HasGuid()); VERIFY_IS_TRUE(settings->_profiles.GetAt(1).HasGuid()); @@ -956,7 +956,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"profile1", settings->_profiles.GetAt(3).Name()); settings->_ValidateSettings(); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(4u, settings->_profiles.Size()); VERIFY_IS_TRUE(settings->_profiles.GetAt(0).HasGuid()); VERIFY_IS_TRUE(settings->_profiles.GetAt(1).HasGuid()); @@ -1057,7 +1057,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"Ubuntu", settings->_profiles.GetAt(3).Name()); settings->_ValidateSettings(); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(4u, settings->_profiles.Size()); VERIFY_IS_TRUE(settings->_profiles.GetAt(0).HasGuid()); VERIFY_IS_TRUE(settings->_profiles.GetAt(1).HasGuid()); @@ -1280,9 +1280,9 @@ namespace TerminalAppLocalTests { settings->_RemoveHiddenProfiles(); } - catch (const ::TerminalApp::SettingsException& ex) + catch (const winrt::TerminalApp::implementation::SettingsException& ex) { - VERIFY_IS_TRUE(ex.Error() == ::TerminalApp::SettingsLoadErrors::AllProfilesHidden); + VERIFY_IS_TRUE(ex.Error() == winrt::TerminalApp::SettingsLoadErrors::AllProfilesHidden); caughtExpectedException = true; } VERIFY_IS_TRUE(caughtExpectedException); @@ -1337,8 +1337,8 @@ namespace TerminalAppLocalTests settings->_ValidateAllSchemesExist(); - VERIFY_ARE_EQUAL(1u, settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::UnknownColorScheme, settings->_warnings.at(0)); + VERIFY_ARE_EQUAL(1u, settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::UnknownColorScheme, settings->_warnings.GetAt(0)); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); VERIFY_ARE_EQUAL(2u, settings->_globals->GetColorSchemes().Size()); @@ -2179,7 +2179,7 @@ namespace TerminalAppLocalTests auto settings = implementation::CascadiaSettings::FromJson(settingsJsonObj); settings->_ValidateSettings(); - VERIFY_ARE_EQUAL(2u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(2u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(2u, settings->_profiles.Size()); VERIFY_ARE_EQUAL(settings->_globals->DefaultProfile(), settings->_profiles.GetAt(0).Guid()); try @@ -2291,17 +2291,17 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings->_globals->_keybindings->_keyShortcuts.size()); VERIFY_ARE_EQUAL(3u, settings->_globals->_keybindingsWarnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, settings->_globals->_keybindingsWarnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(2)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, settings->_globals->_keybindingsWarnings.at(0)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(1)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(2)); settings->_ValidateKeybindings(); - VERIFY_ARE_EQUAL(4u, settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::AtLeastOneKeybindingWarning, settings->_warnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, settings->_warnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.at(2)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.at(3)); + VERIFY_ARE_EQUAL(4u, settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::AtLeastOneKeybindingWarning, settings->_warnings.GetAt(0)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, settings->_warnings.GetAt(1)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.GetAt(2)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.GetAt(3)); } void SettingsTests::ValidateExecuteCommandlineWarning() @@ -2338,17 +2338,17 @@ namespace TerminalAppLocalTests L"warning:%d", warning)); } VERIFY_ARE_EQUAL(3u, settings->_globals->_keybindingsWarnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(2)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(0)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(1)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(2)); settings->_ValidateKeybindings(); - VERIFY_ARE_EQUAL(4u, settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::AtLeastOneKeybindingWarning, settings->_warnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.at(2)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.at(3)); + VERIFY_ARE_EQUAL(4u, settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::AtLeastOneKeybindingWarning, settings->_warnings.GetAt(0)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.GetAt(1)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.GetAt(2)); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_warnings.GetAt(3)); } void SettingsTests::ValidateLegacyGlobalsWarning() @@ -2376,15 +2376,15 @@ namespace TerminalAppLocalTests settings->LayerJson(settings->_defaultSettings); settings->_ValidateNoGlobalsKey(); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); // Now layer on the user's settings settings->_ParseJsonString(badSettings, false); settings->LayerJson(settings->_userSettings); settings->_ValidateNoGlobalsKey(); - VERIFY_ARE_EQUAL(1u, settings->_warnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::LegacyGlobalsProperty, settings->_warnings.at(0)); + VERIFY_ARE_EQUAL(1u, settings->_warnings.Size()); + VERIFY_ARE_EQUAL(winrt::TerminalApp::SettingsLoadWarnings::LegacyGlobalsProperty, settings->_warnings.GetAt(0)); } void SettingsTests::TestTrailingCommas() @@ -2668,7 +2668,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); @@ -2696,7 +2696,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); { @@ -2799,7 +2799,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); @@ -2827,7 +2827,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); { @@ -2932,7 +2932,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); @@ -2961,7 +2961,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); { @@ -3075,7 +3075,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); @@ -3083,7 +3083,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); auto rootCommandProj = expandedCommands.Lookup(L"Connect to ssh..."); @@ -3184,7 +3184,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); @@ -3192,7 +3192,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); auto grandparentCommandProj = expandedCommands.Lookup(L"grandparent"); @@ -3324,7 +3324,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); @@ -3332,7 +3332,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); @@ -3478,7 +3478,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); @@ -3486,7 +3486,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); auto rootCommandProj = expandedCommands.Lookup(L"New Tab With Profile..."); @@ -3592,7 +3592,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); @@ -3600,7 +3600,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); auto rootCommandProj = expandedCommands.Lookup(L"New Pane..."); @@ -3754,14 +3754,14 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); settings->_ValidateSettings(); _logCommandNames(commands); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); // Because the "parent" command didn't have a name, it couldn't be // placed into the list of commands. It and it's children are just @@ -3831,14 +3831,14 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); settings->_ValidateSettings(); _logCommandNames(commands); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(1u, commands.Size()); Log::Comment(L"Layer second bit of json, to unbind the original command."); @@ -3847,7 +3847,7 @@ namespace TerminalAppLocalTests settings->LayerJson(settings->_userSettings); settings->_ValidateSettings(); _logCommandNames(commands); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(0u, commands.Size()); } @@ -3914,14 +3914,14 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); auto commands = settings->_globals->GetCommands(); settings->_ValidateSettings(); _logCommandNames(commands); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -3941,7 +3941,7 @@ namespace TerminalAppLocalTests settings->LayerJson(settings->_userSettings); settings->_ValidateSettings(); _logCommandNames(commands); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -4010,7 +4010,7 @@ namespace TerminalAppLocalTests settings->_ParseJsonString(settingsJson, false); settings->LayerJson(settings->_userSettings); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, settings->_profiles.Size()); @@ -4038,7 +4038,7 @@ namespace TerminalAppLocalTests auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings->Profiles().GetView(), settings->_globals->GetColorSchemes()); _logCommandNames(expandedCommands.GetView()); - VERIFY_ARE_EQUAL(0u, settings->_warnings.size()); + VERIFY_ARE_EQUAL(0u, settings->_warnings.Size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); // Yes, this test is testing splitPane with profiles named after each diff --git a/src/cascadia/TerminalApp/ActionAndArgs.cpp b/src/cascadia/TerminalApp/ActionAndArgs.cpp index 76943897177..8f7048f9dc0 100644 --- a/src/cascadia/TerminalApp/ActionAndArgs.cpp +++ b/src/cascadia/TerminalApp/ActionAndArgs.cpp @@ -105,7 +105,7 @@ namespace winrt::TerminalApp::implementation { UnboundKey, ShortcutAction::Invalid }, }; - using ParseResult = std::tuple>; + using ParseResult = std::tuple>; using ParseActionFunction = std::function; // This is a map of ShortcutAction->function. It holds @@ -169,7 +169,7 @@ namespace winrt::TerminalApp::implementation // - a deserialized ActionAndArgs corresponding to the values in json, or // null if we failed to deserialize an action. winrt::com_ptr ActionAndArgs::FromJson(const Json::Value& json, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings) + std::vector& warnings) { // Invalid is our placeholder that the action was not parsed. ShortcutAction action = ShortcutAction::Invalid; @@ -208,7 +208,7 @@ namespace winrt::TerminalApp::implementation // does, we'll try to deserialize any "args" that were provided with // the binding. IActionArgs args{ nullptr }; - std::vector<::TerminalApp::SettingsLoadWarnings> parseWarnings; + std::vector parseWarnings; const auto deserializersIter = argParsers.find(action); if (deserializersIter != argParsers.end()) { diff --git a/src/cascadia/TerminalApp/ActionAndArgs.h b/src/cascadia/TerminalApp/ActionAndArgs.h index bc202216379..a0e26fc8957 100644 --- a/src/cascadia/TerminalApp/ActionAndArgs.h +++ b/src/cascadia/TerminalApp/ActionAndArgs.h @@ -9,7 +9,7 @@ namespace winrt::TerminalApp::implementation { static const std::map> ActionKeyNamesMap; static winrt::com_ptr FromJson(const Json::Value& json, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings); + std::vector& warnings); ActionAndArgs() = default; hstring GenerateName() const; diff --git a/src/cascadia/TerminalApp/ActionArgs.h b/src/cascadia/TerminalApp/ActionArgs.h index de3bbd0b3da..3f7e829cd04 100644 --- a/src/cascadia/TerminalApp/ActionArgs.h +++ b/src/cascadia/TerminalApp/ActionArgs.h @@ -39,7 +39,7 @@ namespace winrt::TerminalApp::implementation { using namespace ::TerminalApp; - using FromJsonResult = std::tuple>; + using FromJsonResult = std::tuple>; struct ActionEventArgs : public ActionEventArgsT { @@ -202,7 +202,7 @@ namespace winrt::TerminalApp::implementation JsonUtils::GetValueForKey(json, DirectionKey, args->_Direction); if (args->_Direction == TerminalApp::Direction::None) { - return { nullptr, { ::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; + return { nullptr, { TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; } else { @@ -237,7 +237,7 @@ namespace winrt::TerminalApp::implementation JsonUtils::GetValueForKey(json, DirectionKey, args->_Direction); if (args->_Direction == TerminalApp::Direction::None) { - return { nullptr, { ::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; + return { nullptr, { TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; } else { @@ -299,7 +299,7 @@ namespace winrt::TerminalApp::implementation JsonUtils::GetValueForKey(json, InputKey, args->_Input); if (args->_Input.empty()) { - return { nullptr, { ::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; + return { nullptr, { TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; } return { *args, {} }; } @@ -395,7 +395,7 @@ namespace winrt::TerminalApp::implementation JsonUtils::GetValueForKey(json, NameKey, args->_SchemeName); if (args->_SchemeName.empty()) { - return { nullptr, { ::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; + return { nullptr, { TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; } return { *args, {} }; } @@ -486,7 +486,7 @@ namespace winrt::TerminalApp::implementation JsonUtils::GetValueForKey(json, CommandlineKey, args->_Commandline); if (args->_Commandline.empty()) { - return { nullptr, { ::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; + return { nullptr, { TerminalApp::SettingsLoadWarnings::MissingRequiredParameter } }; } return { *args, {} }; } diff --git a/src/cascadia/TerminalApp/AppKeyBindings.h b/src/cascadia/TerminalApp/AppKeyBindings.h index 4feb7e8968a..5a726046589 100644 --- a/src/cascadia/TerminalApp/AppKeyBindings.h +++ b/src/cascadia/TerminalApp/AppKeyBindings.h @@ -53,7 +53,7 @@ namespace winrt::TerminalApp::implementation static Windows::System::VirtualKeyModifiers ConvertVKModifiers(winrt::Microsoft::Terminal::TerminalControl::KeyModifiers modifiers); // Defined in AppKeyBindingsSerialization.cpp - std::vector<::TerminalApp::SettingsLoadWarnings> LayerJson(const Json::Value& json); + std::vector LayerJson(const Json::Value& json); Json::Value ToJson(); void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch); diff --git a/src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp b/src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp index 2bb507ec86f..907cf9f1b3f 100644 --- a/src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp +++ b/src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp @@ -93,13 +93,13 @@ Json::Value winrt::TerminalApp::implementation::AppKeyBindings::ToJson() // `"unbound"`, then we'll clear the keybinding from the existing keybindings. // Arguments: // - json: an array of Json::Value's to deserialize into our _keyShortcuts mapping. -std::vector<::TerminalApp::SettingsLoadWarnings> winrt::TerminalApp::implementation::AppKeyBindings::LayerJson(const Json::Value& json) +std::vector winrt::TerminalApp::implementation::AppKeyBindings::LayerJson(const Json::Value& json) { // It's possible that the user provided keybindings have some warnings in // them - problems that we should alert the user to, but we can recover // from. Most of these warnings cannot be detected later in the Validate // settings phase, so we'll collect them now. - std::vector<::TerminalApp::SettingsLoadWarnings> warnings; + std::vector warnings; for (const auto& value : json) { @@ -121,7 +121,7 @@ std::vector<::TerminalApp::SettingsLoadWarnings> winrt::TerminalApp::implementat // TODO: GH#1334 - remove this check. if (keys.isArray() && keys.size() > 1) { - warnings.push_back(::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord); + warnings.push_back(SettingsLoadWarnings::TooManyKeysForChord); } if (!validString && !validArray) diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 1b9c1304113..a4fa041601e 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -29,7 +29,7 @@ static const winrt::hstring StartupTaskName = L"StartTerminalOnLoginTask"; // !!! IMPORTANT !!! // Make sure that these keys are in the same order as the // SettingsLoadWarnings/Errors enum is! -static const std::array(SettingsLoadWarnings::WARNINGS_SIZE)> settingsLoadWarningsLabels { +static const std::array(winrt::TerminalApp::SettingsLoadWarnings::WARNINGS_SIZE)> settingsLoadWarningsLabels { USES_RESOURCE(L"MissingDefaultProfileText"), USES_RESOURCE(L"DuplicateProfileText"), USES_RESOURCE(L"UnknownColorSchemeText"), @@ -41,7 +41,7 @@ static const std::array(SettingsLoadWar USES_RESOURCE(L"LegacyGlobalsProperty"), USES_RESOURCE(L"FailedToParseCommandJson") }; -static const std::array(SettingsLoadErrors::ERRORS_SIZE)> settingsLoadErrorsLabels { +static const std::array(winrt::TerminalApp::SettingsLoadErrors::ERRORS_SIZE)> settingsLoadErrorsLabels { USES_RESOURCE(L"NoProfilesText"), USES_RESOURCE(L"AllProfilesHiddenText") }; @@ -76,7 +76,7 @@ static winrt::hstring _GetMessageText(uint32_t index, std::array(warning), settingsLoadWarningsLabels); } @@ -89,7 +89,7 @@ static winrt::hstring _GetWarningText(::TerminalApp::SettingsLoadWarnings warnin // - error: the SettingsLoadErrors value to get the localized text for. // Return Value: // - localized text for the given error -static winrt::hstring _GetErrorText(::TerminalApp::SettingsLoadErrors error) +static winrt::hstring _GetErrorText(winrt::TerminalApp::SettingsLoadErrors error) { return _GetMessageText(static_cast(error), settingsLoadErrorsLabels); } @@ -411,8 +411,7 @@ namespace winrt::TerminalApp::implementation // Make sure the lines of text wrap warningsTextBlock.TextWrapping(TextWrapping::Wrap); - const auto settingsImpl{ winrt::get_self(_settings) }; - const auto& warnings = settingsImpl->GetWarnings(); + const auto warnings = _settings.Warnings(); for (const auto& warning : warnings) { // Try looking up the warning message key for each warning. @@ -631,9 +630,18 @@ namespace winrt::TerminalApp::implementation auto newSettings = _isUwp ? CascadiaSettings::LoadUniversal() : CascadiaSettings::LoadAll(); _settings = newSettings; - const auto settingsImpl{ winrt::get_self(_settings) }; - const auto& warnings = settingsImpl->GetWarnings(); - hr = warnings.size() == 0 ? S_OK : S_FALSE; + if (_settings.GetLoadingError()) + { + _settingsLoadExceptionText = _GetErrorText(_settings.GetLoadingError().Value()); + return E_INVALIDARG; + } + else if (!_settings.GetSerializationErrorMessage().empty()) + { + _settingsLoadExceptionText = _settings.GetSerializationErrorMessage(); + return E_INVALIDARG; + } + + hr = _settings.Warnings().Size() == 0 ? S_OK : S_FALSE; } catch (const winrt::hresult_error& e) { @@ -641,17 +649,6 @@ namespace winrt::TerminalApp::implementation _settingsLoadExceptionText = e.message(); LOG_HR(hr); } - catch (const ::TerminalApp::SettingsException& ex) - { - hr = E_INVALIDARG; - _settingsLoadExceptionText = _GetErrorText(ex.Error()); - } - catch (const ::TerminalApp::SettingsTypedDeserializationException& e) - { - hr = E_INVALIDARG; - std::string_view what{ e.what() }; - _settingsLoadExceptionText = til::u8u16(what); - } catch (...) { hr = wil::ResultFromCaughtException(); diff --git a/src/cascadia/TerminalApp/CascadiaSettings.cpp b/src/cascadia/TerminalApp/CascadiaSettings.cpp index 66e2f8a2607..26c6b48da87 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettings.cpp @@ -46,7 +46,9 @@ CascadiaSettings::CascadiaSettings() : // - addDynamicProfiles: if true, we'll add the built-in DPGs. CascadiaSettings::CascadiaSettings(const bool addDynamicProfiles) : _globals{ winrt::make_self() }, - _profiles{ winrt::single_threaded_observable_vector() } + _profiles{ winrt::single_threaded_observable_vector() }, + _warnings{ winrt::single_threaded_vector() }, + _deserializationErrorMessage{ L"" } { if (addDynamicProfiles) { @@ -119,9 +121,19 @@ winrt::TerminalApp::GlobalAppSettings CascadiaSettings::GlobalSettings() // knew were bad when we called `_ValidateSettings` last. // Return Value: // - a reference to our list of warnings. -std::vector& CascadiaSettings::GetWarnings() +IVectorView CascadiaSettings::Warnings() { - return _warnings; + return _warnings.GetView(); +} + +winrt::Windows::Foundation::IReference CascadiaSettings::GetLoadingError() +{ + return _loadError; +} + +winrt::hstring CascadiaSettings::GetSerializationErrorMessage() +{ + return _deserializationErrorMessage; } // Method Description: @@ -136,7 +148,7 @@ std::vector& CascadiaSettings::GetWarnings() // - void CascadiaSettings::_ValidateSettings() { - _warnings.clear(); + _warnings.Clear(); // Make sure to check that profiles exists at all first and foremost: _ValidateProfilesExist(); @@ -198,7 +210,7 @@ void CascadiaSettings::_ValidateProfilesExist() // We can't add the warning to the list of warnings here, because this // object is not going to be returned at any point. - throw ::TerminalApp::SettingsException(::TerminalApp::SettingsLoadErrors::NoProfiles); + throw SettingsException(TerminalApp::SettingsLoadErrors::NoProfiles); } } @@ -252,7 +264,7 @@ void CascadiaSettings::_ValidateDefaultProfileExists() if (nullDefaultProfile || defaultProfileNotInProfiles) { - _warnings.push_back(::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile); + _warnings.Append(TerminalApp::SettingsLoadWarnings::MissingDefaultProfile); // Use the first profile as the new default // _temporarily_ set the default profile to the first profile. Because @@ -295,7 +307,7 @@ void CascadiaSettings::_ValidateNoDuplicateProfiles() if (foundDupe) { - _warnings.push_back(::TerminalApp::SettingsLoadWarnings::DuplicateProfile); + _warnings.Append(TerminalApp::SettingsLoadWarnings::DuplicateProfile); } } @@ -384,7 +396,7 @@ void CascadiaSettings::_RemoveHiddenProfiles() { // Throw an exception. This is an invalid state, and we want the app to // be able to gracefully use the default settings. - throw ::TerminalApp::SettingsException(::TerminalApp::SettingsLoadErrors::AllProfilesHidden); + throw SettingsException(TerminalApp::SettingsLoadErrors::AllProfilesHidden); } } @@ -413,7 +425,7 @@ void CascadiaSettings::_ValidateAllSchemesExist() if (foundInvalidScheme) { - _warnings.push_back(::TerminalApp::SettingsLoadWarnings::UnknownColorScheme); + _warnings.Append(SettingsLoadWarnings::UnknownColorScheme); } } @@ -468,12 +480,12 @@ void CascadiaSettings::_ValidateMediaResources() if (invalidBackground) { - _warnings.push_back(::TerminalApp::SettingsLoadWarnings::InvalidBackgroundImage); + _warnings.Append(TerminalApp::SettingsLoadWarnings::InvalidBackgroundImage); } if (invalidIcon) { - _warnings.push_back(::TerminalApp::SettingsLoadWarnings::InvalidIcon); + _warnings.Append(TerminalApp::SettingsLoadWarnings::InvalidIcon); } } @@ -659,8 +671,11 @@ void CascadiaSettings::_ValidateKeybindings() if (!keybindingWarnings.empty()) { - _warnings.push_back(::TerminalApp::SettingsLoadWarnings::AtLeastOneKeybindingWarning); - _warnings.insert(_warnings.end(), keybindingWarnings.begin(), keybindingWarnings.end()); + _warnings.Append(TerminalApp::SettingsLoadWarnings::AtLeastOneKeybindingWarning); + for (auto warning : keybindingWarnings) + { + _warnings.Append(warning); + } } } @@ -679,7 +694,7 @@ void CascadiaSettings::_ValidateNoGlobalsKey() { if (auto oldGlobalsProperty{ _userSettings["globals"] }) { - _warnings.push_back(::TerminalApp::SettingsLoadWarnings::LegacyGlobalsProperty); + _warnings.Append(TerminalApp::SettingsLoadWarnings::LegacyGlobalsProperty); } } diff --git a/src/cascadia/TerminalApp/CascadiaSettings.h b/src/cascadia/TerminalApp/CascadiaSettings.h index d02704e30c6..3d07bcc7628 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.h +++ b/src/cascadia/TerminalApp/CascadiaSettings.h @@ -84,14 +84,18 @@ namespace winrt::TerminalApp::implementation TerminalApp::Profile FindProfile(guid profileGuid) const noexcept; TerminalApp::ColorScheme GetColorSchemeForProfile(const guid profileGuid) const; - std::vector<::TerminalApp::SettingsLoadWarnings>& GetWarnings(); + Windows::Foundation::Collections::IVectorView Warnings(); + Windows::Foundation::IReference GetLoadingError(); + hstring GetSerializationErrorMessage(); bool ApplyColorScheme(Microsoft::Terminal::TerminalControl::IControlSettings settings, hstring schemeName); private: com_ptr _globals; Windows::Foundation::Collections::IObservableVector _profiles; - std::vector<::TerminalApp::SettingsLoadWarnings> _warnings; + Windows::Foundation::Collections::IVector _warnings; + Windows::Foundation::IReference _loadError; + hstring _deserializationErrorMessage; std::vector> _profileGenerators; diff --git a/src/cascadia/TerminalApp/CascadiaSettings.idl b/src/cascadia/TerminalApp/CascadiaSettings.idl index 58695b9dc31..d23b193b400 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.idl +++ b/src/cascadia/TerminalApp/CascadiaSettings.idl @@ -3,6 +3,7 @@ import "GlobalAppSettings.idl"; import "Profile.idl"; +import "TerminalWarnings.idl"; namespace TerminalApp { @@ -17,6 +18,10 @@ namespace TerminalApp AppKeyBindings Keybindings { get; }; + Windows.Foundation.Collections.IVectorView Warnings { get; }; + Windows.Foundation.IReference GetLoadingError { get; }; + String GetSerializationErrorMessage { get; }; + Profile FindProfile(Guid profileGuid); ColorScheme GetColorSchemeForProfile(Guid profileGuid); } diff --git a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp index e34d10e25e8..13479fb25ee 100644 --- a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp @@ -18,7 +18,6 @@ // Both defaults.h and userDefaults.h are generated at build time into the // "Generated Files" directory. -using namespace ::TerminalApp; using namespace winrt::TerminalApp::implementation; using namespace ::Microsoft::Console; @@ -103,145 +102,161 @@ static void _CatchRethrowSerializationExceptionWithLocationInfo(std::string_view // - a unique_ptr containing a new CascadiaSettings object. winrt::TerminalApp::CascadiaSettings CascadiaSettings::LoadAll() { - auto settings = LoadDefaults(); - auto resultPtr = winrt::get_self(settings); - - // GH 3588, we need this below to know if the user chose something that wasn't our default. - // Collect it up here in case it gets modified by any of the other layers between now and when - // the user's preferences are loaded and layered. - const auto hardcodedDefaultGuid = resultPtr->GlobalSettings().DefaultProfile(); - - std::optional fileData = _ReadUserSettings(); - const bool foundFile = fileData.has_value(); - - // Make sure the file isn't totally empty. If it is, we'll treat the file - // like it doesn't exist at all. - const bool fileHasData = foundFile && !fileData.value().empty(); - bool needToWriteFile = false; - if (fileHasData) + try { - resultPtr->_ParseJsonString(fileData.value(), false); - } + auto settings = LoadDefaults(); + auto resultPtr = winrt::get_self(settings); - // Load profiles from dynamic profile generators. _userSettings should be - // created by now, because we're going to check in there for any generators - // that should be disabled (if the user had any settings.) - resultPtr->_LoadDynamicProfiles(); + // GH 3588, we need this below to know if the user chose something that wasn't our default. + // Collect it up here in case it gets modified by any of the other layers between now and when + // the user's preferences are loaded and layered. + const auto hardcodedDefaultGuid = resultPtr->GlobalSettings().DefaultProfile(); - if (!fileHasData) - { - // We didn't find the user settings. We'll need to create a file - // to use as the user defaults. - // For now, just parse our user settings template as their user settings. - auto userSettings{ resultPtr->_ApplyFirstRunChangesToSettingsTemplate(UserSettingsJson) }; - resultPtr->_ParseJsonString(userSettings, false); - needToWriteFile = true; - } + std::optional fileData = _ReadUserSettings(); + const bool foundFile = fileData.has_value(); - try - { - // See microsoft/terminal#2325: find the defaultSettings from the user's - // settings. Layer those settings upon all the existing profiles we have - // (defaults and dynamic profiles). We'll also set - // _userDefaultProfileSettings here. When we LayerJson below to apply the - // user settings, we'll make sure to use these defaultSettings _before_ any - // profiles the user might have. - resultPtr->_ApplyDefaultsFromUserSettings(); - - // Apply the user's settings - resultPtr->LayerJson(resultPtr->_userSettings); - } - catch (...) - { - _CatchRethrowSerializationExceptionWithLocationInfo(resultPtr->_userSettingsString); - } + // Make sure the file isn't totally empty. If it is, we'll treat the file + // like it doesn't exist at all. + const bool fileHasData = foundFile && !fileData.value().empty(); + bool needToWriteFile = false; + if (fileHasData) + { + resultPtr->_ParseJsonString(fileData.value(), false); + } - // After layering the user settings, check if there are any new profiles - // that need to be inserted into their user settings file. - needToWriteFile = resultPtr->_AppendDynamicProfilesToUserSettings() || needToWriteFile; + // Load profiles from dynamic profile generators. _userSettings should be + // created by now, because we're going to check in there for any generators + // that should be disabled (if the user had any settings.) + resultPtr->_LoadDynamicProfiles(); - if (needToWriteFile) - { - // For safety's sake, we need to re-parse the JSON document to ensure that - // all future patches are applied with updated object offsets. - resultPtr->_ParseJsonString(resultPtr->_userSettingsString, false); - } + if (!fileHasData) + { + // We didn't find the user settings. We'll need to create a file + // to use as the user defaults. + // For now, just parse our user settings template as their user settings. + auto userSettings{ resultPtr->_ApplyFirstRunChangesToSettingsTemplate(UserSettingsJson) }; + resultPtr->_ParseJsonString(userSettings, false); + needToWriteFile = true; + } - // Make sure there's a $schema at the top of the file. - needToWriteFile = resultPtr->_PrependSchemaDirective() || needToWriteFile; + try + { + // See microsoft/terminal#2325: find the defaultSettings from the user's + // settings. Layer those settings upon all the existing profiles we have + // (defaults and dynamic profiles). We'll also set + // _userDefaultProfileSettings here. When we LayerJson below to apply the + // user settings, we'll make sure to use these defaultSettings _before_ any + // profiles the user might have. + resultPtr->_ApplyDefaultsFromUserSettings(); + + // Apply the user's settings + resultPtr->LayerJson(resultPtr->_userSettings); + } + catch (...) + { + _CatchRethrowSerializationExceptionWithLocationInfo(resultPtr->_userSettingsString); + } - // TODO:GH#2721 If powershell core is installed, we need to set that to the - // default profile, but only when the settings file was newly created. We'll - // re-write the segment of the user settings for "default profile" to have - // the powershell core GUID instead. + // After layering the user settings, check if there are any new profiles + // that need to be inserted into their user settings file. + needToWriteFile = resultPtr->_AppendDynamicProfilesToUserSettings() || needToWriteFile; - // If we created the file, or found new dynamic profiles, write the user - // settings string back to the file. - if (needToWriteFile) - { - // If AppendDynamicProfilesToUserSettings (or the pwsh check above) - // changed the file, then our local settings JSON is no longer accurate. - // We should re-parse, but not re-layer - resultPtr->_ParseJsonString(resultPtr->_userSettingsString, false); + if (needToWriteFile) + { + // For safety's sake, we need to re-parse the JSON document to ensure that + // all future patches are applied with updated object offsets. + resultPtr->_ParseJsonString(resultPtr->_userSettingsString, false); + } - _WriteSettings(resultPtr->_userSettingsString); - } + // Make sure there's a $schema at the top of the file. + needToWriteFile = resultPtr->_PrependSchemaDirective() || needToWriteFile; - // If this throws, the app will catch it and use the default settings - resultPtr->_ValidateSettings(); + // TODO:GH#2721 If powershell core is installed, we need to set that to the + // default profile, but only when the settings file was newly created. We'll + // re-write the segment of the user settings for "default profile" to have + // the powershell core GUID instead. - // GH 3855 - Gathering Data on custom profiles to inform better defaults - // Do it after everything else so it won't happen unless validation passed. - // Also, avoid processing unless someone's listening for measures. The keybindings work, at least, - // is a lot of computation we can skip if no one cares. - if (TraceLoggingProviderEnabled(g_hTerminalAppProvider, 0, MICROSOFT_KEYWORD_MEASURES)) - { - const auto guid = resultPtr->GlobalSettings().DefaultProfile(); - - // Compare to the defaults.json one that we set on install. - // If it's different, log what the user chose. - if (hardcodedDefaultGuid != guid) + // If we created the file, or found new dynamic profiles, write the user + // settings string back to the file. + if (needToWriteFile) { - TraceLoggingWrite( - g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider - "CustomDefaultProfile", - TraceLoggingDescription("Event emitted when user has chosen a different default profile than hardcoded one on load/reload"), - TraceLoggingGuid(guid, "DefaultProfile", "ID of user-chosen default profile"), - TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), - TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage)); + // If AppendDynamicProfilesToUserSettings (or the pwsh check above) + // changed the file, then our local settings JSON is no longer accurate. + // We should re-parse, but not re-layer + resultPtr->_ParseJsonString(resultPtr->_userSettingsString, false); + + _WriteSettings(resultPtr->_userSettingsString); } - // If the user had keybinding settings preferences, we want to learn from them to make better defaults - auto userKeybindings = resultPtr->_userSettings[JsonKey(KeybindingsKey)]; - if (!userKeybindings.empty()) + // If this throws, the app will catch it and use the default settings + resultPtr->_ValidateSettings(); + + // GH 3855 - Gathering Data on custom profiles to inform better defaults + // Do it after everything else so it won't happen unless validation passed. + // Also, avoid processing unless someone's listening for measures. The keybindings work, at least, + // is a lot of computation we can skip if no one cares. + if (TraceLoggingProviderEnabled(g_hTerminalAppProvider, 0, MICROSOFT_KEYWORD_MEASURES)) { - // If there are custom key bindings, let's understand what they are because maybe the defaults aren't good enough - - // Run it through the object so we can parse it apart and then only serialize the fields we're interested in - // and avoid extraneous data. - auto akb = winrt::make_self(); - akb->LayerJson(userKeybindings); - auto value = akb->ToJson(); - - // Reserialize the keybindings - Json::StreamWriterBuilder wbuilder; - // Use 4 spaces to indent instead of \t - wbuilder.settings_["indentation"] = " "; - wbuilder.settings_["enableYAMLCompatibility"] = true; // suppress spaces around colons - - const auto keybindingsString = Json::writeString(wbuilder, value); - - TraceLoggingWrite( - g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider - "CustomKeybindings", - TraceLoggingDescription("Event emitted when custom keybindings are identified on load/reload"), - TraceLoggingUtf8String(keybindingsString.c_str(), "Keybindings", "Keybindings as JSON"), - TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), - TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage)); + const auto guid = resultPtr->GlobalSettings().DefaultProfile(); + + // Compare to the defaults.json one that we set on install. + // If it's different, log what the user chose. + if (hardcodedDefaultGuid != guid) + { + TraceLoggingWrite( + g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider + "CustomDefaultProfile", + TraceLoggingDescription("Event emitted when user has chosen a different default profile than hardcoded one on load/reload"), + TraceLoggingGuid(guid, "DefaultProfile", "ID of user-chosen default profile"), + TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), + TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage)); + } + + // If the user had keybinding settings preferences, we want to learn from them to make better defaults + auto userKeybindings = resultPtr->_userSettings[JsonKey(KeybindingsKey)]; + if (!userKeybindings.empty()) + { + // If there are custom key bindings, let's understand what they are because maybe the defaults aren't good enough + + // Run it through the object so we can parse it apart and then only serialize the fields we're interested in + // and avoid extraneous data. + auto akb = winrt::make_self(); + akb->LayerJson(userKeybindings); + auto value = akb->ToJson(); + + // Reserialize the keybindings + Json::StreamWriterBuilder wbuilder; + // Use 4 spaces to indent instead of \t + wbuilder.settings_["indentation"] = " "; + wbuilder.settings_["enableYAMLCompatibility"] = true; // suppress spaces around colons + + const auto keybindingsString = Json::writeString(wbuilder, value); + + TraceLoggingWrite( + g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider + "CustomKeybindings", + TraceLoggingDescription("Event emitted when custom keybindings are identified on load/reload"), + TraceLoggingUtf8String(keybindingsString.c_str(), "Keybindings", "Keybindings as JSON"), + TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), + TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage)); + } } - } - return *resultPtr; + return *resultPtr; + } + catch (const SettingsException& ex) + { + auto settings{ winrt::make_self() }; + settings->_loadError = ex.Error(); + return *settings; + } + catch (const SettingsTypedDeserializationException& e) + { + auto settings{ winrt::make_self() }; + std::string_view what{ e.what() }; + settings->_deserializationErrorMessage = til::u8u16(what); + return *settings; + } } // Function Description: @@ -255,16 +270,32 @@ winrt::TerminalApp::CascadiaSettings CascadiaSettings::LoadUniversal() // We're going to do this ourselves because we want to exclude almost everything // from the special Universal-for-developers configuration - // Create settings and get the universal defaults loaded up. - auto resultPtr = winrt::make_self(); - resultPtr->_ParseJsonString(DefaultUniversalJson, true); - resultPtr->LayerJson(resultPtr->_defaultSettings); + try + { + // Create settings and get the universal defaults loaded up. + auto resultPtr = winrt::make_self(); + resultPtr->_ParseJsonString(DefaultUniversalJson, true); + resultPtr->LayerJson(resultPtr->_defaultSettings); - // Now validate. - // If this throws, the app will catch it and use the default settings - resultPtr->_ValidateSettings(); + // Now validate. + // If this throws, the app will catch it and use the default settings + resultPtr->_ValidateSettings(); - return *resultPtr; + return *resultPtr; + } + catch (const SettingsException& ex) + { + auto settings{ winrt::make_self() }; + settings->_loadError = ex.Error(); + return *settings; + } + catch (const SettingsTypedDeserializationException& e) + { + auto settings{ winrt::make_self() }; + std::string_view what{ e.what() }; + settings->_deserializationErrorMessage = til::u8u16(what); + return *settings; + } } // Function Description: @@ -276,7 +307,7 @@ winrt::TerminalApp::CascadiaSettings CascadiaSettings::LoadUniversal() // - a unique_ptr to a CascadiaSettings with the settings from defaults.json winrt::TerminalApp::CascadiaSettings CascadiaSettings::LoadDefaults() { - auto resultPtr = winrt::make_self(); + auto resultPtr{ winrt::make_self() }; // We already have the defaults in memory, because we stamp them into a // header as part of the build process. We don't need to bother with reading diff --git a/src/cascadia/TerminalApp/Command.cpp b/src/cascadia/TerminalApp/Command.cpp index 014058d4bca..03b452e705f 100644 --- a/src/cascadia/TerminalApp/Command.cpp +++ b/src/cascadia/TerminalApp/Command.cpp @@ -187,7 +187,7 @@ namespace winrt::TerminalApp::implementation // Return Value: // - the newly constructed Command object. winrt::com_ptr Command::FromJson(const Json::Value& json, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings) + std::vector& warnings) { auto result = winrt::make_self(); @@ -280,10 +280,10 @@ namespace winrt::TerminalApp::implementation // - json: A Json::Value containing an array of serialized commands // Return Value: // - A vector containing any warnings detected while parsing - std::vector<::TerminalApp::SettingsLoadWarnings> Command::LayerJson(Windows::Foundation::Collections::IMap& commands, - const Json::Value& json) + std::vector Command::LayerJson(Windows::Foundation::Collections::IMap& commands, + const Json::Value& json) { - std::vector<::TerminalApp::SettingsLoadWarnings> warnings; + std::vector warnings; for (const auto& value : json) { @@ -355,7 +355,7 @@ namespace winrt::TerminalApp::implementation void Command::ExpandCommands(Windows::Foundation::Collections::IMap& commands, Windows::Foundation::Collections::IVectorView profiles, gsl::span schemes, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings) + std::vector& warnings) { std::vector commandsToRemove; std::vector commandsToAdd; @@ -411,7 +411,7 @@ namespace winrt::TerminalApp::implementation std::vector Command::_expandCommand(Command* const expandable, Windows::Foundation::Collections::IVectorView profiles, gsl::span schemes, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings) + std::vector& warnings) { std::vector newCommands; @@ -438,7 +438,7 @@ namespace winrt::TerminalApp::implementation const auto actualDataEnd = newJsonString.data() + newJsonString.size(); if (!reader->parse(actualDataStart, actualDataEnd, &newJsonValue, &errs)) { - warnings.push_back(::TerminalApp::SettingsLoadWarnings::FailedToParseCommandJson); + warnings.push_back(SettingsLoadWarnings::FailedToParseCommandJson); // If we encounter a re-parsing error, just stop processing the rest of the commands. return false; } diff --git a/src/cascadia/TerminalApp/Command.h b/src/cascadia/TerminalApp/Command.h index 2b8e62a6044..a89f10ed78b 100644 --- a/src/cascadia/TerminalApp/Command.h +++ b/src/cascadia/TerminalApp/Command.h @@ -38,15 +38,15 @@ namespace winrt::TerminalApp::implementation Command(); static winrt::com_ptr FromJson(const Json::Value& json, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings); + std::vector& warnings); static void ExpandCommands(Windows::Foundation::Collections::IMap& commands, Windows::Foundation::Collections::IVectorView profiles, gsl::span schemes, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings); + std::vector& warnings); - static std::vector<::TerminalApp::SettingsLoadWarnings> LayerJson(Windows::Foundation::Collections::IMap& commands, - const Json::Value& json); + static std::vector LayerJson(Windows::Foundation::Collections::IMap& commands, + const Json::Value& json); bool HasNestedCommands(); Windows::Foundation::Collections::IMapView NestedCommands(); @@ -71,7 +71,7 @@ namespace winrt::TerminalApp::implementation static std::vector _expandCommand(Command* const expandable, Windows::Foundation::Collections::IVectorView profiles, gsl::span schemes, - std::vector<::TerminalApp::SettingsLoadWarnings>& warnings); + std::vector& warnings); friend class TerminalAppLocalTests::SettingsTests; friend class TerminalAppLocalTests::CommandTests; }; diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.cpp b/src/cascadia/TerminalApp/GlobalAppSettings.cpp index 7507e83bdc6..7a5b1aa43b5 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalApp/GlobalAppSettings.cpp @@ -218,7 +218,7 @@ void GlobalAppSettings::AddColorScheme(const winrt::TerminalApp::ColorScheme& sc // - // Return Value: // - -std::vector GlobalAppSettings::GetKeybindingsWarnings() const +std::vector GlobalAppSettings::GetKeybindingsWarnings() const { return _keybindingsWarnings; } diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.h b/src/cascadia/TerminalApp/GlobalAppSettings.h index 82d385a9434..59a3cc541b7 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.h +++ b/src/cascadia/TerminalApp/GlobalAppSettings.h @@ -45,7 +45,7 @@ namespace winrt::TerminalApp::implementation void ApplyToSettings(const TerminalApp::TerminalSettings& settings) const noexcept; - std::vector<::TerminalApp::SettingsLoadWarnings> GetKeybindingsWarnings() const; + std::vector GetKeybindingsWarnings() const; Windows::Foundation::Collections::IMapView GetCommands() noexcept; @@ -84,7 +84,7 @@ namespace winrt::TerminalApp::implementation guid _defaultProfile; com_ptr _keybindings; - std::vector<::TerminalApp::SettingsLoadWarnings> _keybindingsWarnings; + std::vector _keybindingsWarnings; Windows::Foundation::Collections::IMap _colorSchemes; Windows::Foundation::Collections::IMap _commands; diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index 46cc4bd46bc..8813262396d 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -122,7 +122,9 @@ - + + TerminalWarnings.idl + @@ -295,6 +297,7 @@ + diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index f7d377b278e..25b3e0dc291 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -2120,7 +2120,7 @@ namespace winrt::TerminalApp::implementation IVectorView profiles, IMapView schemes) { - std::vector<::TerminalApp::SettingsLoadWarnings> warnings; + std::vector warnings; std::vector sortedSchemes; sortedSchemes.reserve(schemes.Size()); diff --git a/src/cascadia/TerminalApp/TerminalWarnings.h b/src/cascadia/TerminalApp/TerminalWarnings.h index 3b0be2b4022..57250be7d8a 100644 --- a/src/cascadia/TerminalApp/TerminalWarnings.h +++ b/src/cascadia/TerminalApp/TerminalWarnings.h @@ -15,34 +15,8 @@ Author(s): --*/ #pragma once -namespace TerminalApp +namespace winrt::TerminalApp::implementation { - // SettingsLoadWarnings are scenarios where the settings contained - // information we knew was invalid, but we could recover from. - enum class SettingsLoadWarnings : uint32_t - { - MissingDefaultProfile = 0, - DuplicateProfile = 1, - UnknownColorScheme = 2, - InvalidBackgroundImage = 3, - InvalidIcon = 4, - AtLeastOneKeybindingWarning = 5, - TooManyKeysForChord = 6, - MissingRequiredParameter = 7, - LegacyGlobalsProperty = 8, - FailedToParseCommandJson = 9, - WARNINGS_SIZE // IMPORTANT: This MUST be the last value in this enum. It's an unused placeholder. - }; - - // SettingsLoadWarnings are scenarios where the settings had invalid state - // that we could not recover from. - enum class SettingsLoadErrors : uint32_t - { - NoProfiles = 0, - AllProfilesHidden = 1, - ERRORS_SIZE // IMPORTANT: This MUST be the last value in this enum. It's an unused placeholder. - }; - // This is a helper class to wrap up a SettingsLoadErrors into a proper // exception type. class SettingsException : public std::runtime_error diff --git a/src/cascadia/TerminalApp/TerminalWarnings.idl b/src/cascadia/TerminalApp/TerminalWarnings.idl new file mode 100644 index 00000000000..fd4558ad6cb --- /dev/null +++ b/src/cascadia/TerminalApp/TerminalWarnings.idl @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// Licensed under the MIT license. +#pragma once + +namespace TerminalApp +{ + // SettingsLoadWarnings are scenarios where the settings contained + // information we knew was invalid, but we could recover from. + enum SettingsLoadWarnings + { + MissingDefaultProfile = 0, + DuplicateProfile = 1, + UnknownColorScheme = 2, + InvalidBackgroundImage = 3, + InvalidIcon = 4, + AtLeastOneKeybindingWarning = 5, + TooManyKeysForChord = 6, + MissingRequiredParameter = 7, + LegacyGlobalsProperty = 8, + FailedToParseCommandJson = 9, + WARNINGS_SIZE // IMPORTANT: This MUST be the last value in this enum. It's an unused placeholder. + }; + + // SettingsLoadWarnings are scenarios where the settings had invalid state + // that we could not recover from. + enum SettingsLoadErrors + { + NoProfiles = 0, + AllProfilesHidden = 1, + ERRORS_SIZE // IMPORTANT: This MUST be the last value in this enum. It's an unused placeholder. + }; +}