diff --git a/SimpleCom/SerialSetup.cpp b/SimpleCom/SerialSetup.cpp index c142fe0..1860dd7 100644 --- a/SimpleCom/SerialSetup.cpp +++ b/SimpleCom/SerialSetup.cpp @@ -19,6 +19,7 @@ #include "stdafx.h" #include "SerialSetup.h" +#include "util.h" #include "WinAPIException.h" #include "resource.h" @@ -112,6 +113,10 @@ template void SimpleCom::CommandlineOption::set(T new_value) { #endif void SimpleCom::CommandlineHelpOption::set_from_arg(LPCTSTR arg) { + ProductInfo prodinfo; + + COUT << prodinfo.GetProductName() << _T(" ") << prodinfo.GetProductVersion() << std::endl; + COUT << prodinfo.GetLegalCopyright() << std::endl; COUT << R"( Usage: SimpleCom.exe @@ -170,6 +175,15 @@ static void InitializeDialog(HWND hDlg, SimpleCom::SerialSetup *setup) { // Initialize serial configuration. // Initial value is for serial console of Raspberry Pi. + TStringStream dlg_caption; + dlg_caption << _T("Serial Connection Setup"); + ProductInfo prodinfo; + LPCTSTR product_name = prodinfo.GetProductName(); + if (product_name != nullptr) { + dlg_caption << _T(" - ") << product_name << _T(" ") << prodinfo.GetProductVersion(); + } + SetWindowText(hDlg, dlg_caption.str().c_str()); + TString text_str; WPARAM cb_idx; diff --git a/SimpleCom/SimpleCom.rc b/SimpleCom/SimpleCom.rc index cfb87f9..518d326 100644 --- a/SimpleCom/SimpleCom.rc +++ b/SimpleCom/SimpleCom.rc @@ -51,7 +51,6 @@ END IDD_SETUP DIALOGEX 0, 0, 195, 204 STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION -CAPTION "Serial Connection Setup" FONT 9, "MS Shell Dlg", 400, 0, 0x0 BEGIN COMBOBOX IDC_SERIAL_DEVICE,8,9,181,105,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP diff --git a/SimpleCom/SimpleCom.vcxproj b/SimpleCom/SimpleCom.vcxproj index 310f20d..26d0c88 100644 --- a/SimpleCom/SimpleCom.vcxproj +++ b/SimpleCom/SimpleCom.vcxproj @@ -98,6 +98,7 @@ Console true + version.lib;%(AdditionalDependencies) @@ -115,6 +116,7 @@ Console true + version.lib;%(AdditionalDependencies) app.manifest @@ -140,6 +142,7 @@ true true true + version.lib;%(AdditionalDependencies) @@ -162,6 +165,7 @@ true true true + version.lib;%(AdditionalDependencies) powershell -ExecutionPolicy Unrestricted -File $(SolutionDir)zip-packaging.ps1 1.2.3 $(SolutionDir) @@ -182,6 +186,7 @@ Create + @@ -207,4 +212,4 @@ - + \ No newline at end of file diff --git a/SimpleCom/SimpleCom.vcxproj.filters b/SimpleCom/SimpleCom.vcxproj.filters index 778b1f3..30e52d3 100644 --- a/SimpleCom/SimpleCom.vcxproj.filters +++ b/SimpleCom/SimpleCom.vcxproj.filters @@ -45,6 +45,9 @@ ソース ファイル + + ソース ファイル + diff --git a/SimpleCom/util.cpp b/SimpleCom/util.cpp new file mode 100644 index 0000000..e5c39a4 --- /dev/null +++ b/SimpleCom/util.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2024, Yasumasa Suenaga + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ +#include "stdafx.h" + +#include "util.h" + + +ProductInfo::ProductInfo() { + TCHAR exeName[MAX_PATH]; + GetModuleFileName(NULL, exeName, MAX_PATH); + if (GetLastError() == ERROR_SUCCESS) { + LoadVersionInfo(exeName); + } + else { + data = nullptr; + data_len = 0; + } +} + +ProductInfo::~ProductInfo() { + if (data_len > 0) { + free(data); + } +} + +void ProductInfo::LoadVersionInfo(LPCTSTR exe_name) { + DWORD dummy = 0; + data_len = GetFileVersionInfoSize(exe_name, &dummy); + if (data_len == 0) { + data = nullptr; + return; + } + + data = (unsigned char *)malloc(data_len); + if (data == nullptr) { + data_len = 0; + return; + } + + if (!GetFileVersionInfo(exe_name, 0, data_len, data)) { + free(data); + data = nullptr; + data_len = 0; + return; + } +} + +LPCTSTR ProductInfo::GetString(LPCTSTR query) { + if (data_len > 0) { + LPTSTR name = nullptr; + UINT nameLen; + if (VerQueryValue(data, query, reinterpret_cast(&name), &nameLen)) { + return name; + } + } + return nullptr; +} + +LPCTSTR ProductInfo::GetProductName() { + // Neutral codepage (000004b0) + LPCTSTR query_result = GetString(_T("\\StringFileInfo\\000004b0\\ProductName")); + return query_result ? query_result : _T(""); +} + +LPCTSTR ProductInfo::GetProductVersion() { + // Neutral codepage (000004b0) + LPCTSTR query_result = GetString(_T("\\StringFileInfo\\000004b0\\ProductVersion")); + return query_result ? query_result : _T(""); +} + +LPCTSTR ProductInfo::GetLegalCopyright() { + // Neutral codepage (000004b0) + LPCTSTR query_result = GetString(_T("\\StringFileInfo\\000004b0\\LegalCopyright")); + return query_result ? query_result : _T("Copyright (C) Yasumasa Suenaga"); +} \ No newline at end of file diff --git a/SimpleCom/util.h b/SimpleCom/util.h index 25c0dff..039b316 100644 --- a/SimpleCom/util.h +++ b/SimpleCom/util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023, Yasumasa Suenaga + * Copyright (C) 2023, 2024, Yasumasa Suenaga * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -72,3 +72,23 @@ class RegistryKeyHandler { return hKey; } }; + +/* + * Class for handling product (SimpleCom) information. + */ +class ProductInfo { +private: + unsigned char* data; + DWORD data_len; + + void LoadVersionInfo(LPCTSTR exe_name); + LPCTSTR GetString(LPCTSTR query); + +public: + ProductInfo(); + ~ProductInfo(); + + LPCTSTR GetProductName(); + LPCTSTR GetProductVersion(); + LPCTSTR GetLegalCopyright(); +}; \ No newline at end of file diff --git a/SimpleComTest/SimpleComTest.vcxproj b/SimpleComTest/SimpleComTest.vcxproj index d5d1ed9..2958fae 100644 --- a/SimpleComTest/SimpleComTest.vcxproj +++ b/SimpleComTest/SimpleComTest.vcxproj @@ -100,7 +100,7 @@ Windows $(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - %(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj + %(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj @@ -116,7 +116,7 @@ Windows $(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - %(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj + %(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj @@ -136,7 +136,7 @@ true true $(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - %(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj + %(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj @@ -156,7 +156,7 @@ true true $(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - %(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj + %(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj