Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version info to help message and dialog caption #48

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions SimpleCom/SerialSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "stdafx.h"

#include "SerialSetup.h"
#include "util.h"
#include "WinAPIException.h"
#include "resource.h"

Expand Down Expand Up @@ -112,6 +113,10 @@ template<typename T> void SimpleCom::CommandlineOption<T>::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 <options> <COM port>
Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion SimpleCom/SimpleCom.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion SimpleCom/SimpleCom.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -115,6 +116,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>app.manifest</AdditionalManifestFiles>
Expand All @@ -140,6 +142,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -162,6 +165,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>powershell -ExecutionPolicy Unrestricted -File $(SolutionDir)zip-packaging.ps1 1.2.3 $(SolutionDir)</Command>
Expand All @@ -182,6 +186,7 @@
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="util.cpp" />
<ClCompile Include="WinAPIException.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -207,4 +212,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
3 changes: 3 additions & 0 deletions SimpleCom/SimpleCom.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<ClCompile Include="LogWriter.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="util.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SerialSetup.h">
Expand Down
91 changes: 91 additions & 0 deletions SimpleCom/util.cpp
Original file line number Diff line number Diff line change
@@ -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<LPVOID*>(&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");
}
22 changes: 21 additions & 1 deletion SimpleCom/util.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
};
8 changes: 4 additions & 4 deletions SimpleComTest/SimpleComTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalLibraryDirectories>$(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand All @@ -116,7 +116,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalLibraryDirectories>$(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -136,7 +136,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -156,7 +156,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(ProjectDir)..\SimpleCom\$(Platform)\$(Configuration);$(ProjectDir)..\SimpleCom\SimpleCom\$(Platform)\$(Configuration);$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies);WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies);version.lib;WinAPIException.obj;debug.obj;stdafx.obj;SerialPortWriter.obj;SerialSetup.obj;SerialDeviceScanner.obj;EnumValue.obj;LogWriter.obj;util.obj</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
Loading