terminal/src/cascadia/TerminalApp/CascadiaSettings.h
Mike Griese 8a69be0cc7
Switch to jsoncpp as our json library (#1005)
Switch to using jsoncpp as our json library. This lets us pretty-print the json file by default, and lets users place comments in the json file.

We will now only re-write the file when the actual logical structure of the json object changes, not only when the serialization changes.

Unfortunately, this will remove any existing ordering of profiles, and make the order random. We don't terribly care though, because when #754 lands, this will be less painful.

It also introduces a top-level globals object to hold all the global properties, including keybindings. Existing profiles should gracefully upgrade.
2019-06-04 16:55:27 -05:00

76 lines
2.4 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- CascadiaSettings.hpp
Abstract:
- This class acts as the container for all app settings. It's composed of two
parts: Globals, which are app-wide settings, and Profiles, which contain
a set of settings that apply to a single instance of the terminal.
Also contains the logic for serializing and deserializing this object.
Author(s):
- Mike Griese - March 2019
--*/
#pragma once
#include <winrt/Microsoft.Terminal.TerminalControl.h>
#include "GlobalAppSettings.h"
#include "Profile.h"
namespace TerminalApp
{
class CascadiaSettings;
};
class TerminalApp::CascadiaSettings final
{
public:
CascadiaSettings();
~CascadiaSettings();
static std::unique_ptr<CascadiaSettings> LoadAll(const bool saveOnLoad = true);
void SaveAll() const;
winrt::Microsoft::Terminal::Settings::TerminalSettings MakeSettings(std::optional<GUID> profileGuid) const;
GlobalAppSettings& GlobalSettings();
std::basic_string_view<Profile> GetProfiles() const noexcept;
winrt::TerminalApp::AppKeyBindings GetKeybindings() const noexcept;
Json::Value ToJson() const;
static std::unique_ptr<CascadiaSettings> FromJson(const Json::Value& json);
static winrt::hstring GetSettingsPath();
const Profile* FindProfile(GUID profileGuid) const noexcept;
void CreateDefaults();
private:
GlobalAppSettings _globals;
std::vector<Profile> _profiles;
void _CreateDefaultKeybindings();
void _CreateDefaultSchemes();
void _CreateDefaultProfiles();
static bool _IsPackaged();
static void _SaveAsPackagedApp(const std::string& content);
static void _SaveAsUnpackagedApp(const std::string& content);
static std::wstring _GetFullPathToUnpackagedSettingsFile();
static winrt::hstring _GetPackagedSettingsPath();
static std::optional<std::string> _LoadAsPackagedApp();
static std::optional<std::string> _LoadAsUnpackagedApp();
static bool _isPowerShellCoreInstalledInPath(const std::wstring_view programFileEnv, std::filesystem::path& cmdline);
static bool _isPowerShellCoreInstalled(std::filesystem::path& cmdline);
static std::wstring ExpandEnvironmentVariableString(std::wstring_view source);
static Profile _CreateDefaultProfile(const std::wstring_view name);
};