1 Star 0 Fork 0

陈祎麒/mlcc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
versioninfo.h 2.72 KB
一键复制 编辑 原始数据 按行查看 历史
sb500 提交于 2023-10-07 12:35 . no message
#pragma once
#include <string>
#include <Windows.h>
#include "fmt1.h"
#pragma comment(lib, "version.lib")
enum InfoType
{
InfoType_Version,
InfoType_FileDescription,
};
inline std::string get_version(const std::string& filename, InfoType it)
{
DWORD verHandle = 0;
UINT size = 0;
LPBYTE lpBuffer = NULL;
DWORD verSize = GetFileVersionInfoSizeA(filename.c_str(), &verHandle);
if (verSize != NULL)
{
std::string verData;
verData.resize(verSize);
if (GetFileVersionInfoA(filename.c_str(), verHandle, verSize, (LPVOID)verData.data()))
{
if (it == InfoType_Version && VerQueryValueA(verData.data(), "\\", (VOID FAR * FAR*)&lpBuffer, &size))
{
if (size)
{
VS_FIXEDFILEINFO* verInfo = (VS_FIXEDFILEINFO*)lpBuffer;
if (verInfo->dwSignature == 0xfeef04bd)
{
// Doesn't matter if you are on 32 bit or 64 bit,
// DWORD is always 32 bits, so first two revision numbers
// come from dwFileVersionMS, last two come from dwFileVersionLS
return fmt1::format("{}.{}.{}.{}",
(verInfo->dwFileVersionMS >> 16) & 0xffff,
(verInfo->dwFileVersionMS >> 0) & 0xffff,
(verInfo->dwFileVersionLS >> 16) & 0xffff,
(verInfo->dwFileVersionLS >> 0) & 0xffff);
}
}
}
if (it == InfoType_FileDescription && VerQueryValue(verData.data(), TEXT("\\VarFileInfo\\Translation"), (VOID FAR * FAR*)&lpBuffer, &size))
{
if (size)
{
// Read the list of languages and code pages.
struct LANGANDCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
}* lpTranslate;
lpTranslate = (struct LANGANDCODEPAGE*)lpBuffer;
// Read the file description for each language and code page.
for (UINT i = 0; i < (size / sizeof(struct LANGANDCODEPAGE)); i++)
{
char SubBlock[50];
snprintf(SubBlock, 50, "\\StringFileInfo\\%04x%04x\\FileDescription", lpTranslate[i].wLanguage, lpTranslate[i].wCodePage);
if (VerQueryValueA(verData.data(), SubBlock, (VOID FAR * FAR*)&lpBuffer, &size))
{
return (const char*)lpBuffer;
}
}
}
}
}
}
return "";
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chen-yiqi-duke/mlcc.git
git@gitee.com:chen-yiqi-duke/mlcc.git
chen-yiqi-duke
mlcc
mlcc
master

搜索帮助