🔧 Fixed Windows version output and non-windows encoding option

This commit is contained in:
bitcookies
2026-06-29 19:07:03 +08:00
parent 385381eecc
commit 62c120f738
5 changed files with 14 additions and 47 deletions
+5 -1
View File
@@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Version
set(APP_VERSION "4.1.0.0")
set(APP_VERSION "4.2.0")
add_executable(winrar-keygen
_tmain.cpp
@@ -19,6 +19,10 @@ add_executable(winrar-keygen
WinRarKeygen.hpp
)
if(WIN32)
target_sources(winrar-keygen PRIVATE winrar-keygen.rc)
endif()
target_compile_definitions(winrar-keygen PRIVATE
APP_VERSION="${APP_VERSION}"
)
+4 -41
View File
@@ -21,12 +21,11 @@
#include <stdexcept>
#ifdef _WIN32
#pragma comment(lib, "Version.lib")
#pragma comment(lib, "winhttp.lib")
#endif
#ifndef APP_VERSION
#define APP_VERSION "4.1.0.0"
#define APP_VERSION "4.2.0"
#endif
#ifdef _WIN32
@@ -237,7 +236,7 @@ void ShowHelp(const std::string& version) {
std::cout << " winrar-keygen -v | --version\n";
std::cout << " winrar-keygen -h | --help\n\n";
std::cout << "Options:\n";
std::cout << " -e, --encoding <enc> utf8 (default), ascii\n";
std::cout << " -e, --encoding <enc> utf8 (default), ascii, ansi\n";
std::cout << " -o, --output <file> Output file (default: rarreg.key)\n";
#ifdef __APPLE__
std::cout << " -a, --activate Write to ~/Library/Application Support/com.rarlab.WinRAR/rarreg.key\n";
@@ -256,44 +255,9 @@ void ShowHelp(const std::string& version) {
}
#endif
#ifdef _WIN32
std::wstring GetExecutableVersion() {
wchar_t exePath[MAX_PATH] = {};
DWORD pathLen = GetModuleFileNameW(nullptr, exePath, MAX_PATH);
if (pathLen == 0) {
return L"unknown";
}
DWORD handle = 0;
DWORD versionSize = GetFileVersionInfoSizeW(exePath, &handle);
if (versionSize == 0) {
return L"unknown";
}
std::vector<BYTE> versionData(versionSize);
if (!GetFileVersionInfoW(exePath, 0, versionSize, versionData.data())) {
return L"unknown";
}
VS_FIXEDFILEINFO* fixedInfo = nullptr;
UINT len = 0;
if (!VerQueryValueW(versionData.data(), L"\\",
reinterpret_cast<LPVOID*>(&fixedInfo),
&len) ||
fixedInfo == nullptr) {
return L"unknown";
}
return std::to_wstring(HIWORD(fixedInfo->dwFileVersionMS)) + L"." +
std::to_wstring(LOWORD(fixedInfo->dwFileVersionMS)) + L"." +
std::to_wstring(HIWORD(fixedInfo->dwFileVersionLS)) + L"." +
std::to_wstring(LOWORD(fixedInfo->dwFileVersionLS));
}
#else
std::string GetAppVersion() {
return APP_VERSION;
}
#endif
#ifdef _WIN32
void PrintRegisterInfo(const WinRarKeygen<WinRarConfig>::RegisterInfo& Info,
@@ -577,7 +541,7 @@ int wmain(int argc, wchar_t* argv[]) {
return -1;
}
std::wstring version = GetExecutableVersion();
std::wstring version = Utf8ToWide(GetAppVersion());
std::string versionUtf8 = WideToUtf8(version);
if (opts.showVersion) {
@@ -801,8 +765,7 @@ int main(int argc, char* argv[]) {
return -1;
}
const char* encName = (opts.encoding == Encoding::UTF8) ? "UTF-8" :
(opts.encoding == Encoding::ANSI) ? "ANSI" : "ASCII";
const char* encName = (opts.encoding == Encoding::ASCII) ? "ASCII" : "UTF-8";
std::cout << "\n";
PrintRegisterInfo(Info, displayUser, displayLicense);
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "winrar-keygen",
"version": "4.1.0.0",
"version": "4.2.0",
"dependencies": [
"gmp"
]
+4 -4
View File
@@ -51,8 +51,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,1,0,0
PRODUCTVERSION 4,1,0,0
FILEVERSION 4,2,0,0
PRODUCTVERSION 4,2,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "WinRAR Keygen"
VALUE "FileDescription", "WinRAR Key Generation Tool"
VALUE "FileVersion", "4.1.0.0"
VALUE "FileVersion", "4.2.0"
VALUE "InternalName", "winrar-keygen.exe"
VALUE "LegalCopyright", "Copyright (C) 2021 Bitcookies"
VALUE "OriginalFilename", "winrar-keygen.exe"
VALUE "ProductName", "WinRAR Keygen"
VALUE "ProductVersion", "4.1.0.0"
VALUE "ProductVersion", "4.2.0"
END
END
BLOCK "VarFileInfo"