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

Just never save the settings #2475

Merged
merged 1 commit into from
Aug 20, 2019
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
12 changes: 4 additions & 8 deletions src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,19 +680,15 @@ namespace winrt::TerminalApp::implementation

// Method Description:
// - Attempt to load the settings. If we fail for any reason, returns an error.
// Arguments:
// - saveOnLoad: If true, after loading the settings, we should re-write
// them to the file, to make sure the schema is updated. See
// `CascadiaSettings::LoadAll` for details.
// Return Value:
// - S_OK if we successfully parsed the settings, otherwise an appropriate HRESULT.
[[nodiscard]] HRESULT App::_TryLoadSettings(const bool saveOnLoad) noexcept
[[nodiscard]] HRESULT App::_TryLoadSettings() noexcept
{
HRESULT hr = E_FAIL;

try
{
auto newSettings = CascadiaSettings::LoadAll(saveOnLoad);
auto newSettings = CascadiaSettings::LoadAll();
_settings = std::move(newSettings);
const auto& warnings = _settings->GetWarnings();
hr = warnings.size() == 0 ? S_OK : S_FALSE;
Expand Down Expand Up @@ -733,7 +729,7 @@ namespace winrt::TerminalApp::implementation
// we should display the loading error.
// * We can't display the error now, because we might not have a
// UI yet. We'll display the error in _OnLoaded.
_settingsLoadedResult = _TryLoadSettings(true);
_settingsLoadedResult = _TryLoadSettings();

if (FAILED(_settingsLoadedResult))
{
Expand Down Expand Up @@ -813,7 +809,7 @@ namespace winrt::TerminalApp::implementation
// - don't change the settings (and don't actually apply the new settings)
// - don't persist them.
// - display a loading error
_settingsLoadedResult = _TryLoadSettings(false);
_settingsLoadedResult = _TryLoadSettings();

if (FAILED(_settingsLoadedResult))
{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace winrt::TerminalApp::implementation
void _ShowLoadWarningsDialog();
void _ShowLoadErrorsDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey);

[[nodiscard]] HRESULT _TryLoadSettings(const bool saveOnLoad) noexcept;
[[nodiscard]] HRESULT _TryLoadSettings() noexcept;
void _LoadSettings();
void _OpenSettings();

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/CascadiaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TerminalApp::CascadiaSettings final
CascadiaSettings();
~CascadiaSettings();

static std::unique_ptr<CascadiaSettings> LoadAll(const bool saveOnLoad = true);
static std::unique_ptr<CascadiaSettings> LoadAll();
void SaveAll() const;

winrt::Microsoft::Terminal::Settings::TerminalSettings MakeSettings(std::optional<GUID> profileGuid) const;
Expand Down
21 changes: 1 addition & 20 deletions src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ static constexpr std::string_view Utf8Bom{ u8"\uFEFF" };
// it will load the settings from our packaged localappdata. If we're
// running as an unpackaged application, it will read it from the path
// we've set under localappdata.
// Arguments:
// - saveOnLoad: If true, we'll write the settings back out after we load them,
// to make sure the schema is updated.
// Return Value:
// - a unique_ptr containing a new CascadiaSettings object.
std::unique_ptr<CascadiaSettings> CascadiaSettings::LoadAll(const bool saveOnLoad)
std::unique_ptr<CascadiaSettings> CascadiaSettings::LoadAll()
{
std::unique_ptr<CascadiaSettings> resultPtr;
std::optional<std::string> fileData = _ReadSettings();
Expand Down Expand Up @@ -70,22 +67,6 @@ std::unique_ptr<CascadiaSettings> CascadiaSettings::LoadAll(const bool saveOnLoa

// If this throws, the app will catch it and use the default settings (temporarily)
resultPtr->_ValidateSettings();

const bool foundWarnings = resultPtr->_warnings.size() > 0;

// Don't save on load if there were warnings - we tried to gracefully
// handle them.
if (saveOnLoad && !foundWarnings)
{
// Logically compare the json we've parsed from the file to what
// we'd serialize at runtime. If the values are different, then
// write the updated schema back out.
const Json::Value reserialized = resultPtr->ToJson();
if (reserialized != root)
{
resultPtr->SaveAll();
}
}
}
else
{
Expand Down