diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml
index 78ad6a1..40f4b0f 100644
--- a/.github/workflows/release-please.yml
+++ b/.github/workflows/release-please.yml
@@ -11,6 +11,7 @@ permissions:
env:
APP_NAME: WindowTool
+ VER_FILE: ./source/version.h
jobs:
release:
@@ -29,6 +30,18 @@ jobs:
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
release-type: simple
+ - name: Generate & Commit Version Header
+ if: ${{ steps.release.outputs.release_created }}
+ run: |
+ echo "// Do not modify this file, it is overwritten by release-please.yml!" > ${{ env.VER_FILE }}
+ echo "#pragma once" >> ${{ env.VER_FILE }}
+ echo "constexpr const wchar_t APP_VERSION[] = L\"${{ steps.release.outputs.tag_name }}\"" >> ${{ env.VER_FILE }}
+ git config user.name "github-actions[bot]"
+ git config user.email "github-actions[bot]@users.noreply.github.com"
+ git add ${{ env.VER_FILE }}
+ git commit -m "chore: update version header to ${{ steps.release.outputs.tag_name }}"
+ git push
+
build-x64:
name: Build x64 Release
needs: release
diff --git a/.gitignore b/.gitignore
index e7cf555..8ae5752 100644
--- a/.gitignore
+++ b/.gitignore
@@ -250,3 +250,7 @@ AkavacheSqliteLinkerOverride.cs
NuGetBuild
WiX.Toolset.DummyFile.txt
GitHubVS.sln.DotSettings
+
+# Ignore version.h except in the release branch
+/source/version.h
+!release-branch-*
\ No newline at end of file
diff --git a/WindowTool.vcxproj b/WindowTool.vcxproj
index 2840c5f..2ef8ca2 100644
--- a/WindowTool.vcxproj
+++ b/WindowTool.vcxproj
@@ -25,6 +25,7 @@
+
diff --git a/WindowTool.vcxproj.filters b/WindowTool.vcxproj.filters
index 2249ff2..cca0c27 100644
--- a/WindowTool.vcxproj.filters
+++ b/WindowTool.vcxproj.filters
@@ -33,6 +33,9 @@
source
+
+ source
+
diff --git a/source/main.cpp b/source/main.cpp
index 4f937bc..62b237d 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -1,6 +1,4 @@
-// WindowTool.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
-
+#include "version.h"
#include "window_actions.h"
#include
#include
@@ -8,6 +6,7 @@
#include
bool should_show_help(const std::vector& arguments, std::function display_func);
+bool should_show_version(const std::vector& arguments);
int wmain(int argc, wchar_t* argv[])
{
@@ -17,6 +16,9 @@ int wmain(int argc, wchar_t* argv[])
window_tool::window_actions actions(arguments);
+ if (should_show_version(arguments))
+ return 0;
+
if (should_show_help(arguments, [actions]() { actions.display_usage(); }))
return 0;
@@ -37,3 +39,18 @@ bool should_show_help(const std::vector& arguments, std::function<
return false;
}
+
+bool should_show_version(const std::vector& arguments)
+{
+ std::unordered_set possibleVersionOptions = {
+ L"--version", L"-v"
+ };
+
+ if (arguments.size() > 1 && possibleVersionOptions.find(arguments[1]) != possibleVersionOptions.end())
+ {
+ std::wcout << L"v" << APP_VERSION << std::endl;
+ return true;
+ }
+
+ return false;
+}
diff --git a/source/window_actions.cpp b/source/window_actions.cpp
index 9bb4d31..e6924bd 100644
--- a/source/window_actions.cpp
+++ b/source/window_actions.cpp
@@ -1,4 +1,5 @@
#include "window_actions.h"
+#include "version.h"
#include
#include
#include
@@ -80,6 +81,7 @@ int window_actions::run()
void window_actions::display_usage() const
{
+ std::wcout << L"Window Tool Version " << APP_VERSION << std::endl;
std::wcout << L"Usage: " << _app_name << L" \"Window Title\" \"Action\" [ButtonName]" << std::endl
<< std::endl
<< L"Options surrounded by [] are optional, but do not include the brackets." << std::endl