deep-wine-runner/demo/GetExeVersion/main.cpp

70 lines
1.9 KiB
C++
Raw Normal View History

2022-11-27 16:17:57 +08:00
/**********************************
* <EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>gfdgd xi<EFBFBD><EFBFBD>Ϊʲô<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD>û<EFBFBD>Ͱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>2.5.0
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>2022<EFBFBD><EFBFBD>11<EFBFBD><EFBFBD>27<EFBFBD><EFBFBD>
* ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Wine/Windows <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
**********************************/
#include <iostream>
#include <string>
#include <fstream>
#include <Windows.h>
#pragma comment(lib, "version.lib");
using namespace std;
// <20>ȿӡ<C8BF><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA> Dev CPP <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD> -lversion
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><E6B1BE>
//@params:filename:<3A>ļ<EFBFBD><C4BC><EFBFBD>
string GetFileVersion(LPCWSTR filename)
{
string asVer = "";
VS_FIXEDFILEINFO *pVsInfo;
unsigned int iFileInfoSize = sizeof(VS_FIXEDFILEINFO);
int iVerInfoSize = GetFileVersionInfoSizeW(filename, NULL);
if(iVerInfoSize != 0)
{
char *pBuf = NULL;
while(!pBuf)
{
pBuf = new char[iVerInfoSize];
}
if(GetFileVersionInfoW(filename, 0, iVerInfoSize, pBuf))
{
if(VerQueryValueA(pBuf, "\\", (void **)&pVsInfo, &iFileInfoSize))
{
sprintf(pBuf, "%d.%d.%d.%d", HIWORD(pVsInfo->dwFileVersionMS), LOWORD(pVsInfo->dwFileVersionMS), HIWORD(pVsInfo->dwFileVersionLS), LOWORD(pVsInfo->dwFileVersionLS));
asVer = pBuf;
}
}
delete pBuf;
}
return asVer;
}
// <20><>ʽת<CABD><D7AA>
LPWSTR ConvertCharToLPWSTR(const char* szString)
{
int dwLen = strlen(szString) + 1;
int nwLen = MultiByteToWideChar(CP_ACP, 0, szString, dwLen, NULL, 0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵij<CAB5><C4B3><EFBFBD>
LPWSTR lpszPath = new WCHAR[dwLen];
MultiByteToWideChar(CP_ACP, 0, szString, dwLen, lpszPath, nwLen);
return lpszPath;
}
int main(int argc, char* argv[]){
if (argc < 2){
cout << "Unfull Option" << endl;
return 1;
}
string version = GetFileVersion(ConvertCharToLPWSTR(argv[1]));
cout << "Version: " << version << endl;
if (argc == 3){
cout << "Write To " << argv[2] << endl;
// Ϊ<>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>д<EFBFBD><D0B4><EFBFBD>ı<EFBFBD><C4B1>ĵ<EFBFBD>
ofstream write(argv[2], ios::trunc);
write << version;
write.close();
}
return 0;
}