|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Show / Check atool version. |
|
15 * |
|
16 */ |
|
17 #include "../inc/ATCommonDefines.h" |
|
18 #include "../inc/CATBase.h" |
|
19 |
|
20 //Function declarations. |
|
21 int showVersionInfo( void ); |
|
22 int showCoreVersionInfo( void ); |
|
23 bool readCoreVersionInfo( const string& sFile, string& sVersion ); |
|
24 string findAnalyzeToolHeader( void ); |
|
25 |
|
26 //External GetEpocRoot function |
|
27 extern bool GetEpocRoot( string &sEpocRoot ); |
|
28 |
|
29 void convertWriteTimeToLocalTime( FILETIME ftWrite, LPSTR lpszString ); |
|
30 |
|
31 int showCoreVersionInfo( void ) |
|
32 { |
|
33 LOG_FUNC_ENTRY( "version.cpp::showCoreVersionInfo" ); |
|
34 // Try find header from environment where to locate version info. |
|
35 string sHeaderFile = findAnalyzeToolHeader(); |
|
36 if ( sHeaderFile.empty() ) |
|
37 return 0; |
|
38 string sVersion(""); |
|
39 if ( readCoreVersionInfo( sHeaderFile, sVersion ) ) |
|
40 { |
|
41 cout << "AnalyzeTool SDK binaries version: " |
|
42 << sVersion |
|
43 << endl; |
|
44 } |
|
45 return 0; |
|
46 } |
|
47 |
|
48 |
|
49 /** |
|
50 * Find analyzetool.h header file |
|
51 * @return string containing full path to file or empty string if not found. |
|
52 */ |
|
53 string findAnalyzeToolHeader( void ) |
|
54 { |
|
55 LOG_FUNC_ENTRY( "version.cpp::findAnalyzeToolHeader" ); |
|
56 string sEpocRoot; |
|
57 if ( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
58 return string(""); |
|
59 int iC = sizeof( AT_CORE_INCLUDE_FILE_WITH_VERSION_NUMBER ) / sizeof ( string ); |
|
60 for( int i = 0 ; i < iC ; i++ ) |
|
61 { |
|
62 string sCheck( sEpocRoot ); |
|
63 sCheck.append( AT_CORE_INCLUDE_FILE_WITH_VERSION_NUMBER[i] ); |
|
64 if ( CATBase::FileExists( sCheck.c_str() ) ) |
|
65 return sCheck; |
|
66 } |
|
67 return string(""); |
|
68 } |
|
69 /** |
|
70 * Read core version string. |
|
71 * @param sVersion string will contain version info if funtion returns true. |
|
72 * @return true if successful. |
|
73 */ |
|
74 bool readCoreVersionInfo( const string& sFile, string& sVersion ) |
|
75 { |
|
76 LOG_FUNC_ENTRY( "version.cpp::readCoreVersionInfo" ); |
|
77 try { |
|
78 ifstream in; |
|
79 in.open( sFile.c_str() ); |
|
80 if ( ! in.good() ) |
|
81 return false; |
|
82 char cBuff[MAX_LINE_LENGTH]; |
|
83 while ( in.good() ) |
|
84 { |
|
85 in.getline( cBuff, MAX_LINE_LENGTH ); |
|
86 string s( cBuff ); |
|
87 if ( s.find( AT_CORE_VERSION_NUMBER_TAG ) != string::npos ) |
|
88 { |
|
89 // Find spot after first space (ignore first 3 chars). |
|
90 size_t t = s.find_first_of( ' ', 3 )+1; |
|
91 sVersion = s.substr( t, s.size()-t ); |
|
92 return true; |
|
93 } |
|
94 } |
|
95 } |
|
96 catch(...) |
|
97 { |
|
98 LOG_STRING(AT_MSG << "Exception reading core version info."); |
|
99 } |
|
100 return false; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Print version information of atool.exe binary. |
|
105 */ |
|
106 int showVersionInfo( void ) |
|
107 { |
|
108 LOG_FUNC_ENTRY( "version.cpp::showVersionInfo" ); |
|
109 string sTemp( "Version: " ); |
|
110 sTemp.append( ATOOL_VERSION ); |
|
111 sTemp.append( "\n" ); |
|
112 //Print atool version |
|
113 printf( sTemp.c_str() ); |
|
114 |
|
115 //atool.exe:s path + filename |
|
116 char buffer[MAX_PATH]; |
|
117 |
|
118 GetModuleFileName( NULL, buffer, MAX_PATH ); |
|
119 |
|
120 printf( "Path: %s\n", buffer ); |
|
121 |
|
122 WIN32_FIND_DATA FindFileData; |
|
123 HANDLE hFind; |
|
124 //Get file handle |
|
125 hFind = FindFirstFile( buffer, &FindFileData ); |
|
126 |
|
127 if( hFind == INVALID_HANDLE_VALUE ) |
|
128 { |
|
129 printf( "Can not find file:%s", buffer ); |
|
130 return 0; |
|
131 } |
|
132 |
|
133 convertWriteTimeToLocalTime( FindFileData.ftLastWriteTime , buffer ); |
|
134 printf( "Modified: %s\n", buffer ); |
|
135 |
|
136 // Show core version information. |
|
137 showCoreVersionInfo(); |
|
138 return 0; |
|
139 } |
|
140 |
|
141 // Convert the last-write time to local time. |
|
142 void convertWriteTimeToLocalTime( FILETIME ftWrite, LPSTR lpszString ) |
|
143 { |
|
144 LOG_FUNC_ENTRY( "version.cpp::convertWriteTimeToLocalTime" ); |
|
145 SYSTEMTIME stUTC, stLocal; |
|
146 // Convert the last-write time to local time. |
|
147 FileTimeToSystemTime(&ftWrite, &stUTC); |
|
148 SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal); |
|
149 |
|
150 // Build a string showing the date and time. |
|
151 wsprintf(lpszString, "%02d/%02d/%d %02d:%02d:%02d", |
|
152 stLocal.wDay, stLocal.wMonth, stLocal.wYear, |
|
153 stLocal.wHour, stLocal.wMinute, stLocal.wSecond); |
|
154 } |
|
155 |
|
156 //EOF |