Source code of Windows XP (NT5)
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.

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