use GetDLLVersion
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5117 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
b8888a69bd
commit
a4fe984390
3 changed files with 6 additions and 156 deletions
|
@ -12,8 +12,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "../../../Source/ResourceEditor.h"
|
#include "../../../Source/util.h"
|
||||||
#include "../../../Source/ResourceVersionInfo.h"
|
|
||||||
#include "../../../Source/winchar.h"
|
#include "../../../Source/winchar.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -22,68 +21,6 @@ int g_noconfig=0;
|
||||||
int g_display_errors=1;
|
int g_display_errors=1;
|
||||||
FILE *g_output=stdout;
|
FILE *g_output=stdout;
|
||||||
|
|
||||||
int GetDLLVersion(string& filepath, DWORD& high, DWORD & low)
|
|
||||||
{
|
|
||||||
int found = 0;
|
|
||||||
|
|
||||||
FILE *fdll = fopen(filepath.c_str(), "rb");
|
|
||||||
if (!fdll)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fseek(fdll, 0, SEEK_END);
|
|
||||||
unsigned int len = ftell(fdll);
|
|
||||||
fseek(fdll, 0, SEEK_SET);
|
|
||||||
|
|
||||||
LPBYTE dll = (LPBYTE) malloc(len);
|
|
||||||
|
|
||||||
if (!dll)
|
|
||||||
{
|
|
||||||
fclose(fdll);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fread(dll, 1, len, fdll) != len)
|
|
||||||
{
|
|
||||||
fclose(fdll);
|
|
||||||
free(dll);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CResourceEditor *dllre = new CResourceEditor(dll, len);
|
|
||||||
LPBYTE ver = dllre->GetResourceA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
|
|
||||||
int versize = dllre->GetResourceSizeA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
|
|
||||||
|
|
||||||
if (ver)
|
|
||||||
{
|
|
||||||
if ((size_t) versize > sizeof(WORD) * 3)
|
|
||||||
{
|
|
||||||
// get VS_FIXEDFILEINFO from VS_VERSIONINFO
|
|
||||||
WCHAR *szKey = (WCHAR *)(ver + sizeof(WORD) * 3);
|
|
||||||
int len = (winchar_strlen(szKey) + 1) * sizeof(WCHAR) + sizeof(WORD) * 3;
|
|
||||||
len = (len + 3) & ~3; // align on DWORD boundry
|
|
||||||
VS_FIXEDFILEINFO *verinfo = (VS_FIXEDFILEINFO *)(ver + len);
|
|
||||||
if (versize > len && verinfo->dwSignature == VS_FFI_SIGNATURE)
|
|
||||||
{
|
|
||||||
low = verinfo->dwFileVersionLS;
|
|
||||||
high = verinfo->dwFileVersionMS;
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dllre->FreeResource(ver);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete dllre;
|
|
||||||
}
|
|
||||||
catch (exception&)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetTLBVersion(string& filepath, DWORD& high, DWORD & low)
|
int GetTLBVersion(string& filepath, DWORD& high, DWORD & low)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
@ -12,6 +12,7 @@ required_files = Split("""
|
||||||
|
|
||||||
libs = Split("""
|
libs = Split("""
|
||||||
oleaut32
|
oleaut32
|
||||||
|
version
|
||||||
""")
|
""")
|
||||||
|
|
||||||
Import('BuildUtil BuildUtilEnv')
|
Import('BuildUtil BuildUtilEnv')
|
||||||
|
|
|
@ -4664,110 +4664,22 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
||||||
return add_entry(&ent);
|
return add_entry(&ent);
|
||||||
case TOK_GETDLLVERSIONLOCAL:
|
case TOK_GETDLLVERSIONLOCAL:
|
||||||
{
|
{
|
||||||
char buf[128];
|
DWORD low, high;
|
||||||
DWORD low=0, high=0;
|
if (!GetDLLVersion(line.gettoken_str(1),high,low))
|
||||||
int flag=0;
|
|
||||||
#ifdef _WIN32
|
|
||||||
DWORD s,d;
|
|
||||||
int alloced=0;
|
|
||||||
char *upath=line.gettoken_str(1);
|
|
||||||
char path[1024];
|
|
||||||
char *name;
|
|
||||||
path[0] = 0;
|
|
||||||
GetFullPathName(upath, 1024, path, &name);
|
|
||||||
s=GetFileVersionInfoSize(path,&d);
|
|
||||||
if (s)
|
|
||||||
{
|
|
||||||
void *buf;
|
|
||||||
buf=(void *)GlobalAlloc(GPTR,s);
|
|
||||||
if (buf)
|
|
||||||
{
|
|
||||||
UINT uLen;
|
|
||||||
VS_FIXEDFILEINFO *pvsf;
|
|
||||||
if (GetFileVersionInfo(path,0,s,buf) && VerQueryValue(buf,"\\",(void**)&pvsf,&uLen))
|
|
||||||
{
|
|
||||||
low=pvsf->dwFileVersionLS;
|
|
||||||
high=pvsf->dwFileVersionMS;
|
|
||||||
flag=1;
|
|
||||||
}
|
|
||||||
GlobalFree(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
FILE *fdll = FOPEN(line.gettoken_str(1), "rb");
|
|
||||||
if (!fdll) {
|
|
||||||
ERROR_MSG("Error: Can't open \"%s\"!\n", line.gettoken_str(1));
|
|
||||||
return PS_ERROR;
|
|
||||||
}
|
|
||||||
MANAGE_WITH(fdll, fclose);
|
|
||||||
|
|
||||||
fseek(fdll, 0, SEEK_END);
|
|
||||||
unsigned int len = ftell(fdll);
|
|
||||||
fseek(fdll, 0, SEEK_SET);
|
|
||||||
LPBYTE dll = (LPBYTE) malloc(len);
|
|
||||||
if (!dll) {
|
|
||||||
ERROR_MSG("Internal compiler error #12345: malloc(%d) failed\n", dll);
|
|
||||||
extern void quit(); quit();
|
|
||||||
}
|
|
||||||
MANAGE_WITH(dll, free);
|
|
||||||
if (fread(dll, 1, len, fdll) != len) {
|
|
||||||
ERROR_MSG("Error: Can't read \"%s\"!\n", line.gettoken_str(1));
|
|
||||||
return PS_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CResourceEditor *dllre = new CResourceEditor(dll, len);
|
|
||||||
LPBYTE ver = dllre->GetResourceA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
|
|
||||||
int versize = dllre->GetResourceSizeA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
|
|
||||||
|
|
||||||
if (ver)
|
|
||||||
{
|
|
||||||
if ((size_t) versize > sizeof(WORD) * 3)
|
|
||||||
{
|
|
||||||
// get VS_FIXEDFILEINFO from VS_VERSIONINFO
|
|
||||||
WCHAR *szKey = (WCHAR *)(ver + sizeof(WORD) * 3);
|
|
||||||
int len = (winchar_strlen(szKey) + 1) * sizeof(WCHAR) + sizeof(WORD) * 3;
|
|
||||||
len = (len + 3) & ~3; // align on DWORD boundry
|
|
||||||
VS_FIXEDFILEINFO *verinfo = (VS_FIXEDFILEINFO *)(ver + len);
|
|
||||||
if (versize > len && verinfo->dwSignature == VS_FFI_SIGNATURE)
|
|
||||||
{
|
|
||||||
low = verinfo->dwFileVersionLS;
|
|
||||||
high = verinfo->dwFileVersionMS;
|
|
||||||
flag = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dllre->FreeResource(ver);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete dllre;
|
|
||||||
}
|
|
||||||
catch (exception& err) {
|
|
||||||
ERROR_MSG(
|
|
||||||
"GetDLLVersionLocal: error reading version info from \"%s\": %s\n",
|
|
||||||
line.gettoken_str(1),
|
|
||||||
err.what()
|
|
||||||
);
|
|
||||||
return PS_ERROR;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (!flag)
|
|
||||||
{
|
{
|
||||||
ERROR_MSG("GetDLLVersionLocal: error reading version info from \"%s\"\n",line.gettoken_str(1));
|
ERROR_MSG("GetDLLVersionLocal: error reading version info from \"%s\"\n",line.gettoken_str(1));
|
||||||
return PS_ERROR;
|
return PS_ERROR;
|
||||||
}
|
}
|
||||||
ent.which=EW_ASSIGNVAR;
|
ent.which=EW_ASSIGNVAR;
|
||||||
ent.offsets[0]=GetUserVarIndex(line, 2);
|
ent.offsets[0]=GetUserVarIndex(line, 2);
|
||||||
wsprintf(buf,"%u",high);
|
ent.offsets[1]=add_intstring(high);
|
||||||
ent.offsets[1]=add_string(buf);
|
|
||||||
ent.offsets[2]=0;
|
ent.offsets[2]=0;
|
||||||
ent.offsets[3]=0;
|
ent.offsets[3]=0;
|
||||||
if (ent.offsets[0]<0) PRINTHELP()
|
if (ent.offsets[0]<0) PRINTHELP()
|
||||||
add_entry(&ent);
|
add_entry(&ent);
|
||||||
|
|
||||||
ent.offsets[0]=GetUserVarIndex(line, 3);
|
ent.offsets[0]=GetUserVarIndex(line, 3);
|
||||||
wsprintf(buf,"%u",low);
|
ent.offsets[1]=add_intstring(low);
|
||||||
ent.offsets[1]=add_string(buf);
|
|
||||||
ent.offsets[2]=0;
|
ent.offsets[2]=0;
|
||||||
ent.offsets[3]=0;
|
ent.offsets[3]=0;
|
||||||
if (ent.offsets[0]<0) PRINTHELP()
|
if (ent.offsets[0]<0) PRINTHELP()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue