2004-08-06 22:04:13 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
LibraryLocal - used by the Library.nsh macros
|
|
|
|
Get the version of local DLL and TLB files
|
|
|
|
Written by Joost Verburg
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-04-16 20:15:00 +00:00
|
|
|
#include "../../../Source/Platform.h"
|
|
|
|
|
2004-08-06 22:04:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
2007-04-24 14:11:35 +00:00
|
|
|
#include "../../../Source/util.h"
|
2007-04-15 21:27:41 +00:00
|
|
|
#include "../../../Source/winchar.h"
|
|
|
|
|
2004-08-06 22:04:13 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2007-04-17 18:30:30 +00:00
|
|
|
int g_noconfig=0;
|
|
|
|
int g_display_errors=1;
|
|
|
|
FILE *g_output=stdout;
|
|
|
|
|
2007-04-15 21:27:41 +00:00
|
|
|
int GetTLBVersion(string& filepath, DWORD& high, DWORD & low)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
int found = 0;
|
|
|
|
|
2007-04-17 18:30:30 +00:00
|
|
|
char fullpath[1024];
|
|
|
|
char *p;
|
|
|
|
if (!GetFullPathName(filepath.c_str(), sizeof(fullpath), fullpath, &p))
|
|
|
|
return 0;
|
|
|
|
|
2009-01-10 22:12:10 +00:00
|
|
|
WCHAR *ole_filename = winchar_fromansi(fullpath);
|
2007-04-15 21:27:41 +00:00
|
|
|
|
|
|
|
ITypeLib* typeLib;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = LoadTypeLib(ole_filename, &typeLib);
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2005-04-16 17:08:46 +00:00
|
|
|
int main(int argc, char* argv[])
|
2004-08-06 22:04:13 +00:00
|
|
|
{
|
|
|
|
|
2005-04-16 17:08:46 +00:00
|
|
|
// Parse the command line
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2007-04-14 15:05:02 +00:00
|
|
|
string cmdline;
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2007-04-14 15:05:02 +00:00
|
|
|
string mode;
|
|
|
|
string filename;
|
|
|
|
string filepath;
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2007-04-14 15:05:02 +00:00
|
|
|
int filefound = 0;
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2005-10-07 13:21:09 +00:00
|
|
|
if (argc != 4)
|
|
|
|
return 1;
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2005-10-07 13:21:09 +00:00
|
|
|
// Get the full path of the local file
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2005-10-07 13:21:09 +00:00
|
|
|
mode = argv[1];
|
|
|
|
filename = argv[2];
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2005-10-07 13:21:09 +00:00
|
|
|
// Validate filename
|
2004-08-06 22:04:13 +00:00
|
|
|
|
2007-04-17 18:30:30 +00:00
|
|
|
ifstream fs(filename.c_str());
|
2005-10-07 13:21:09 +00:00
|
|
|
|
2007-04-16 20:15:00 +00:00
|
|
|
if (fs.is_open())
|
2005-10-07 13:21:09 +00:00
|
|
|
{
|
|
|
|
filefound = 1;
|
2007-04-16 20:15:00 +00:00
|
|
|
fs.close();
|
2005-10-07 13:21:09 +00:00
|
|
|
}
|
2007-04-16 20:15:00 +00:00
|
|
|
|
|
|
|
// Work
|
2007-04-14 15:05:02 +00:00
|
|
|
|
|
|
|
int versionfound = 0;
|
|
|
|
DWORD low = 0, high = 0;
|
|
|
|
|
|
|
|
if (filefound)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Get version
|
|
|
|
|
2008-11-20 21:54:21 +00:00
|
|
|
// DLL / EXE
|
2007-04-14 15:05:02 +00:00
|
|
|
|
|
|
|
if (mode.compare("D") == 0)
|
|
|
|
{
|
|
|
|
|
2007-04-17 18:30:30 +00:00
|
|
|
versionfound = GetDLLVersion(filename, high, low);
|
2007-04-14 15:05:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TLB
|
|
|
|
|
|
|
|
if (mode.compare("T") == 0)
|
|
|
|
{
|
|
|
|
|
2007-04-17 18:30:30 +00:00
|
|
|
versionfound = GetTLBVersion(filename, high, low);
|
2007-04-14 15:05:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the version to an NSIS header file
|
|
|
|
|
|
|
|
ofstream header(argv[3], ofstream::out);
|
|
|
|
|
|
|
|
if (header)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!filefound)
|
|
|
|
{
|
|
|
|
header << "!define LIBRARY_VERSION_FILENOTFOUND" << endl;
|
|
|
|
}
|
|
|
|
else if (!versionfound)
|
|
|
|
{
|
|
|
|
header << "!define LIBRARY_VERSION_NONE" << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header << "!define LIBRARY_VERSION_HIGH " << high << endl;
|
|
|
|
header << "!define LIBRARY_VERSION_LOW " << low << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
header.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2004-08-06 22:04:13 +00:00
|
|
|
|
|
|
|
}
|