From a4fe984390cfd6b40178a6809ab1955e0fe69e71 Mon Sep 17 00:00:00 2001 From: kichik Date: Tue, 24 Apr 2007 14:11:35 +0000 Subject: [PATCH] use GetDLLVersion git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5117 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Library/LibraryLocal/LibraryLocal.cpp | 65 +------------ Contrib/Library/LibraryLocal/SConscript | 1 + Source/script.cpp | 96 +------------------ 3 files changed, 6 insertions(+), 156 deletions(-) diff --git a/Contrib/Library/LibraryLocal/LibraryLocal.cpp b/Contrib/Library/LibraryLocal/LibraryLocal.cpp index d0b6d8e7..4f94fab8 100644 --- a/Contrib/Library/LibraryLocal/LibraryLocal.cpp +++ b/Contrib/Library/LibraryLocal/LibraryLocal.cpp @@ -12,8 +12,7 @@ #include #include -#include "../../../Source/ResourceEditor.h" -#include "../../../Source/ResourceVersionInfo.h" +#include "../../../Source/util.h" #include "../../../Source/winchar.h" using namespace std; @@ -22,68 +21,6 @@ int g_noconfig=0; int g_display_errors=1; 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) { #ifdef _WIN32 diff --git a/Contrib/Library/LibraryLocal/SConscript b/Contrib/Library/LibraryLocal/SConscript index 49bf45c3..e3f676c5 100644 --- a/Contrib/Library/LibraryLocal/SConscript +++ b/Contrib/Library/LibraryLocal/SConscript @@ -12,6 +12,7 @@ required_files = Split(""" libs = Split(""" oleaut32 + version """) Import('BuildUtil BuildUtilEnv') diff --git a/Source/script.cpp b/Source/script.cpp index a5f73d77..b0b53478 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -4664,110 +4664,22 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return add_entry(&ent); case TOK_GETDLLVERSIONLOCAL: { - char buf[128]; - DWORD low=0, high=0; - 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) + DWORD low, high; + if (!GetDLLVersion(line.gettoken_str(1),high,low)) { ERROR_MSG("GetDLLVersionLocal: error reading version info from \"%s\"\n",line.gettoken_str(1)); return PS_ERROR; } ent.which=EW_ASSIGNVAR; ent.offsets[0]=GetUserVarIndex(line, 2); - wsprintf(buf,"%u",high); - ent.offsets[1]=add_string(buf); + ent.offsets[1]=add_intstring(high); ent.offsets[2]=0; ent.offsets[3]=0; if (ent.offsets[0]<0) PRINTHELP() add_entry(&ent); ent.offsets[0]=GetUserVarIndex(line, 3); - wsprintf(buf,"%u",low); - ent.offsets[1]=add_string(buf); + ent.offsets[1]=add_intstring(low); ent.offsets[2]=0; ent.offsets[3]=0; if (ent.offsets[0]<0) PRINTHELP()