in src/propsheet/registry.cpp [682:1013]
VOID SetRegistryValues(
PCONSOLE_STATE_INFO pStateInfo,
DWORD dwPage)
{
HKEY hCurrentUserKey, hConsoleKey, hTitleKey;
NTSTATUS Status;
DWORD dwValue, i;
WCHAR awchBuffer[LF_FACESIZE];
//
// Open the current user registry key and console registry key.
//
Status = RegistrySerialization::s_OpenConsoleKey(&hCurrentUserKey, &hConsoleKey);
if (!NT_SUCCESS(Status))
{
return;
}
//
// Save the current page.
//
LOG_IF_FAILED(RegistrySerialization::s_SetValue(hConsoleKey,
CONSOLE_REGISTRY_CURRENTPAGE,
REG_DWORD,
(BYTE*)&dwPage,
sizeof(dwPage)));
//
// Open the console title subkey unless we're changing the defaults.
//
if (pStateInfo->Defaults)
{
hTitleKey = hConsoleKey;
}
else
{
Status = RegistrySerialization::s_CreateKey(hConsoleKey,
pStateInfo->OriginalTitle,
&hTitleKey);
if (!NT_SUCCESS(Status))
{
RegCloseKey(hConsoleKey);
RegCloseKey(hCurrentUserKey);
return;
}
}
//
// Save screen and popup colors and color table
//
dwValue = pStateInfo->ScreenAttributes;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_FILLATTR,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->PopupAttributes;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_POPUPATTR,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
for (i = 0; i < 16; i++)
{
dwValue = pStateInfo->ColorTable[i];
if (SUCCEEDED(StringCchPrintf(awchBuffer, ARRAYSIZE(awchBuffer), CONSOLE_REGISTRY_COLORTABLE, i)))
{
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
awchBuffer,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
}
}
//
// Save insert, quickedit, and fullscreen mode settings
//
dwValue = pStateInfo->InsertMode;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_INSERTMODE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->QuickEdit;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_QUICKEDIT,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
FAIL_FAST_IF(!(OEMCP != 0));
if (g_fEastAsianSystem)
{
dwValue = (DWORD)pStateInfo->CodePage;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_CODEPAGE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
}
//
// Save screen buffer size
//
dwValue = MAKELONG(pStateInfo->ScreenBufferSize.X,
pStateInfo->ScreenBufferSize.Y);
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_BUFFERSIZE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
//
// Save window size
//
dwValue = MAKELONG(pStateInfo->WindowSize.X,
pStateInfo->WindowSize.Y);
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_WINDOWSIZE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
//
// Save window position
//
if (pStateInfo->AutoPosition)
{
LOG_IF_FAILED(RegistrySerialization::s_DeleteValue(hTitleKey, CONSOLE_REGISTRY_WINDOWPOS));
}
else
{
dwValue = MAKELONG(pStateInfo->WindowPosX,
pStateInfo->WindowPosY);
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_WINDOWPOS,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
}
//
// Save font size, family, weight, and face name
//
dwValue = MAKELONG(pStateInfo->FontSize.X,
pStateInfo->FontSize.Y);
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_FONTSIZE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->FontFamily;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_FONTFAMILY,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->FontWeight;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_FONTWEIGHT,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_FACENAME,
REG_SZ,
(BYTE*)(pStateInfo->FaceName),
(DWORD)(wcslen(pStateInfo->FaceName) + 1) * sizeof(TCHAR)));
//
// Save cursor size
//
dwValue = pStateInfo->CursorSize;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_CURSORSIZE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
//
// Save history buffer size and number
//
dwValue = pStateInfo->HistoryBufferSize;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_HISTORYSIZE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->NumberOfHistoryBuffers;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_HISTORYBUFS,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->HistoryNoDup;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_HISTORYNODUP,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
// Save per-title V2 console state
dwValue = pStateInfo->fWrapText;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_LINEWRAP,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->fFilterOnPaste;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_FILTERONPASTE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->fCtrlKeyShortcutsDisabled;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_CTRLKEYSHORTCUTS_DISABLED,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->fLineSelection;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_LINESELECTION,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->bWindowTransparency;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_WINDOWALPHA,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
SetGlobalRegistryValues();
// Only save the "Terminal" settings if we launched as a v2 propsheet. The
// v1 console doesn't know anything about these settings, and their value
// will be incorrectly zero'd if we save in this state.
// See microsoft/terminal#2319 for more details.
if (gpStateInfo->fIsV2Console)
{
// Save cursor type and color
dwValue = pStateInfo->CursorType;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_CURSORTYPE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->CursorColor;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_CURSORCOLOR,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->InterceptCopyPaste;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_INTERCEPTCOPYPASTE,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->TerminalScrolling;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_TERMINALSCROLLING,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->DefaultForeground;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_DEFAULTFOREGROUND,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
dwValue = pStateInfo->DefaultBackground;
LOG_IF_FAILED(RegistrySerialization::s_UpdateValue(hConsoleKey,
hTitleKey,
CONSOLE_REGISTRY_DEFAULTBACKGROUND,
REG_DWORD,
(BYTE*)&dwValue,
sizeof(dwValue)));
}
//
// Close the registry keys
//
if (hTitleKey != hConsoleKey)
{
RegCloseKey(hTitleKey);
}
RegCloseKey(hConsoleKey);
RegCloseKey(hCurrentUserKey);
}