Added !gettlbversion and TLB reading support on POSIX
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6913 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
f34fd48105
commit
a51d89712c
19 changed files with 256 additions and 247 deletions
|
@ -3,7 +3,9 @@
|
|||
LibraryLocal - used by the Library.nsh macros
|
||||
Get the version of local DLL and TLB files
|
||||
Written by Joost Verburg
|
||||
Unicode support by Jim Park -- 07/27/2007
|
||||
POSIX DLL version support by kichik -- 20070415
|
||||
Unicode support by Jim Park -- 20070727
|
||||
POSIX TLB version support by anders_k -- 20170929
|
||||
|
||||
*/
|
||||
|
||||
|
@ -14,6 +16,7 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "../../../Source/BinInterop.h"
|
||||
#include "../../../Source/util.h"
|
||||
#include "../../../Source/winchar.h"
|
||||
|
||||
|
@ -22,139 +25,79 @@ using namespace std;
|
|||
int g_noconfig=0; // TODO: Not used?
|
||||
NSISRT_DEFINEGLOBALS();
|
||||
|
||||
int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
int found = 0;
|
||||
|
||||
TCHAR fullpath[1024];
|
||||
TCHAR *p;
|
||||
if (!GetFullPathName(filepath.c_str(), COUNTOF(fullpath), fullpath, &p))
|
||||
return 0;
|
||||
|
||||
ITypeLib* typeLib;
|
||||
HRESULT hr;
|
||||
|
||||
#ifdef _UNICODE
|
||||
hr = LoadTypeLib(fullpath, &typeLib);
|
||||
#else
|
||||
// If built without UNICODE, we still need to convert this string to a Unicode string.
|
||||
WCHAR *ole_filename = (WCHAR*) WinWStrDupFromTChar(fullpath);
|
||||
if (!ole_filename) return 0;
|
||||
hr = LoadTypeLib(ole_filename, &typeLib);
|
||||
free(ole_filename);
|
||||
#endif //~ _UNICODE
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
|
||||
TLIBATTR* typelibAttr;
|
||||
|
||||
hr = typeLib->GetLibAttr(&typelibAttr);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
|
||||
high = typelibAttr->wMajorVerNum;
|
||||
low = typelibAttr->wMinorVerNum;
|
||||
|
||||
found = 1;
|
||||
|
||||
}
|
||||
|
||||
typeLib->Release();
|
||||
|
||||
}
|
||||
|
||||
return found;
|
||||
|
||||
#else
|
||||
|
||||
return 0;
|
||||
|
||||
#endif //~ _WIN32
|
||||
}
|
||||
enum {
|
||||
EC_SUCCESS = 0,
|
||||
EC_NO_VERSION_PRESENT = 1,
|
||||
EC_UNSUPPORTED_FORMAT = 10, // TODO: POSIX should return this for 16-bit NE files
|
||||
EC_FILE_NOT_FOUND = 15,
|
||||
EC_INVALID_PARAMETER = 20,
|
||||
EC_FILE_IO_ERROR = 50,
|
||||
EC_UNKNOWN_ERROR = 99
|
||||
};
|
||||
|
||||
NSIS_ENTRYPOINT_TMAIN
|
||||
int _tmain(int argc, TCHAR* argv[])
|
||||
{
|
||||
if (!NSISRT_Initialize()) return 1;
|
||||
if (!NSISRT_Initialize()) return EC_UNKNOWN_ERROR;
|
||||
|
||||
// Parse the command line
|
||||
|
||||
tstring cmdline;
|
||||
|
||||
tstring mode;
|
||||
tstring filename;
|
||||
tstring filepath;
|
||||
|
||||
int filefound = 0;
|
||||
tstring appmode;
|
||||
const TCHAR *filename;
|
||||
int filefound = 0, exitcode = EC_INVALID_PARAMETER;
|
||||
|
||||
if (argc != 4)
|
||||
return 1;
|
||||
return EC_INVALID_PARAMETER;
|
||||
|
||||
// Get the full path of the local file
|
||||
|
||||
mode = argv[1];
|
||||
appmode = argv[1];
|
||||
filename = argv[2];
|
||||
|
||||
// Validate filename
|
||||
|
||||
FILE*fIn = FOPEN(filename.c_str(), ("rb"));
|
||||
FILE*fIn = FOPEN(filename, ("rb"));
|
||||
filefound = !!fIn;
|
||||
if (fIn)
|
||||
fclose(fIn);
|
||||
|
||||
// Work
|
||||
|
||||
int versionfound = 0;
|
||||
DWORD low = 0, high = 0;
|
||||
|
||||
if (filefound)
|
||||
{
|
||||
|
||||
// Get version
|
||||
|
||||
// DLL / EXE
|
||||
|
||||
if (mode.compare(_T("D")) == 0)
|
||||
// DLL/EXE version
|
||||
if (appmode.compare(_T("D")) == 0)
|
||||
{
|
||||
|
||||
versionfound = GetDLLVersion(filename, high, low);
|
||||
|
||||
}
|
||||
|
||||
// TLB
|
||||
|
||||
if (mode.compare(_T("T")) == 0)
|
||||
// TLB version
|
||||
if (appmode.compare(_T("T")) == 0)
|
||||
{
|
||||
|
||||
versionfound = GetTLBVersion(filename, high, low);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Write the version to an NSIS header file
|
||||
|
||||
// Write the version to a NSIS header file
|
||||
FILE*fHdr = FOPEN(argv[3], ("wt"));
|
||||
if (!fHdr) return 1;
|
||||
if (!fHdr) return EC_FILE_IO_ERROR;
|
||||
|
||||
fputs("!warning \"LibraryLocal is deprecated, use !getdllversion /packed\"\n", fHdr);
|
||||
|
||||
// File content is always ASCII so we don't use TCHAR
|
||||
if (!filefound)
|
||||
{
|
||||
fputs("!define LIBRARY_VERSION_FILENOTFOUND\n", fHdr);
|
||||
exitcode = EC_FILE_NOT_FOUND;
|
||||
}
|
||||
else if (!versionfound)
|
||||
{
|
||||
fputs("!define LIBRARY_VERSION_NONE\n", fHdr);
|
||||
exitcode = EC_NO_VERSION_PRESENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(fHdr, "!define LIBRARY_VERSION_HIGH %lu\n", static_cast<unsigned long>(high));
|
||||
fprintf(fHdr, "!define LIBRARY_VERSION_LOW %lu\n", static_cast<unsigned long>(low));
|
||||
exitcode = EC_SUCCESS;
|
||||
}
|
||||
|
||||
fclose(fHdr);
|
||||
return 0;
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ files = Split("""
|
|||
|
||||
required_files = Split("""
|
||||
#Source/ResourceEditor.cpp
|
||||
#Source/BinInterop.cpp
|
||||
#Source/util.cpp
|
||||
#Source/winchar.cpp
|
||||
""")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue