Use `.rc` files in TSM instead of string literals (#16844)

More prerequisite work for Action IDs - turns out if we add the action
IDs to the actions defined in `defaults.json` the string ends up being
too large and the compiler complains about it. Use a `.rc` file for
`defaults.json` instead and also for `enableColorSelection.json` +
`userDefaults.json`.
This commit is contained in:
PankajBhojwani 2024-03-14 13:50:07 -07:00 коммит произвёл GitHub
Родитель 806d5e2d05
Коммит 566b660eb2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
15 изменённых файлов: 119 добавлений и 69 удалений

Просмотреть файл

@ -43,6 +43,16 @@ winrt::com_ptr<Profile> Model::implementation::CreateChild(const winrt::com_ptr<
return profile;
}
std::string_view Model::implementation::LoadStringResource(int resourceID)
{
const HINSTANCE moduleInstanceHandle{ wil::GetModuleInstanceHandle() };
const auto resource = FindResourceW(moduleInstanceHandle, MAKEINTRESOURCEW(resourceID), RT_RCDATA);
const auto loaded = LoadResource(moduleInstanceHandle, resource);
const auto sz = SizeofResource(moduleInstanceHandle, resource);
const auto ptr = LockResource(loaded);
return { reinterpret_cast<const char*>(ptr), sz };
}
winrt::hstring CascadiaSettings::Hash() const noexcept
{
return _hash;

Просмотреть файл

@ -29,6 +29,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
std::string_view LoadStringResource(int resourceID);
winrt::com_ptr<Profile> CreateChild(const winrt::com_ptr<Profile>& parent);
class SettingsTypedDeserializationException final : public std::runtime_error

Просмотреть файл

@ -8,6 +8,7 @@
#include <fmt/chrono.h>
#include <shlobj.h>
#include <til/latch.h>
#include "resource.h"
#include "AzureCloudShellGenerator.h"
#include "PowershellCoreProfileGenerator.h"
@ -17,15 +18,9 @@
#include "SshHostGenerator.h"
#endif
// The following files are generated at build time into the "Generated Files" directory.
// defaults.h is a file containing the default json settings in a std::string_view.
#include "defaults.h"
// userDefault.h is like the above, but with a default template for the user's settings.json.
#include <LegacyProfileGeneratorNamespaces.h>
#include "userDefaults.h"
#include "enableColorSelection.h"
#include "ApplicationState.h"
#include "DefaultTerminal.h"
#include "FileUtils.h"
@ -349,7 +344,7 @@ void SettingsLoader::FinalizeLayering()
// actions, this is the time to do it.
if (userSettings.globals->EnableColorSelection())
{
const auto json = _parseJson(EnableColorSelectionSettingsJson);
const auto json = _parseJson(LoadStringResource(IDR_ENABLE_COLOR_SELECTION));
const auto globals = GlobalAppSettings::FromJson(json.root);
userSettings.globals->AddLeastImportantParent(globals);
}
@ -972,10 +967,10 @@ try
// Only uses default settings when firstTimeSetup is true and releaseSettingExists is false
// Otherwise use existing settingsString
const auto settingsStringView = (firstTimeSetup && !releaseSettingExists) ? UserSettingsJson : settingsString;
const auto settingsStringView = (firstTimeSetup && !releaseSettingExists) ? LoadStringResource(IDR_USER_DEFAULTS) : settingsString;
auto mustWriteToDisk = firstTimeSetup;
SettingsLoader loader{ settingsStringView, DefaultJson };
SettingsLoader loader{ settingsStringView, LoadStringResource(IDR_DEFAULTS) };
// Generate dynamic profiles and add them as parents of user profiles.
// That way the user profiles will get appropriate defaults from the generators (like icons and such).
@ -1127,7 +1122,7 @@ void CascadiaSettings::_researchOnLoad()
// - a unique_ptr to a CascadiaSettings with the settings from defaults.json
Model::CascadiaSettings CascadiaSettings::LoadDefaults()
{
return *winrt::make_self<CascadiaSettings>(std::string_view{}, DefaultJson);
return *winrt::make_self<CascadiaSettings>(std::string_view{}, LoadStringResource(IDR_DEFAULTS));
}
CascadiaSettings::CascadiaSettings(const winrt::hstring& userJSON, const winrt::hstring& inboxJSON) :

Просмотреть файл

@ -0,0 +1,31 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(65001)
/////////////////////////////////////////////////////////////////////////////
//
// RCDATA
//
IDR_DEFAULTS RCDATA "Generated Files\defaults.json"
IDR_USER_DEFAULTS RCDATA "Generated Files\userDefaults.json"
IDR_ENABLE_COLOR_SELECTION RCDATA "Generated Files\enableColorSelection.json"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -20,6 +20,7 @@
<Import Project="$(OpenConsoleDir)src\cppwinrt.build.pre.props" />
<!-- ========================= Headers ======================== -->
<ItemGroup>
<ClInclude Include="resource.h" />
<ClInclude Include="ActionArgsMagic.h" />
<ClInclude Include="NewTabMenuEntry.h">
<DependentUpon>NewTabMenuEntry.idl</DependentUpon>
@ -238,6 +239,9 @@
<PRIResource Include="Resources\en-US\Resources.resw" />
<OCResourceDirectory Include="Resources" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Microsoft.Terminal.Settings.Model.rc" />
</ItemGroup>
<!-- ========================= Project References ======================== -->
<ItemGroup>
<!--
@ -320,26 +324,13 @@
<Import Project="$(OpenConsoleDir)src\common.nugetversions.targets" />
<!-- PowerShell version check, outputs error if the wrong version is installed. -->
<Target Name="_WindowsPowershellVersionCheck" BeforeTargets="BeforeClCompile">
<Exec Command="powershell.exe -NoProfile -ExecutionPolicy Unrestricted -File &quot;$(OpenConsoleDir)\tools\WindowsCheckPSVersion.ps1&quot;" />
</Target>
<Target Name="_PowershellVersionCheck" BeforeTargets="BeforeClCompile">
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\CheckPSVersion.ps1&quot;" />
</Target>
<!-- This target will take our defaults.json and stamp it into a .h file that
we can include in the code directly. This way, we don't need to worry about
failing to load the default settings at runtime. -->
<Target Name="_TerminalAppGenerateDefaultsH" Inputs="defaults.json" Outputs="Generated Files\defaults.h" BeforeTargets="BeforeClCompile">
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\GenerateHeaderForJson.ps1&quot; -JsonFile defaults.json -OutPath &quot;Generated Files\defaults.h&quot; -VariableName DefaultJson" />
</Target>
<!-- Same as above, but for the default settings.json template -->
<Target Name="_TerminalAppGenerateUserSettingsH" Inputs="userDefaults.json" Outputs="Generated Files\userDefaults.h" BeforeTargets="BeforeClCompile">
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\GenerateHeaderForJson.ps1&quot; -JsonFile userDefaults.json -OutPath &quot;Generated Files\userDefaults.h&quot; -VariableName UserSettingsJson" />
</Target>
<!-- Same as above, but for the enableColorSelection actions -->
<Target Name="_TerminalAppGenerateEnableColorSelectionSettingsH" Inputs="enableColorSelection.json" Outputs="Generated Files\enableColorSelection.h" BeforeTargets="BeforeClCompile">
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\GenerateHeaderForJson.ps1&quot; -JsonFile enableColorSelection.json -OutPath &quot;Generated Files\enableColorSelection.h&quot; -VariableName EnableColorSelectionSettingsJson" />
</Target>
<Import Project="$(SolutionDir)build\rules\CollectWildcardResources.targets" />
<Target Name="BeforeResourceCompile" Inputs="defaults.json;userDefaults.json;enableColorSelection.json" Outputs="Generated Files\defaults.json;Generated Files\userDefaults.json;Generated Files\enableColorSelection.json">
<Exec Command="powershell.exe -NoProfile -ExecutionPolicy Unrestricted -File &quot;$(OpenConsoleDir)\tools\WindowsCheckPSVersion.ps1&quot;" />
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\CheckPSVersion.ps1&quot;" />
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\CompressJson.ps1&quot; -JsonFile defaults.json -OutPath &quot;Generated Files\defaults.json&quot;" />
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\CompressJson.ps1&quot; -JsonFile userDefaults.json -OutPath &quot;Generated Files\userDefaults.json&quot;" />
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\CompressJson.ps1&quot; -JsonFile enableColorSelection.json -OutPath &quot;Generated Files\enableColorSelection.json&quot;" />
</Target>
</Project>

Просмотреть файл

@ -129,7 +129,7 @@
<AdditionalIncludeDirectories>$(OpenConsoleDir)\dep\jsoncpp\json;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies);user32.lib</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies);user32.lib;$(IntDir)\..\Microsoft.Terminal.Settings.Model.lib\Microsoft.Terminal.Settings.Model.res</AdditionalDependencies>
<!-- TSM Lib contains a DllMain that we need to force the use of. -->
<AdditionalOptions Condition="'$(Platform)'=='Win32'">/INCLUDE:_DllMain@12 %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Platform)'!='Win32'">/INCLUDE:DllMain %(AdditionalOptions)</AdditionalOptions>

Просмотреть файл

@ -0,0 +1,7 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by WindowsTerminal.rc
//
#define IDR_DEFAULTS 101
#define IDR_USER_DEFAULTS 102
#define IDR_ENABLE_COLOR_SELECTION 103

Просмотреть файл

@ -5,12 +5,10 @@
#include "../TerminalSettingsModel/ColorScheme.h"
#include "../TerminalSettingsModel/CascadiaSettings.h"
#include "../TerminalSettingsModel/resource.h"
#include "JsonTestClass.h"
#include "TestUtils.h"
#include <defaults.h>
#include <userDefaults.h>
using namespace Microsoft::Console;
using namespace WEX::Logging;
using namespace WEX::TestExecution;
@ -541,7 +539,7 @@ namespace SettingsModelUnitTests
]
})" };
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, DefaultJson);
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, implementation::LoadStringResource(IDR_DEFAULTS));
VERIFY_ARE_EQUAL(0u, settings->Warnings().Size());
VERIFY_ARE_EQUAL(4u, settings->AllProfiles().Size());
@ -619,7 +617,7 @@ namespace SettingsModelUnitTests
]
})" };
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, DefaultJson);
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, implementation::LoadStringResource(IDR_DEFAULTS));
VERIFY_ARE_EQUAL(0u, settings->Warnings().Size());
VERIFY_ARE_EQUAL(4u, settings->AllProfiles().Size());
@ -656,7 +654,7 @@ namespace SettingsModelUnitTests
]
})" };
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, DefaultJson);
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, implementation::LoadStringResource(IDR_DEFAULTS));
const auto profiles = settings->AllProfiles();
VERIFY_ARE_EQUAL(5u, profiles.Size());
VERIFY_ARE_EQUAL(L"ThisProfileIsGood", profiles.GetAt(0).Name());
@ -1065,7 +1063,7 @@ namespace SettingsModelUnitTests
const auto guid1String = L"{6239a42c-1111-49a3-80bd-e8fdd045185c}";
const winrt::guid guid1{ Utils::GuidFromString(guid1String) };
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, DefaultJson);
const auto settings = winrt::make_self<implementation::CascadiaSettings>(settings0String, implementation::LoadStringResource(IDR_DEFAULTS));
VERIFY_ARE_EQUAL(guid1String, settings->GlobalSettings().UnparsedDefaultProfile());
VERIFY_ARE_EQUAL(4u, settings->AllProfiles().Size());
@ -2006,7 +2004,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ std::string_view{}, DefaultJson };
implementation::SettingsLoader loader{ std::string_view{}, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(winrt::hstring{ fragmentSource }, fragmentJson);
loader.FinalizeLayering();
@ -2029,7 +2027,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ std::string_view{}, DefaultJson };
implementation::SettingsLoader loader{ std::string_view{}, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(winrt::hstring{ fragmentSource }, fragmentJson);
loader.FinalizeLayering();
@ -2054,7 +2052,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ std::string_view{}, DefaultJson };
implementation::SettingsLoader loader{ std::string_view{}, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(winrt::hstring{ fragmentSource }, fragmentJson);
loader.FinalizeLayering();
@ -2088,7 +2086,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ std::string_view{}, DefaultJson };
implementation::SettingsLoader loader{ std::string_view{}, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(winrt::hstring{ fragmentSource }, fragmentJson);
loader.FinalizeLayering();
@ -2123,7 +2121,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ std::string_view{}, DefaultJson };
implementation::SettingsLoader loader{ std::string_view{}, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(winrt::hstring{ fragmentSource }, fragmentJson);
loader.FinalizeLayering();
@ -2149,7 +2147,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ std::string_view{}, DefaultJson };
implementation::SettingsLoader loader{ std::string_view{}, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(winrt::hstring{ fragmentSource }, fragmentJson);
loader.FinalizeLayering();
@ -2175,7 +2173,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ std::string_view{}, DefaultJson };
implementation::SettingsLoader loader{ std::string_view{}, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(winrt::hstring{ fragmentSource }, fragmentJson);
loader.FinalizeLayering();
@ -2189,7 +2187,7 @@ namespace SettingsModelUnitTests
const auto oldResult{ oldSettings->ToJson() };
Log::Comment(L"Now, create a _new_ settings object from the re-serialization of the first");
implementation::SettingsLoader newLoader{ toString(oldResult), DefaultJson };
implementation::SettingsLoader newLoader{ toString(oldResult), implementation::LoadStringResource(IDR_DEFAULTS) };
// NOTABLY! Don't load the fragment here.
newLoader.MergeInboxIntoUserSettings();
newLoader.FinalizeLayering();
@ -2223,7 +2221,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader loader{ settings1Json, DefaultJson };
implementation::SettingsLoader loader{ settings1Json, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.FinalizeLayering();

Просмотреть файл

@ -6,11 +6,10 @@
#include "../TerminalSettingsModel/NewTabMenuEntry.h"
#include "../TerminalSettingsModel/FolderEntry.h"
#include "../TerminalSettingsModel/CascadiaSettings.h"
#include "../TerminalSettingsModel/resource.h"
#include "../types/inc/colorTable.hpp"
#include "JsonTestClass.h"
#include <defaults.h>
using namespace Microsoft::Console;
using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;
@ -37,7 +36,7 @@ namespace SettingsModelUnitTests
try
{
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, DefaultJson) };
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, LoadStringResource(IDR_DEFAULTS)) };
VERIFY_ARE_EQUAL(0u, settings->Warnings().Size());
@ -71,7 +70,7 @@ namespace SettingsModelUnitTests
try
{
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, DefaultJson) };
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, LoadStringResource(IDR_DEFAULTS)) };
VERIFY_ARE_EQUAL(0u, settings->Warnings().Size());

Просмотреть файл

@ -5,10 +5,9 @@
#include "../TerminalSettingsModel/ColorScheme.h"
#include "../TerminalSettingsModel/CascadiaSettings.h"
#include "../TerminalSettingsModel/resource.h"
#include "JsonTestClass.h"
#include <defaults.h>
using namespace Microsoft::Console;
using namespace winrt::Microsoft::Terminal::Settings::Model;
using namespace WEX::Logging;

Просмотреть файл

@ -5,9 +5,9 @@
#include "../TerminalSettingsModel/ColorScheme.h"
#include "../TerminalSettingsModel/CascadiaSettings.h"
#include "../TerminalSettingsModel/resource.h"
#include "JsonTestClass.h"
#include "TestUtils.h"
#include <defaults.h>
using namespace Microsoft::Console;
using namespace WEX::Logging;
@ -588,14 +588,14 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader oldLoader{ oldSettingsJson, DefaultJson };
implementation::SettingsLoader oldLoader{ oldSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
oldLoader.MergeInboxIntoUserSettings();
oldLoader.FinalizeLayering();
VERIFY_IS_TRUE(oldLoader.FixupUserSettings(), L"Validate that this will indicate we need to write them back to disk");
const auto oldSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(oldLoader));
const auto oldResult{ oldSettings->ToJson() };
implementation::SettingsLoader newLoader{ newSettingsJson, DefaultJson };
implementation::SettingsLoader newLoader{ newSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
newLoader.MergeInboxIntoUserSettings();
newLoader.FinalizeLayering();
newLoader.FixupUserSettings();
@ -630,7 +630,7 @@ namespace SettingsModelUnitTests
]
})" };
implementation::SettingsLoader oldLoader{ oldSettingsJson, DefaultJson };
implementation::SettingsLoader oldLoader{ oldSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
oldLoader.MergeInboxIntoUserSettings();
oldLoader.FinalizeLayering();
oldLoader.FixupUserSettings();
@ -638,7 +638,7 @@ namespace SettingsModelUnitTests
const auto oldResult{ oldSettings->ToJson() };
Log::Comment(L"Now, create a _new_ settings object from the re-serialization of the first");
implementation::SettingsLoader newLoader{ toString(oldResult), DefaultJson };
implementation::SettingsLoader newLoader{ toString(oldResult), implementation::LoadStringResource(IDR_DEFAULTS) };
newLoader.MergeInboxIntoUserSettings();
newLoader.FinalizeLayering();
newLoader.FixupUserSettings();
@ -763,14 +763,14 @@ namespace SettingsModelUnitTests
]
})-" };
implementation::SettingsLoader oldLoader{ oldSettingsJson, DefaultJson };
implementation::SettingsLoader oldLoader{ oldSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
oldLoader.MergeInboxIntoUserSettings();
oldLoader.FinalizeLayering();
VERIFY_IS_TRUE(oldLoader.FixupUserSettings(), L"Validate that this will indicate we need to write them back to disk");
const auto oldSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(oldLoader));
const auto oldResult{ oldSettings->ToJson() };
implementation::SettingsLoader newLoader{ newSettingsJson, DefaultJson };
implementation::SettingsLoader newLoader{ newSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
newLoader.MergeInboxIntoUserSettings();
newLoader.FinalizeLayering();
newLoader.FixupUserSettings();
@ -860,14 +860,14 @@ namespace SettingsModelUnitTests
]
})-" };
implementation::SettingsLoader oldLoader{ oldSettingsJson, DefaultJson };
implementation::SettingsLoader oldLoader{ oldSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
oldLoader.MergeInboxIntoUserSettings();
oldLoader.FinalizeLayering();
VERIFY_IS_TRUE(oldLoader.FixupUserSettings(), L"Validate that this will indicate we need to write them back to disk");
const auto oldSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(oldLoader));
const auto oldResult{ oldSettings->ToJson() };
implementation::SettingsLoader newLoader{ newSettingsJson, DefaultJson };
implementation::SettingsLoader newLoader{ newSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
newLoader.MergeInboxIntoUserSettings();
newLoader.FinalizeLayering();
newLoader.FixupUserSettings();
@ -932,14 +932,14 @@ namespace SettingsModelUnitTests
"schemes": [ ]
})-" };
implementation::SettingsLoader oldLoader{ oldSettingsJson, DefaultJson };
implementation::SettingsLoader oldLoader{ oldSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
oldLoader.MergeInboxIntoUserSettings();
oldLoader.FinalizeLayering();
VERIFY_IS_TRUE(oldLoader.FixupUserSettings(), L"Validate that this will indicate we need to write them back to disk");
const auto oldSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(oldLoader));
const auto oldResult{ oldSettings->ToJson() };
implementation::SettingsLoader newLoader{ newSettingsJson, DefaultJson };
implementation::SettingsLoader newLoader{ newSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
newLoader.MergeInboxIntoUserSettings();
newLoader.FinalizeLayering();
newLoader.FixupUserSettings();

Просмотреть файл

@ -77,7 +77,7 @@
<DisableSpecificWarnings>4702;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>onecoreuap.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>onecoreuap.lib;%(AdditionalDependencies);$(IntDir)\..\Microsoft.Terminal.Settings.Model.lib\Microsoft.Terminal.Settings.Model.res</AdditionalDependencies>
<!--
SettingsModelLib contains a DllMain that we need to force the use of.
If you don't have this, then you'll see an error like

Просмотреть файл

@ -5,11 +5,10 @@
#include "../TerminalSettingsModel/Theme.h"
#include "../TerminalSettingsModel/CascadiaSettings.h"
#include "../TerminalSettingsModel/resource.h"
#include "../types/inc/colorTable.hpp"
#include "JsonTestClass.h"
#include <defaults.h>
using namespace Microsoft::Console;
using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;
@ -180,7 +179,7 @@ namespace SettingsModelUnitTests
try
{
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, DefaultJson) };
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, LoadStringResource(IDR_DEFAULTS)) };
const auto& themes{ settings->GlobalSettings().Themes() };
{
@ -236,7 +235,7 @@ namespace SettingsModelUnitTests
try
{
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, DefaultJson) };
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, LoadStringResource(IDR_DEFAULTS)) };
VERIFY_ARE_EQUAL(1u, settings->Warnings().Size());
VERIFY_ARE_EQUAL(Settings::Model::SettingsLoadWarnings::UnknownTheme, settings->Warnings().GetAt(0));

Просмотреть файл

@ -167,6 +167,13 @@
</Link>
</ItemDefinitionGroup>
<!-- Work around the Windows Store platform not specifying a TargetMachine for static libraries -->
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
<Lib>
<TargetMachine>MachineX86</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<!-- For Debug ONLY -->
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>

13
tools/CompressJson.ps1 Normal file
Просмотреть файл

@ -0,0 +1,13 @@
# This script is used for taking a json file and stripping the whitespace from it.
param (
[parameter(Mandatory = $true)]
[string]$JsonFile,
[parameter(Mandatory = $true)]
[string]$OutPath
)
$jsonData = Get-Content -Raw $JsonFile | ConvertFrom-Json | ConvertTo-Json -Compress -Depth 100
$jsonData | Out-File -FilePath $OutPath -Encoding utf8