mirror of
https://gitlab.com/hashborgir/plugy.git
synced 2024-11-30 12:36:02 +00:00
118 lines
3.5 KiB
C++
118 lines
3.5 KiB
C++
#include "VersionInfo.h"
|
|
#pragma comment(lib, "Version.Lib") //ïî ñğàâíåíèş ñ Delphi 7 - òàêîé ãåììîğîé! :(
|
|
|
|
|
|
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){ // ïîëó÷åíèå âåğñèè ôàéëà
|
|
VerInfo->full = -1;
|
|
if(!IsFile(FileName)){ // Ïğîâåğÿåì íàëè÷èå ôàéëà
|
|
return false; // Åñëè íåò ô-öèÿ íåóñïåøíà
|
|
}
|
|
DWORD FSize = GetFileVersionInfoSize(FileName,NULL); // ğàçìåğ èíôû î âåğñèè ôàéëà
|
|
if(FSize==0){ // Åñëè 0 ôóíêöèÿ íåóñïåøíà
|
|
return false;
|
|
}
|
|
LPVOID pBlock = (char*)malloc(FSize); // àäğåñ áóôåğà äëÿ ğåñóğñîâ âåğñèè
|
|
GetFileVersionInfo(FileName,NULL,FSize,pBlock); // ïîëó÷àåì ğåñóğñ èíôîğìàöèè î âåğñèè
|
|
LPVOID MS;
|
|
UINT LS;
|
|
try{
|
|
VerQueryValue(pBlock,"\\",&MS,&LS); // èçâëåêàåì èíôîğìàöèş èç ğåñóğñà
|
|
}
|
|
catch(...){
|
|
return false; // â ñëó÷àå îøèáêè ôóíêöèÿ íåóñïåøíà
|
|
}
|
|
VS_FIXEDFILEINFO FixedFileInfo; // ñòğóêòóğà ñ èíôîğìàöèåé î âåğñèè ôàéëà
|
|
memmove(&FixedFileInfo, MS, LS); // ïğèâîäèì èíôîğìàöèş ê ñòğóêòóğå
|
|
|
|
DWORD FileVersionMS = FixedFileInfo.dwFileVersionMS;
|
|
DWORD FileVersionLS = FixedFileInfo.dwFileVersionLS;
|
|
|
|
VerInfo->major = HIWORD(FileVersionMS) ; // ïîëó÷àåì çíà÷åíèÿ
|
|
VerInfo->minor = LOWORD(FileVersionMS); // è ïğèñâàèâàåè èõ âõîäíîìó óêàçàòåëş
|
|
VerInfo->revision = HIWORD(FileVersionLS);
|
|
VerInfo->subrevision = LOWORD(FileVersionLS);
|
|
|
|
return true; // ôóíêöèÿ óñïåøíà
|
|
}
|
|
|
|
|
|
#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;
|
|
} |