Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
6.7 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <wtypes.h>
  5. #include <windows.h>
  6. #include <sys\stat.h>
  7. #include "wmdm_ver.h"
  8. #include <tchar.h>
  9. BOOL FileExists(LPCSTR pszFile)
  10. {
  11. return (GetFileAttributesA(pszFile) != 0xFFFFFFFF);
  12. }
  13. ////////////////////////////////////////////////////////////////////////
  14. void SeparateName( const TCHAR *pszFullPath, TCHAR *pszFileName)
  15. ////////////////////////////////////////////////////////////////////////
  16. {
  17. if( ( NULL == pszFullPath ) || ( NULL == pszFileName ) )
  18. {
  19. return;
  20. }
  21. TCHAR *pIndex = _tcsrchr( pszFullPath, _T( '\\' ) );
  22. if( pIndex )
  23. {
  24. _tcscpy( pszFileName, pIndex + 1);
  25. }
  26. else
  27. {
  28. _tcscpy( pszFileName, pszFullPath);
  29. }
  30. }
  31. //////////////////////////////////////////////////////////////////////////////
  32. HRESULT GetFileVersion( LPCSTR pszFileName, LPSTR pszVersionStr )
  33. //////////////////////////////////////////////////////////////////////////////
  34. {
  35. if( ( NULL == pszFileName ) || ( !FileExists( pszFileName ) ) )
  36. {
  37. return( E_FAIL );
  38. }
  39. //
  40. // Figure out size of version information
  41. //
  42. DWORD dwHandle;
  43. DWORD versionInfoSize = GetFileVersionInfoSize( (LPSTR)pszFileName, &dwHandle );
  44. if( 0 == versionInfoSize )
  45. {
  46. DWORD dwError = GetLastError();
  47. return( E_FAIL );
  48. }
  49. //
  50. // Allocate a buffer to hold the version information
  51. //
  52. BYTE *pVersionInfo = new BYTE[versionInfoSize];
  53. if( NULL == pVersionInfo )
  54. {
  55. return( E_OUTOFMEMORY );
  56. }
  57. //
  58. // Load the version information
  59. //
  60. HRESULT hr = E_FAIL;
  61. if( GetFileVersionInfo( (LPSTR)pszFileName, 0, versionInfoSize, pVersionInfo ) )
  62. {
  63. VS_FIXEDFILEINFO *pFileInfo;
  64. UINT fileInfoLen;
  65. if( VerQueryValue( pVersionInfo, "\\", (void**)&pFileInfo, &fileInfoLen ) )
  66. {
  67. sprintf( pszVersionStr, "%lu,%lu,%lu,%lu", HIWORD( pFileInfo->dwFileVersionMS ), LOWORD( pFileInfo->dwFileVersionMS ), HIWORD( pFileInfo->dwFileVersionLS ), LOWORD( pFileInfo->dwFileVersionLS ) );
  68. hr = S_OK;
  69. }
  70. else
  71. {
  72. DWORD dwError = GetLastError();
  73. }
  74. }
  75. else
  76. {
  77. DWORD dwError = GetLastError();
  78. }
  79. delete [] pVersionInfo;
  80. return( hr );
  81. }
  82. //*****************************************************************************
  83. void __cdecl main ( int argc, char **argv )
  84. // See Usage for exact details
  85. //*****************************************************************************
  86. {
  87. BOOL fSent = FALSE;
  88. if( argc > 1 )
  89. {
  90. char szVersion[100];
  91. if( ( strstr( argv[1], "inf" ) ) || ( strstr( argv[1], "INF" ) ) )
  92. {
  93. char *pComma;
  94. strcpy( szVersion, VER_WMDM_PRODUCTVERSION_STR );
  95. pComma = strstr( szVersion, "." );
  96. while( NULL != pComma )
  97. {
  98. pComma[0] = ',';
  99. pComma = strstr( szVersion, "." );
  100. }
  101. fSent = TRUE;
  102. }
  103. else if( ( strstr( argv[1], "purge" ) ) || ( strstr( argv[1], "PURGE" ) ) )
  104. {
  105. char szData[50];
  106. char szCurrentIni[MAX_PATH];
  107. GetTempPath( sizeof( szCurrentIni ), szCurrentIni );
  108. strcat( szCurrentIni, "\\mp2size.ini" );
  109. if( GetPrivateProfileString( "Size", "Total", "Leprechauns", szData, sizeof( szData ), szCurrentIni )
  110. && ( 0 != _stricmp( "Leprechauns", szData ) ) )
  111. {
  112. printf( "TotalSize=%s\n", szData );
  113. }
  114. DeleteFile( szCurrentIni );
  115. exit( 0 );
  116. }
  117. else if( argc > 2 )
  118. {
  119. if( ( strstr( argv[1], "client" ) ) || ( strstr( argv[1], "CLIENT" ) ) )
  120. {
  121. if( S_OK == GetFileVersion( argv[2], szVersion ) )
  122. {
  123. fSent = TRUE;
  124. }
  125. }
  126. else if( ( strstr( argv[1], "addsize" ) ) || ( strstr( argv[1], "ADDSIZE" ) ) )
  127. {
  128. if( FileExists( argv[2] ) )
  129. {
  130. char szData[50];
  131. char szCurrentIni[MAX_PATH];
  132. struct _stat ss;
  133. DWORD dwSize = 0;
  134. GetTempPath( sizeof( szCurrentIni ), szCurrentIni );
  135. strcat( szCurrentIni, "\\mp2size.ini" );
  136. if( GetPrivateProfileString( "Size", "Total", "Leprechauns", szData, sizeof( szData ), szCurrentIni )
  137. && ( 0 != _stricmp( "Leprechauns", szData ) ) )
  138. {
  139. dwSize = atol( szData );
  140. }
  141. else
  142. {
  143. dwSize = 0;
  144. }
  145. if( _stat( argv[2], &ss ) == 0)
  146. {
  147. dwSize += ss.st_size;
  148. }
  149. sprintf( szData, "%lu", dwSize );
  150. WritePrivateProfileString( "Size", "Total", szData, szCurrentIni );
  151. printf( "%lu", dwSize );
  152. }
  153. else
  154. {
  155. printf( "File %s not found!\n", argv[2] );
  156. }
  157. exit( 0 );
  158. }
  159. else if( ( strstr( argv[1], "sizeit" ) ) || ( strstr( argv[1], "SIZEIT" ) ) )
  160. {
  161. if( FileExists( argv[2] ) )
  162. {
  163. TCHAR szFileName[100];
  164. struct _stat ss;
  165. DWORD dwSize = 0;
  166. if( _stat( argv[2], &ss ) == 0)
  167. {
  168. dwSize += ss.st_size;
  169. }
  170. SeparateName( argv[2], szFileName );
  171. printf( "%s=0,,%lu\n", szFileName, dwSize );
  172. }
  173. exit( 0 );
  174. }
  175. }
  176. if( fSent )
  177. {
  178. printf( "\nVERSION=\"%s\"\n", szVersion );
  179. }
  180. }
  181. if( !fSent )
  182. {
  183. printf( "\n[VersionSection]\n" );
  184. printf( "FileVersion=\"%s\"\n", VER_WMDM_PRODUCTVERSION_STR );
  185. printf( "ProductVersion=\"%s\"\n", VER_WMDM_PRODUCTVERSION_STR );
  186. printf( "FileDescription=\"Windows Media Component Setup Application\"\n" );
  187. printf( "ProductName=\"Windows Media Component Setup Application\"\n" );
  188. printf( "LegalCopyright=\"Copyright (C) %s %s\"\n", VER_WMDM_COMPANYNAME_STR, VER_WMDM_LEGALCOPYRIGHT_YEARS );
  189. }
  190. exit( 0 );
  191. }