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.

172 lines
4.5 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000
  5. //
  6. // File: FileVersionInfo.cpp
  7. //
  8. // Contents: Code for generating matching information for files in a given
  9. // directory and it's subdirectories.
  10. //
  11. // History: 18-Jul-00 jdoherty Created.
  12. // 14-Mar-02 mnikkel Modified to use strsafe.h
  13. //
  14. //---------------------------------------------------------------------------
  15. #include <windows.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <shlobj.h>
  19. #include <strsafe.h>
  20. BOOL MyStoreFileVersionInfo( CHAR *szFileName, CHAR *szFileOutName );
  21. void CheckVerQueryStats ( LPVOID lpData );
  22. // Needed by GetFileVersionInfo stubs
  23. typedef struct StringTable
  24. {
  25. WORD wLength;
  26. WORD wValueLength;
  27. WORD wType;
  28. CHAR szKey[8];
  29. } ST;
  30. typedef struct StringFileInfo
  31. {
  32. WORD wLength;
  33. WORD wValueLength;
  34. WORD wType;
  35. CHAR szKey[sizeof("StringFileInfo")];
  36. ST st;
  37. } SFI;
  38. typedef struct tagVERHEAD
  39. {
  40. WORD wTotLen;
  41. WORD wValLen;
  42. WORD wType; // always 0
  43. CHAR szKey[(sizeof("VS_VERSION_INFO")+3)&~03];
  44. VS_FIXEDFILEINFO vsf;
  45. SFI sfi;
  46. } VERHEAD;
  47. int __cdecl main(int argc, CHAR* argv[])
  48. {
  49. LPTSTR szCommandLine = {'\0'};
  50. if (argc > 3)
  51. {
  52. printf("The correct usage is:\n\tFileVerInfo.exe [filename including path]\n");
  53. getchar();
  54. return 0;
  55. }
  56. printf("Attempting to retrieve file version info for: %s\n", argv[1]);
  57. if(!MyStoreFileVersionInfo(argv[1], argv[2]))
  58. {
  59. printf("There was a problem retrieving the information.\n");
  60. getchar();
  61. return 0;
  62. }
  63. else
  64. szCommandLine = GetCommandLine();
  65. printf("The command line contained: %s\n", szCommandLine);
  66. printf("Operation completed successfully");
  67. getchar();
  68. return 0;
  69. }
  70. /*
  71. This function retrieves the version information for the file specified and stores the
  72. information on the users desktop, FileVerInfo.bin
  73. */
  74. BOOL MyStoreFileVersionInfo ( CHAR *szFileName, CHAR *szFileOutName )
  75. {
  76. LPDWORD lpdwHandle = 0;
  77. DWORD dwBytesToWrite = GetFileVersionInfoSizeA(szFileName, lpdwHandle);
  78. DWORD lpdwBytesWritten = 0;
  79. LPVOID lpData= malloc(dwBytesToWrite);
  80. CHAR lpPath[MAX_PATH*2] = {'\0'};
  81. HANDLE hfile;
  82. if( !dwBytesToWrite )
  83. {
  84. printf("There was a problem in GetFileVersionInfoSize()\n");
  85. printf("GLE reports error %d\n", GetLastError());
  86. return FALSE;
  87. }
  88. if ( !GetFileVersionInfoA(szFileName, NULL, dwBytesToWrite, lpData) )
  89. {
  90. printf("There was a problem in GetFileVersionInfo()\n");
  91. return FALSE;
  92. }
  93. CheckVerQueryStats(lpData);
  94. if(S_OK != StringCchCat(lpPath, MAX_PATH*2, ".\\"))
  95. {
  96. printf("Unable to add to path string!\n");
  97. return FALSE;
  98. }
  99. if ( szFileOutName )
  100. {
  101. if(S_OK != StringCchCat(lpPath, MAX_PATH*2, szFileOutName) ||
  102. S_OK != StringCchCat(lpPath, MAX_PATH*2, ".bin"))
  103. {
  104. printf("Unable to add to path string!\n");
  105. return FALSE;
  106. }
  107. }
  108. else
  109. {
  110. if(S_OK != StringCchCat(lpPath, MAX_PATH*2, ".\\FileVerInfo.bin"))
  111. {
  112. printf("Unable to add to path string!\n");
  113. return FALSE;
  114. }
  115. }
  116. hfile = CreateFileA(lpPath,
  117. GENERIC_WRITE,
  118. 0,
  119. NULL,
  120. CREATE_ALWAYS,
  121. FILE_ATTRIBUTE_NORMAL,
  122. NULL);
  123. if (hfile == INVALID_HANDLE_VALUE)
  124. {
  125. printf("There was a problem opening %s\n", lpPath);
  126. return FALSE;
  127. }
  128. printf("About to write to file: %s\n", lpPath);
  129. WriteFile( hfile, lpData, dwBytesToWrite, &lpdwBytesWritten, NULL );
  130. CloseHandle (hfile);
  131. return TRUE;
  132. }
  133. /*
  134. This function displays the minor version and the SFI version to the screen
  135. */
  136. void CheckVerQueryStats ( LPVOID lpData )
  137. {
  138. PUINT puLen = 0;
  139. printf("The minor version is: \t%x\n",((VERHEAD*) lpData)->vsf.dwFileVersionMS);
  140. printf("The SFI version is: \t%s\n",((VERHEAD*) lpData)->sfi.st.szKey);
  141. return;
  142. }