-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxMsLinkerTime.cpp
102 lines (94 loc) · 3.57 KB
/
wxMsLinkerTime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*-----------------------------------------------------------------
* Name: wxMsLinkerTime.cpp
* Purpose:
* Author: A. Wiegert
*
* Copyright:
* Licence: wxWidgets license
*---------------------------------------------------------------- */
/*----------------------------------------------------------------
* Standard wxWidgets headers
*---------------------------------------------------------------- */
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
# if defined ( _DEBUG )
// this statement NEEDS to go BEFORE all headers
# define _CRTDBG_MAP_ALLOC
# endif
#endif
#include "wxMsPreProcDefsh.h" // needs to be first
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
/* For all others, include the necessary headers
* (this file is usually all you need because it
* includes almost all "standard" wxWidgets headers) */
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ------------------------------------------------------------------
#include "wxMsh.h"
#if defined( WANT_EXE_LINK_DATE )
#include <wx/stdpaths.h>
#include "exeDosHdrh.h"
#endif
// ------------------------------------------------------------------
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
// only good for MSVC
// this block needs to go AFTER all headers
#include <crtdbg.h>
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif
#endif
// ------------------------------------------------------------------
#if defined( WANT_EXE_LINK_DATE )
// ------------------------------------------------------------------
/**
* RetrieveLinkerTimestamp - get the linker time stamp from the current executable.
* Used to display the build date & copyright year in the 'About box.
* The old way used the compile macro __DATE__, but that froze the build date
* to the last time the file with the 'OnAbout() function was compiled,
* not what I wanted.
* Taken from:
http://www.codinghorror.com/blog/2005/04/determining-build-date-the-hard-way.html
*/
#define BYTE_BFR_SIZE 2048
#define PE_EXE_LINK_TIME 0x100
bool MyApp::RetrieveLinkerTimestamp( wxString& wsDate, wxString& wsYear )
{
BYTE cByteBfr[BYTE_BFR_SIZE];
size_t szBytesRead;
long lSecondsSince1970;
unsigned long ulNewHdrOffset;
wsDate = wxEmptyString;
wxString wsExePath = wxStandardPaths::Get().GetExecutablePath();
wxFile wfExe( wsExePath );
if ( !wfExe.IsOpened() )
return false;
szBytesRead = wfExe.Read( cByteBfr, BYTE_BFR_SIZE );
if( szBytesRead < BYTE_BFR_SIZE )
return false;
DosExeHdr pDosExeHdr( cByteBfr, BYTE_BFR_SIZE );
ulNewHdrOffset = pDosExeHdr.GetNewHdrOffset( cByteBfr );
// get the EXE link date & time as seconds since Jan 1, 1970
// located at NewHdrOffset + 8 bytes
lSecondsSince1970 = *(long *)(cByteBfr + ulNewHdrOffset + 8);
wxDateTime wdtExe( (time_t)lSecondsSince1970 ); // link time of .EXE
// wxString wsIsoDate = wdtExe.FormatISODate();
// wxString wsIsoTime = wdtExe.FormatISOTime();
wsYear.Printf( _T("%d"), wdtExe.GetYear() ); // Copyright year
// Note in wx 2.9.4 format "%e" - format day without leading '0' - bombs
wsDate = wdtExe.Format( _T("%B %#d, %Y") );// _T("%B %e, %Y") );
return true;
}
#endif //#if defined( WANT_EXE_LINK_DATE )
// ------------------------------- eof ------------------------------