terminal/src/cascadia/TerminalApp
Dustin L. Howett (MSFT) 15505337d8
Introduce a WinRT utils library and "checked resources" (#3350)
This commit introduces a C++/WinRT utility library and moves
ScopedResourceLoader into it. I decided to get uppity and introduce
something I like to call "checked resources." The idea is that every
resource reference from a library is knowable at compile time, and we
should be able to statically ensure that all resources exist.

This is a system that lets us immediately failfast (on launch) when a
library makes a static reference to a resource that doesn't exist at
runtime.

It exposes two new (preprocessor) APIs:
* `RS_(wchar_t)`: loads a localizable string resource by name.
* `USES_RESOURCE(wchar_t)`: marks a resource key as used, but is intended
  for loading images or passing static resource keys as parameters to
  functions that will look them up later.

Resource checking relies on diligent use of `USES_RESOURCE()` and `RS_()`
(which uses `USES_RESOURCE`), but can make sure we don't ship something
that'll blow up at runtime.

It works like this:

**IN DEBUG MODE**
- All resource names referenced through `USES_RESOURCE()` are emitted
  alongside their referencing filenames and line numbers into a static
  section of the binary.
  That section is named `.util$res$m`.

- We emit two sentinel values into two different sections, `.util$res$a`
  and `.util$res$z`.

- The linker sorts all sections alphabetically before crushing them
  together into the final binary.

- When we first construct a library's scoped resource loader, we
  iterate over every resource reference between `$a` and `$z` and check
  residency.

**IN RELEASE MODE**
- All checked resource code is compiled out.

Fixes #2146.

Macros are the only way to do something this cool, incidentally.

## Validation Steps Performed
Made references to a bunch of bad resources, tried to break it a lot.

It looks like this when it fails:

### App.cpp
```
36  static const std::array<std::wstring_view, 2> settingsLoadErrorsLabels {
37      USES_RESOURCE(L"NoProfilesText"),
38      USES_RESOURCE(L"AllProfilesHiddenText_HA_JUST_KIDDING")
39  };
```

```
WinRTUtils\LibraryResources.cpp(68)\TerminalApp.dll:
    FailFast(1) tid(1034) 8000FFFF Catastrophic failure
    Msg:[Resource AllProfilesHiddenText_HA_JUST_KIDDING not found in
      scope TerminalApp/Resources (App.cpp:38)] [EnsureAllResourcesArePresent]
```
2019-11-01 15:47:05 -07:00
..
lib Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
Resources/en-US Add a warning when a profile has an unknown color scheme (#3033) 2019-10-14 22:02:52 -07:00
ActionArgs.cpp Add keyboard shortcuts to increase and decrease font size (#2700) 2019-09-30 08:18:05 -05:00
ActionArgs.h Add keyboard shortcuts to increase and decrease font size (#2700) 2019-09-30 08:18:05 -05:00
ActionArgs.idl Add keyboard shortcuts to increase and decrease font size (#2700) 2019-09-30 08:18:05 -05:00
App.base.h Apply a GDI region to the top level Island window to allow dragging with a single Island (#929) 2019-06-25 13:06:11 -07:00
App.cpp Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
App.h Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
App.idl Enable setting an initial position and maximized launch (#2817) 2019-10-16 21:51:50 -07:00
App.xaml Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
AppActionHandlers.cpp Provide the CloseWindow warning experience for the 'X' button (#3049) 2019-10-10 17:09:07 -07:00
AppKeyBindings.cpp Add keyboard shortcuts to increase and decrease font size (#2700) 2019-09-30 08:18:05 -05:00
AppKeyBindings.h Add keyboard shortcuts to increase and decrease font size (#2700) 2019-09-30 08:18:05 -05:00
AppKeyBindings.idl Add keyboard shortcuts to increase and decrease font size (#2700) 2019-09-30 08:18:05 -05:00
AppKeyBindingsSerialization.cpp Add Cascading User + Default Settings (#2515) 2019-09-16 12:57:10 -07:00
AzureCloudShellGenerator.cpp Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
AzureCloudShellGenerator.h Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
CascadiaSettings.cpp Add a warning when a profile has an unknown color scheme (#3033) 2019-10-14 22:02:52 -07:00
CascadiaSettings.h Add a warning when a profile has an unknown color scheme (#3033) 2019-10-14 22:02:52 -07:00
CascadiaSettingsSerialization.cpp CascadiaSettings: Use map to find matching color scheme (#3288) 2019-10-31 10:11:54 -05:00
ColorScheme.cpp CascadiaSettings: Use map to find matching color scheme (#3288) 2019-10-31 10:11:54 -05:00
ColorScheme.h CascadiaSettings: Use map to find matching color scheme (#3288) 2019-10-31 10:11:54 -05:00
DefaultProfileUtils.cpp Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
DefaultProfileUtils.h Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
defaults.json Update cmd's default profile to disable acrylic (#3020) 2019-10-02 10:23:44 -07:00
FixVisualStudioBug.targets Fix the ut_app build for VS 16.2, 16.3 (#2347) 2019-08-09 13:21:45 -07:00
GlobalAppSettings.cpp Enable setting an initial position and maximized launch (#2817) 2019-10-16 21:51:50 -07:00
GlobalAppSettings.h Enable setting an initial position and maximized launch (#2817) 2019-10-16 21:51:50 -07:00
IDynamicProfileGenerator.h Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
init.cpp Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
JsonUtils.cpp Add Cascading User + Default Settings (#2515) 2019-09-16 12:57:10 -07:00
JsonUtils.h Add Cascading User + Default Settings (#2515) 2019-09-16 12:57:10 -07:00
KeyChordSerialization.cpp Allow the mapping of OEM keys ({}|\<>/_-=+) in key bindings (#2067) 2019-07-23 14:05:07 -07:00
KeyChordSerialization.h Support remapping keybindings (#748) 2019-05-21 09:26:04 -05:00
LegacyProfileGeneratorNamespaces.h Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
MinMaxCloseControl.cpp Propagate window style changes to the titlebar and minmax (#3025) 2019-10-02 10:27:07 -07:00
MinMaxCloseControl.h Propagate window style changes to the titlebar and minmax (#3025) 2019-10-02 10:27:07 -07:00
MinMaxCloseControl.idl Propagate window style changes to the titlebar and minmax (#3025) 2019-10-02 10:27:07 -07:00
MinMaxCloseControl.xaml Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
packages.config Switch to a non-release build of MUXc to fix elevated launch (#3278) 2019-10-22 11:48:09 -07:00
Pane.cpp Indicate which pane is focused with the Accent color on the pan… (#3060) 2019-11-01 15:06:11 -05:00
Pane.h Indicate which pane is focused with the Accent color on the pan… (#3060) 2019-11-01 15:06:11 -05:00
pch.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
pch.h Refactor TerminalApp and Add Tests for Xaml Content (#1164) 2019-07-15 14:27:56 -05:00
PowershellCoreProfileGenerator.cpp Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
PowershellCoreProfileGenerator.h Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
Profile.cpp Add a warning when a profile has an unknown color scheme (#3033) 2019-10-14 22:02:52 -07:00
Profile.h Add a warning when a profile has an unknown color scheme (#3033) 2019-10-14 22:02:52 -07:00
Tab.cpp Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
Tab.h Clean up Pane (#2494) 2019-08-28 07:40:16 -07:00
TabRowControl.cpp Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
TabRowControl.h Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
TabRowControl.idl Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
TabRowControl.xaml Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
TerminalApp.def Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
TerminalApp.vcxproj Combined changes to make the build work again (see inside) (#2945) 2019-09-30 10:39:55 -07:00
TerminalPage.cpp Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
TerminalPage.h Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
TerminalPage.idl Clean up boundary between terminal app and terminal page (#2208) 2019-09-04 14:34:06 -07:00
TerminalPage.xaml Enable dragging with the entire titlebar (#1948) 2019-07-18 17:21:33 -05:00
TerminalWarnings.h Add a warning when a profile has an unknown color scheme (#3033) 2019-10-14 22:02:52 -07:00
TitlebarControl.cpp Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
TitlebarControl.h Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
TitlebarControl.idl Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
TitlebarControl.xaml Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
userDefaults.json Add a schema reference to the userDefaults and patch one into user data (#2803) 2019-09-18 18:37:23 -07:00
Utils.cpp Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
Utils.h Upgrade to Microsoft.UI.Xaml 2.2 (#3027) 2019-10-14 22:41:43 -07:00
WslDistroGenerator.cpp Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00
WslDistroGenerator.h Add Dynamic Profile Generators (#2603) 2019-09-16 13:34:27 -07:00