Skip to content

[GEN][ZH] Generate git version information and print it in the Game Window title, Options Menu (and Main Menu) #1219

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

Merged
merged 4 commits into from
Jul 15, 2025

Conversation

xezon
Copy link

@xezon xezon commented Jun 30, 2025

This change generates information from git and makes it available in the game.

The Window Title now prints additional version information unique to this project. R stands for revision and it simply shows the commit count. We can tweak this if we want to show git tag or commit hash, but for now this appears to be sufficient. The label "By" is technically localized.

The Options Menu (and the Main Menu: "MainMenu.wnd:LabelVersion") also print additional information, including the last commit time (UTC). It also shows the EXE and INI crc's.

versioninfo

TODO

  • Replicate in Generals
  • Log out version
  • Fix constness
  • Check EXE properties

@xezon xezon added this to the Code foundation build up milestone Jun 30, 2025
@xezon xezon requested a review from OmniBlade June 30, 2025 20:23
@xezon xezon added Enhancement Is new feature or request GUI For graphical user interface Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour labels Jun 30, 2025
@xezon
Copy link
Author

xezon commented Jul 1, 2025

One more thing we can do here is log out the version too.

@@ -108,36 +119,15 @@ UnicodeString Version::getUnicodeVersion( void )
return version;
}

UnicodeString Version::getFullUnicodeVersion( void )
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this function because it was almost a duplicate of the one above. I combined what it does with the function above.

NameKeyType versionID = TheNameKeyGenerator->nameToKey( AsciiString("OptionsMenu.wnd:LabelVersion") );
GameWindow *labelVersion = TheWindowManager->winGetWindowFromId( NULL, versionID );
UnicodeString versionString;
versionString.format(TheGameText->fetch("Version:Format2").str(), (GetRegistryVersion() >> 16), (GetRegistryVersion() & 0xffff));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this read the version number from the registry. This is crazy. The version in the registry is meaningless. For example, changing the version from 1 04 to 1 05 in the registry will not magically upgrade the executable.

version.format(TheGameText->fetch("Version:Format3").str(), m_major, m_minor, m_buildNum);
else
version.format(TheGameText->fetch("Version:Format4").str(), m_major, m_minor, m_buildNum, m_localBuildNum,
m_buildUser.getCharAt(0), m_buildUser.getCharAt(1));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be inclined to change this to use the git commit author. You hard code this elsewhere to be "SuperHackers" which I assume is intended to be like a nintendo seal of approval, but anyone forking the repo and building it without changing that will also make a SuperHackers stamped binary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this Build User thing needs more work, because as you say, it is not really unique to us publishing it, if it is embedded as a plain string. I do not know what to do with it at this time.

Using Git Commit Author does not work, because that name is not stable. At least not for the CI builds. For local builds it probably would be fine.

We can use Git Commit Author, and override that with the build user if that is set (from CI).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original game, it seems that the build user was effectively the username of whoever authored the final build which the commit author is kind of an analog to. I like the idea of passing something from the CI which will differ if built on someone elses such as the repo owner and then falling back to commit author for local builds.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved. Now, VERSION_BUILDUSER (and VERSION_BUILDLOC) are empty strings, so build user will default to last git commit author name.

I do not yet know how we generate VERSION_BUILDUSER and VERSION_BUILDLOC, but that can be another change in the future.

@xezon
Copy link
Author

xezon commented Jul 2, 2025

One more thing we can do here is log out the version too.

  • Fixed. Log will now print:
================================================================================
Generals version 1.4.601 Debug
Build date: Jul  2 2025 19:27:54
Build location: 
Build user: 
Build git revision: ~543
Build git version: ~33142610
Build git commit time: 2025-06-30 20:22:40
Build git commit author: xezon
================================================================================
  • Build user now falls back to git commit author name if the build user is empty.

  • Also fixed getAsciiVersion to be consistent with getUnicodeVersion.

  • Added comments to public functions of Version class.

  • Removed all the useless (void) function arguments in Version class.

@xezon
Copy link
Author

xezon commented Jul 11, 2025

RTS_INTERNAL stuff merged in.

xezon added 4 commits July 14, 2025 23:07
…info, fix getAsciiVersion to be consistent with getUnicodeVersion, add comment, remove ( void ), fix Version function ordering
@xezon xezon force-pushed the xezon/add-git-version-info branch from 31a01c6 to 57ab974 Compare July 14, 2025 21:07
@xezon
Copy link
Author

xezon commented Jul 14, 2025

Replicated in Generals with conflicts

$ git diff e5110b67b2f6224a78d97e6cf7a65ca8c5b3e2c4..08a43f3ed9101a1088786b93cfa39249cf1718bb > changes.patch

$ git apply -p2 --directory=Generals --reject --whitespace=fix changes.patch                     changes.patch:23: trailing whitespace.
/**
changes.patch:571: trailing whitespace.
                                                                                                 25, 54,
changes.patch:572: trailing whitespace.
                                                                                                 180, 26,
changes.patch:931: trailing whitespace.

changes.patch:938: trailing whitespace.

Checking patch Generals/CMakeLists.txt...
error: while searching for:
target_link_libraries(corei_always INTERFACE
    core_utility
    corei_libraries_include
)

# Set where the build results will end up

error: patch failed: Generals/CMakeLists.txt:12
Checking patch Generals/Code/GameEngine/Include/Common/version.h...
Checking patch Generals/Code/GameEngine/Source/Common/GameEngine.cpp...
error: while searching for:
                if (TheVersion)
                {
                        DEBUG_LOG(("================================================================================"));
        #if defined RTS_DEBUG
                        const char *buildType = "Debug";
        #else
                        const char *buildType = "Release";
        #endif
                        DEBUG_LOG(("Generals version %s (%s)", TheVersion->getAsciiVersion().str(), buildType));
                        DEBUG_LOG(("Build date: %s", TheVersion->getAsciiBuildTime().str()));
                        DEBUG_LOG(("Build location: %s", TheVersion->getAsciiBuildLocation().str()));
                        DEBUG_LOG(("Built by: %s", TheVersion->getAsciiBuildUser().str()));
                        DEBUG_LOG(("================================================================================"));
                }
#endif

error: patch failed: Generals/Code/GameEngine/Source/Common/GameEngine.cpp:256
Checking patch Generals/Code/GameEngine/Source/Common/version.cpp...
Checking patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp...
Hunk #1 succeeded at 407 (offset -35 lines).
error: while searching for:
        exitID = TheNameKeyGenerator->nameToKey( AsciiString("MainMenu.wnd:ButtonExit") );
        motdID = TheNameKeyGenerator->nameToKey( AsciiString("MainMenu.wnd:ButtonMOTD") );
        worldBuilderID = TheNameKeyGenerator->nameToKey( AsciiString("MainMenu.wnd:ButtonWorldBuilder") );
//      NameKeyType versionID = TheNameKeyGenerator->nameToKey( AsciiString("MainMenu.wnd:LabelVersion") );
        getUpdateID = TheNameKeyGenerator->nameToKey( AsciiString("MainMenu.wnd:ButtonGetUpdate") );
//      buttonTRAININGID = TheNameKeyGenerator->nameToKey( AsciiString("MainMenu.wnd:ButtonTRAINING") );
        buttonChallengeID = TheNameKeyGenerator->nameToKey( AsciiString("MainMenu.wnd:ButtonChallenge") );

error: patch failed: Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp:471
error: while searching for:
        buttonHard = TheWindowManager->winGetWindowFromId( parentMainMenu, buttonHardID );
        buttonDiffBack = TheWindowManager->winGetWindowFromId( parentMainMenu, buttonDiffBackID );


//      GameWindow *labelVersion = TheWindowManager->winGetWindowFromId( parentMainMenu, versionID );

        getUpdate = TheWindowManager->winGetWindowFromId( parentMainMenu, getUpdateID );
//      buttonTRAINING = TheWindowManager->winGetWindowFromId( parentMainMenu, buttonTRAININGID );
        buttonChallenge = TheWindowManager->winGetWindowFromId( parentMainMenu, buttonChallengeID );

error: patch failed: Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp:521
Hunk #4 succeeded at 566 (offset -33 lines).
Checking patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp...
error: while searching for:

        WinAdvancedDisplay->winHide(TRUE);
}
//-------------------------------------------------------------------------------------------------
/** Initialize the options menu */
//-------------------------------------------------------------------------------------------------

error: patch failed: Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp:1399
Hunk #2 succeeded at 1464 (offset -95 lines).
Checking patch Generals/Code/GameEngine/Source/GameClient/GameText.cpp...
Checking patch Generals/Code/Main/CMakeLists.txt...
Hunk #1 succeeded at 29 (offset -2 lines).
Checking patch Generals/CMakeLists.txt...
error: while searching for:
# Add resources (optional)
if (MSVC_IDE)
    add_library(resources INTERFACE
        visualstudio/asciistring.natvis
        visualstudio/stllist.natvis
        visualstudio/stlvector.natvis

error: patch failed: Generals/CMakeLists.txt:1
Checking patch Generals/gitinfo/git_watcher.cmake...
Checking patch Generals/gitinfo/gitinfo.cpp.in...
Checking patch Generals/gitinfo/gitinfo.h...
Applying patch Generals/CMakeLists.txt with 1 reject...
Rejected hunk #1.
Applied patch Generals/Code/GameEngine/Include/Common/version.h cleanly.
Applying patch Generals/Code/GameEngine/Source/Common/GameEngine.cpp with 1 reject...
Rejected hunk #1.
Applied patch Generals/Code/GameEngine/Source/Common/version.cpp cleanly.
Applying patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp with 2 rejects...
Hunk #1 applied cleanly.
Rejected hunk #2.
Rejected hunk #3.
Hunk #4 applied cleanly.
Applying patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp with 1 reject...
Rejected hunk #1.
Hunk #2 applied cleanly.
Applied patch Generals/Code/GameEngine/Source/GameClient/GameText.cpp cleanly.
Applied patch Generals/Code/Main/CMakeLists.txt cleanly.
Applying patch Generals/CMakeLists.txt with 1 reject...
Rejected hunk #1.
Applied patch Generals/gitinfo/git_watcher.cmake cleanly.
Applied patch Generals/gitinfo/gitinfo.cpp.in cleanly.
Applied patch Generals/gitinfo/gitinfo.h cleanly.

@xezon
Copy link
Author

xezon commented Jul 14, 2025

Rebased to Main with Debug Logging LF changes.

@xezon
Copy link
Author

xezon commented Jul 15, 2025

One more thing that came to mind here: What about version properties in EXE properties page?

@xezon

This comment was marked as outdated.

@xezon
Copy link
Author

xezon commented Jul 15, 2025

Actually, maybe it is better move the EXE file info stuff to a separate change. Because it does not match what the title of this change promises. Edit: Removed EXE file info change.

@xezon xezon force-pushed the xezon/add-git-version-info branch from 12e86de to 57ab974 Compare July 15, 2025 21:53
@xezon xezon merged commit a86ed98 into TheSuperHackers:main Jul 15, 2025
30 checks passed
@xezon xezon deleted the xezon/add-git-version-info branch July 15, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Is new feature or request Gen Relates to Generals GUI For graphical user interface Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement build version/commit hash display to identify exact build version
2 participants