OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
modversi.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TModuleVersionInfo, version resource parser &
7/// accessor class
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/module.h>
11#include <stdio.h>
12#include <owl/except.rh>
13
14namespace owl {
15
17
18static tchar viRootStr[] = _T("\\");
19static tchar viTransStr[] = _T("\\VarFileInfo\\Translation");
20static tchar viSubBlockQueryFmt[] = _T("\\StringFileInfo\\%08lx\\%s");
21static tchar viFileDescStr[] = _T("FileDescription");
22static tchar viFileVersionStr[] = _T("FileVersion");
23static tchar viInternalNameStr[] = _T("InternalName");
24static tchar viLegalCopyrightStr[] = _T("LegalCopyright");
25static tchar viOriginalFilenameStr[] = _T("OriginalFilename");
26static tchar viProductNameStr[] = _T("ProductName");
27static tchar viProductVersionStr[] = _T("ProductVersion");
28static tchar viSpecialBuildStr[] = _T("SpecialBuild");
29
30//
31/// Constructs a TModuleVersionInfo given a module or instance handle
32//
34:
35 Buff(nullptr),
36 Lang(0),
37 FixedInfo(nullptr)
38{
40 ::GetModuleFileName(hModule, modFName, _MAX_PATH);
41#if !defined(UNICODE)
43#endif
44
46}
47
48//
49/// Constructs a TModuleVersionInfo given a module filename
50/// String version. Throws TXModuleVersionInfo on errors. [VH 2005-04-03]
51//
53:
54 Buff(nullptr),
55 Lang(0),
56 FixedInfo(nullptr)
57{
58 Init(modFName.c_str ());
59}
60
61//
62// Internal initialization fills in the data members
63// Now returns void and throws exceptions. [VH 2005-04-03]
64//
65void
67{
68 try {
70#if defined WINELIB
72#else
74#endif
75 if (!infoSize)
76 throw 1; // Caught below.
77
80 throw 2; // Caught below.
81
82 // Copy string to buffer so if the -dc compiler switch (Put constant
83 // strings in code segments) is on, VerQueryValue will work under Win16.
84 // This works around a problem in Microsoft's ver.dll which writes to the
85 // string pointed to by subBlockName.
86 //
87 uint vInfoLen; // not really used, but must be passed
88 tchar* subBlockName = viRootStr;
90 throw 3; // Caught below.
91
92 subBlockName = viTransStr;
93 uint32 * trans;
94 if (!TVersion::VerQueryValue(buf, subBlockName, (void **)&trans, &vInfoLen))
95 throw 4; // Caught below.
96
97 // Assign language and buffer.
98 //
99 // Swap the words so sprintf will print the lang-charset in the correct format.
101 Buff = buf.Relinquish (); // Take ownership.
102 }
103
104 catch (...) {
105
106 // Rethrow dedicated exception.
107 //
108 LPCTSTR msg = 0;
110 if (last_error.SysError())
111 msg = last_error.SysMessage ().c_str();
113 }
114}
115
116//
117// Clean up the new'd buffer
118//
123
124//
125/// Queries any given "\\StringFileInfo\\lang-charset\<str>" version. Info string lang
126/// indicates the language translation, may be 0 to signify file default.
127//
128bool
137
138//
139// Commonly used, predefined info string queries. Pass requested language thru,
140// may be 0 to signify default.
141//
142
143//
144/// Retrieves the file description information in the requested language id.
145//
150
151//
152/// Retrieves the file version information in the requested language id.
153//
154bool
159
160//
161/// Retrieves the internal name of the module.
162//
163bool
168
169//
170/// Retrieves the copyright message.
171//
172bool
177
178//
179/// Retrieves the original filename.
180//
181bool
186
187//
188/// Retrieves the product name this module is associated with.
189//
190bool
195
196//
197/// Retrieves the version of the product.
198//
199bool
204
205//
206/// Retrieves the special build number.
207//
208bool
210{
211 // !CQ could check VS_FF_SPECIALBUILD flag first...
212 return GetInfoString(viSpecialBuildStr, specialBuild, lang);
213}
214
215//
216/// Local error handler for string query methods. [VH 2005-04-03]
217//
218static struct TEH
219 {
220 bool operator=(bool r)
221 {if (!r) TXModuleVersionInfo().Throw (); return r;}
222 }
223 E;
224
225//
226// Query any given "\StringFileInfo\lang-charset<str>" version info string.
227// lang indicates the language translation, may be 0 to signify file default.
228// String version. Throws exception on failure. [VH 2005-04-03]
229//
231 {LPCTSTR v = _T(""); E = GetInfoString(str.c_str (), v, lang); return v;}
232
233//
234// Commonly used, predefined info string queries. Pass requested language thru,
235// may be 0 to signify default.
236
237/// Retrieves the file description information in the requested language id.
238/// String version. [VH 2005-04-03]
239//
242
243//
244/// Retrieves the file version information in the requested language id.
245/// String version. [VH 2005-04-03]
246//
249
250//
251/// Retrieves the internal name of the module.
252/// String version. [VH 2005-04-03]
253//
256
257//
258/// Retrieves the copyright message.
259/// String version. [VH 2005-04-03]
260//
263
264//
265/// Retrieves the original filename.
266/// String version. [VH 2005-04-03]
267//
270
271//
272/// Retrieves the product name this module is associated with.
273/// String version. [VH 2005-04-03]
274//
277
278//
279/// Retrieves the version of the product.
280/// String version. [VH 2005-04-03]
281//
284
285//
286/// Retrieves the special build number.
287/// String version. [VH 2005-04-03]
288//
291
292//
293/// Gets the language name string associated with a language/charset code
294//
303
304//
305/// Returns values of TFileType if GetFileType() returned DevDriver or Font.
306/// If GetFileType() returned VirtDriver, this function returns the virtual
307/// device identifier included in the virtual device control block.
308//
310{
312 uint32 fileSubType = FixedInfo->dwFileSubtype;
313
314 switch (GetFileType()) {
315 case TypeUnknown:
316 case App:
317 case DLL:
318 break;
319 case DevDriver:
320 switch (FixedInfo->dwFileSubtype) {
321 case VFT2_UNKNOWN:
323 break;
324 case VFT2_DRV_PRINTER:
326 break;
329 break;
332 break;
333 case VFT2_DRV_DISPLAY:
335 break;
336 case VFT2_DRV_MOUSE:
338 break;
339 case VFT2_DRV_NETWORK:
341 break;
342 case VFT2_DRV_SYSTEM:
344 break;
347 break;
348 default: //case VFT2_DRV_SOUND:
350 }
351 break;
352 case Font:
353 switch (FixedInfo->dwFileSubtype) {
354 case VFT2_UNKNOWN:
356 break;
357 case VFT2_FONT_RASTER:
359 break;
360 case VFT2_FONT_VECTOR:
362 break;
363 default: //case VFT2_FONT_TRUETYPE:
365 }
366 break;
367 case VirtDevice:
368 case StaticLib:
369 break;
370 }
371 return fileSubType;
372}
373
374//
375/// Retrieves the file date.
376//
378{
380 FILETIME ft = {FixedInfo->dwFileDateLS, FixedInfo->dwFileDateMS};
381 return ft;
382}
383
384
385//----------------------------------------------------------------------------
386//
387// Exception class [VH 2005-04-03]
388//
389
390//
391/// Create the exception.
392//
398
399//
400/// Creates a copy of the exception
401//
404{
405 return new TXModuleVersionInfo(*this);
406}
407
408
409//
410/// Throws the exception
411//
412void
414{
415 throw *this;
416}
417
418//
419/// Throws the exception
420//
421void
426
427
428} // OWL namespace
429/* ========================================================================== */
430
#define PRECONDITION(condition)
Definition checks.h:227
static DWORD VerLanguageName(DWORD, TCHAR *, DWORD)
Definition module.cpp:1179
static BOOL VerQueryValue(const LPVOID, TCHAR *, LPVOID, uint *)
Definition module.cpp:1168
static BOOL GetFileVersionInfo(TCHAR *, DWORD, DWORD, LPVOID)
Definition module.cpp:1146
static DWORD GetFileVersionInfoSize(TCHAR *, LPDWORD)
Definition module.cpp:1157
Exception class for TModuleVersionInfo. [VH 2005-04-03].
Definition module.h:315
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition except.h:38
#define _stprintf
Definition cygwin.h:88
#define _MAX_PATH
Definition cygwin.h:97
#define MAX_PATH
Definition cygwin.h:98
#define _T(x)
Definition cygwin.h:51
#define OemToAnsi
Definition cygwin.h:54
VS_FIXEDFILEINFO * FixedInfo
Fixed file info structure.
Definition module.h:287
bool GetSpecialBuild(LPCTSTR &debug, uint lang=0)
Retrieves the special build number.
Definition modversi.cpp:209
static void Raise(const tstring &name=tstring())
Throws the exception.
Definition modversi.cpp:422
bool GetOriginalFilename(LPCTSTR &originalFilename, uint lang=0)
Retrieves the original filename.
Definition modversi.cpp:182
bool GetProductVersion(LPCTSTR &prodVersion, uint lang=0)
Retrieves the version of the product.
Definition modversi.cpp:200
bool GetProductName(LPCTSTR &prodName, uint lang=0)
Retrieves the product name this module is associated with.
Definition modversi.cpp:191
void Throw()
Throws the exception.
Definition modversi.cpp:413
tstring GetLanguageName() const
Return the language name of this module.
Definition module.h:1556
HINSTANCE THandle
TModule encapsulates an HINSTANCE.
Definition module.h:79
TModuleVersionInfo(TModule::THandle module)
Constructs a TModuleVersionInfo given a module or instance handle.
Definition modversi.cpp:33
TXModuleVersionInfo * Clone()
Creates a copy of the exception.
Definition modversi.cpp:403
bool GetFileVersion(LPCTSTR &fileVersion, uint lang=0)
Retrieves the file version information in the requested language id.
Definition modversi.cpp:155
bool GetFileDescription(LPCTSTR &fileDesc, uint lang=0)
Retrieves the file description information in the requested language id.
Definition modversi.cpp:146
TXModuleVersionInfo(const tstring &name=tstring())
Create the exception.
Definition modversi.cpp:393
uint8 * Buff
new'd File version info buffer
Definition module.h:285
bool GetLegalCopyright(LPCTSTR &copyright, uint lang=0)
Retrieves the copyright message.
Definition modversi.cpp:173
TFileType GetFileType() const
Definition module.h:1539
bool GetInternalName(LPCTSTR &internalName, uint lang=0)
Retrieves the internal name of the module.
Definition modversi.cpp:164
uint32 GetFileSubType() const
Returns values of TFileType if GetFileType() returned DevDriver or Font.
Definition modversi.cpp:309
uint32 Lang
Default language translation.
Definition module.h:286
bool GetInfoString(LPCTSTR str, LPCTSTR &value, uint lang=0)
Queries any given "\\StringFileInfo\\lang-charset\<str>" version.
Definition modversi.cpp:129
void Init(LPCTSTR modFName)
Definition modversi.cpp:66
FILETIME GetFileDate() const
Retrieves the file date.
Definition modversi.cpp:377
@ KybdDriver
VFT2_DRV_KEYBOARD.
Definition module.h:213
@ SysDriver
VFT2_DRV_SYSTEM.
Definition module.h:218
@ VectorFont
VFT2_FONT_VECTOR.
Definition module.h:223
@ InstallableDriver
VFT2_DRV_INSTALLABLE.
Definition module.h:219
@ DisplayDriver
VFT2_DRV_DISPLAY.
Definition module.h:215
@ RasterFont
VFT2_FONT_RASTER.
Definition module.h:222
@ UnknownFont
VFT2_UNKNOWN.
Definition module.h:221
@ LangDriver
VFT2_DRV_LANGUAGE.
Definition module.h:214
@ MouseDriver
VFT2_DRV_MOUSE.
Definition module.h:216
@ TrueTypeFont
VFT2_FONT_TRUETYPE.
Definition module.h:224
@ UnknownDevDriver
VFT2_UNKNOWN.
Definition module.h:211
@ PtrDriver
VFT2_DRV_PRINTER.
Definition module.h:212
@ SoundDriver
VFT2_DRV_SOUND.
Definition module.h:220
@ NtwkDriver
VFT2_DRV_NETWORK.
Definition module.h:217
Definition of class TModule.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
uint32 MkUint32(uint16 lo, uint16 hi)
Definition defs.h:261
uint16 HiUint16(LRESULT r)
Definition defs.h:270
unsigned char uint8
Definition number.h:32
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
uint16 LoUint16(LRESULT r)
Definition defs.h:264
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25