Skip to content

Commit

Permalink
Added OS version to About
Browse files Browse the repository at this point in the history
  • Loading branch information
mkitzan committed Nov 23, 2019
1 parent 171f00c commit 460fdd9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Temporarily using the Windows Terminal default settings.
<value>About</value>
</data>
<data name="VersionLabelText" xml:space="preserve">
<value>Version:</value>
<value>WT Version:</value>
</data>
<data name="DocumentationLabelText" xml:space="preserve">
<value>Documentation
Expand Down Expand Up @@ -210,4 +210,7 @@ Temporarily using the Windows Terminal default settings.
<data name="CloseWindowWarningTitle" xml:space="preserve">
<value>Do you want to close all tabs?</value>
</data>
<data name="OsVersionLabelText" xml:space="preserve">
<value>OS Version:</value>
</data>
</root>
43 changes: 42 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#include <LibraryResources.h>

#include <Windows.h>
#include <wil\Resource.h>

#include "TerminalPage.g.cpp"
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>

Expand Down Expand Up @@ -133,6 +136,38 @@ namespace winrt::TerminalApp::implementation
_showDialogHandlers(*this, dialog);
}

// Method Description:
// - Implements the MSDN suggested method of obtaining the full OS version number
// https://docs.microsoft.com/en-us/windows/win32/sysinfo/getting-the-system-version
// - On failure the output wstring will be L"0.0.0.0"
std::wstring TerminalPage::_GetWindowsVersion()
{
const auto dll{ L"kernel32.dll" };
DWORD fill{};
const auto infoSize{ GetFileVersionInfoSizeExW(FILE_VER_GET_NEUTRAL, dll, &fill) };
auto buffer{ wil::make_unique_nothrow<BYTE[]>(infoSize) };
// clear varaibles for use in case of failure
WORD osMaj{}, osMin{}, osBld{}, osRev{};

if (GetFileVersionInfoExW(FILE_VER_GET_NEUTRAL, dll, fill, infoSize, buffer.get()))
{
VS_FIXEDFILEINFO* versionInfo{ nullptr };
UINT size{};

if (VerQueryValueW(buffer.get(), L"\\", (LPVOID*)&versionInfo, &size))
{
osMaj = HIWORD(versionInfo->dwProductVersionMS);
osMin = LOWORD(versionInfo->dwProductVersionMS);
osBld = HIWORD(versionInfo->dwProductVersionLS);
osRev = LOWORD(versionInfo->dwProductVersionLS);
}
}

std::wstringstream osVersionStream{};
osVersionStream << osMaj << L"." << osMin << L"." << osBld << L"." << osRev;
return osVersionStream.str();
}

// Method Description:
// - Show a dialog with "About" information. Displays the app's Display
// Name, version, getting started link, documentation link, and release
Expand All @@ -141,6 +176,7 @@ namespace winrt::TerminalApp::implementation
{
const auto title = RS_(L"AboutTitleText");
const auto versionLabel = RS_(L"VersionLabelText");
const auto osVersionLabel = RS_(L"OsVersionLabelText");
const auto gettingStartedLabel = RS_(L"GettingStartedLabelText");
const auto documentationLabel = RS_(L"DocumentationLabelText");
const auto releaseNotesLabel = RS_(L"ReleaseNotesLabelText");
Expand All @@ -150,6 +186,8 @@ namespace winrt::TerminalApp::implementation
const auto package = winrt::Windows::ApplicationModel::Package::Current();
const auto packageName = package.DisplayName();
const auto version = package.Id().Version();
const auto osVersion = _GetWindowsVersion();

winrt::Windows::UI::Xaml::Documents::Run about;
winrt::Windows::UI::Xaml::Documents::Run gettingStarted;
winrt::Windows::UI::Xaml::Documents::Run documentation;
Expand Down Expand Up @@ -177,7 +215,8 @@ namespace winrt::TerminalApp::implementation

// Format our about text. It will look like the following:
// <Display Name>
// Version: <Major>.<Minor>.<Build>.<Revision>
// WT Version: <WtMajor>.<WtMinor>.<WtBuild>.<WtRevision>
// OS Version: <OsMajor>.<OsMinor>.<OsBuild>.<OsRevision>
// Getting Started
// Documentation
// Release Notes
Expand All @@ -187,6 +226,8 @@ namespace winrt::TerminalApp::implementation
aboutTextStream << versionLabel.c_str() << L" ";
aboutTextStream << version.Major << L"." << version.Minor << L"." << version.Build << L"." << version.Revision << L"\n";

aboutTextStream << osVersionLabel.c_str() << L" " << osVersion.c_str() << L"\n";

winrt::hstring aboutText{ aboutTextStream.str() };
about.Text(aboutText);

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace winrt::TerminalApp::implementation
std::optional<int> _rearrangeFrom;
std::optional<int> _rearrangeTo;

std::wstring _GetWindowsVersion();
void _ShowAboutDialog();
void _ShowCloseWarningDialog();

Expand Down

0 comments on commit 460fdd9

Please sign in to comment.