mirror of
https://gitlab.com/hashborgir/plugy.git
synced 2024-12-02 13:36:02 +00:00
118 lines
3.5 KiB
C++
118 lines
3.5 KiB
C++
|
#include "VersionInfo.h"
|
|||
|
#pragma comment(lib, "Version.Lib") //<2F><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> Delphi 7 - <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>! :(
|
|||
|
|
|||
|
|
|||
|
bool IsFile(char* sPath)
|
|||
|
{
|
|||
|
bool bFile = false;
|
|||
|
HANDLE hFile = CreateFile
|
|||
|
(
|
|||
|
sPath,
|
|||
|
GENERIC_READ,
|
|||
|
FILE_SHARE_READ,
|
|||
|
NULL,
|
|||
|
OPEN_EXISTING,
|
|||
|
FILE_ATTRIBUTE_NORMAL,
|
|||
|
NULL
|
|||
|
);
|
|||
|
if(hFile != INVALID_HANDLE_VALUE)
|
|||
|
{
|
|||
|
CloseHandle(hFile);
|
|||
|
bFile = true;
|
|||
|
}
|
|||
|
return bFile;
|
|||
|
}
|
|||
|
|
|||
|
bool GetAppVersion(char* FileName, TFileVersion* VerInfo){ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
VerInfo->full = -1;
|
|||
|
if(!IsFile(FileName)){ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
return false; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20>-<2D><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
DWORD FSize = GetFileVersionInfoSize(FileName,NULL); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if(FSize==0){ // <20><><EFBFBD><EFBFBD> 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
return false;
|
|||
|
}
|
|||
|
LPVOID pBlock = (char*)malloc(FSize); // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GetFileVersionInfo(FileName,NULL,FSize,pBlock); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
LPVOID MS;
|
|||
|
UINT LS;
|
|||
|
try{
|
|||
|
VerQueryValue(pBlock,"\\",&MS,&LS); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
catch(...){
|
|||
|
return false; // <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
VS_FIXEDFILEINFO FixedFileInfo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
memmove(&FixedFileInfo, MS, LS); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
DWORD FileVersionMS = FixedFileInfo.dwFileVersionMS;
|
|||
|
DWORD FileVersionLS = FixedFileInfo.dwFileVersionLS;
|
|||
|
|
|||
|
VerInfo->major = HIWORD(FileVersionMS) ; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
VerInfo->minor = LOWORD(FileVersionMS); // <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
VerInfo->revision = HIWORD(FileVersionLS);
|
|||
|
VerInfo->subrevision = LOWORD(FileVersionLS);
|
|||
|
|
|||
|
return true; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#define SUBKEY "Software\\Blizzard Entertainment\\Diablo II"
|
|||
|
#define GAMEFILE "\\Game.exe"
|
|||
|
bool GetD2Path(char* buf, DWORD bufsize)
|
|||
|
{
|
|||
|
HKEY hKey;
|
|||
|
DWORD type;
|
|||
|
int res;
|
|||
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, SUBKEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
|
|||
|
res = RegQueryValueEx(hKey,"InstallPath",NULL,&type,(LPBYTE)buf,&bufsize);
|
|||
|
RegCloseKey(hKey);
|
|||
|
if (res!=ERROR_SUCCESS) return false;
|
|||
|
} else if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, SUBKEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
|
|||
|
res = RegQueryValueEx(hKey,"InstallPath",NULL,&type,(LPBYTE)buf,&bufsize);
|
|||
|
RegCloseKey(hKey);
|
|||
|
if (res!=ERROR_SUCCESS) return false;
|
|||
|
} else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
strcat(buf, GAMEFILE);
|
|||
|
if (GetFileAttributes(buf) == INVALID_FILE_ATTRIBUTES)
|
|||
|
return false;
|
|||
|
return true;
|
|||
|
};
|
|||
|
|
|||
|
int GetVerD2(TFileVersion GameVer)
|
|||
|
{
|
|||
|
if ((GameVer.major != 1)||(GameVer.minor != 0)) return -1;
|
|||
|
switch (GameVer.revision)
|
|||
|
{
|
|||
|
case 9:
|
|||
|
if (GameVer.subrevision == 20) return v109b;
|
|||
|
if (GameVer.subrevision == 22) return v109d;
|
|||
|
break;
|
|||
|
case 10:
|
|||
|
if (GameVer.subrevision == 39) return v110;
|
|||
|
break;
|
|||
|
case 11:
|
|||
|
if (GameVer.subrevision == 45) return v111;
|
|||
|
if (GameVer.subrevision == 46) return v111b;
|
|||
|
break;
|
|||
|
case 12:
|
|||
|
if (GameVer.subrevision == 49) return v112;
|
|||
|
break;
|
|||
|
case 13:
|
|||
|
if (GameVer.subrevision == 60) return v113c;
|
|||
|
if (GameVer.subrevision == 64) return v113d;
|
|||
|
break;
|
|||
|
}
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
int GetD2Version(char* PathGameExe)
|
|||
|
{
|
|||
|
TFileVersion GameVer = {-1};
|
|||
|
if (! GetAppVersion(PathGameExe, &GameVer)) return -1;
|
|||
|
int ver = GetVerD2(GameVer);
|
|||
|
return ver;
|
|||
|
}
|