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.

223 lines
6.8 KiB

  1. // ------------------------------------------------------------------------
  2. //
  3. // Microsoft Visual Studio
  4. // Copyright (c) 1997 Microsoft Corporation
  5. //
  6. // ------------------------------------------------------------------------
  7. // MODULE : hhsetup.cpp
  8. // PURPOSE : stub dll
  9. // FUNCTIONS :
  10. // COMMENTS :
  11. // ------------------------------------------------------------------------
  12. #define STRICT // strict type checking enabled
  13. // #define _UNICODE // make the application Unicode compliant (C/C++)
  14. // #define UNICODE // make the application Unicode compliant (Win32)
  15. #include <Windows.H> // required for all Windows applications
  16. #include "fs.h"
  17. #include "info.h"
  18. #include "util.h"
  19. #include "stdio.h"
  20. // public defines
  21. // ------------------------------------------------------------------------
  22. // public data
  23. // ------------------------------------------------------------------------
  24. // public function prototypes
  25. // -----------------------------------------------------------------------
  26. DWORD GetTitleVersion(const TCHAR *szFileName);
  27. DWORD GetFileVersion(const TCHAR *szFileName);
  28. LANGID GetLangId(const TCHAR *szFileName);
  29. // private defines
  30. // ------------------------------------------------------------------------
  31. // private data
  32. // ------------------------------------------------------------------------
  33. static HINSTANCE g_hInstance = 0;
  34. // private function prototypes
  35. // -----------------------------------------------------------------------
  36. // callback procedures prototypes
  37. // -----------------------------------------------------------------------
  38. // ========================================================================
  39. // == Standard Windows Entry Point Function ==
  40. // ========================================================================
  41. // ------------------------------------------------------------------------
  42. // DllMain
  43. //
  44. // @Doc WINDOWS BOTH
  45. // @Func DllMain is the Win32 internal entry point. DllMain is called
  46. // by the C run-time library from the _DllMainCRTStartup entry
  47. // point. The DLL entry point gets called (entered) on the
  48. // following events: "Process Attach", "Thread Attach",
  49. // "Thread Detach" or "Process Detach".
  50. // @Parm: (NONE)
  51. // @RDesc:(NONE)
  52. // @Comm: (NONE)
  53. // ------------------------------------------------------------------------
  54. BOOL WINAPI DllMain( HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved )
  55. {
  56. switch( dwReason ) {
  57. case DLL_PROCESS_ATTACH:
  58. // to your init stuff here
  59. g_hInstance = hDll;
  60. break;
  61. case DLL_THREAD_ATTACH:
  62. case DLL_THREAD_DETACH:
  63. break;
  64. case DLL_PROCESS_DETACH:
  65. // free you init stuff here
  66. g_hInstance = 0;
  67. break;
  68. }
  69. return( TRUE );
  70. UNREFERENCED_PARAMETER( lpReserved );
  71. }
  72. DWORD GetTitleVersion(const TCHAR *szFileName)
  73. {
  74. WCHAR wszFileSysName[MAX_PATH]; // UNICODE filename buffer
  75. CHAR szFileSysName[MAX_PATH]; // MBCS filename buffer
  76. HRESULT hr;
  77. // Create destination storage names
  78. LPTSTR pszFilename = NULL;
  79. GetFullPathName( szFileName, MAX_PATH, szFileSysName, &pszFilename );
  80. if (0 == MultiByteToWideChar(CP_ACP, 0, szFileSysName, -1, wszFileSysName, MAX_PATH)) {
  81. return GetFileVersion(szFileName);
  82. }
  83. CFileSystem* pFileSystem = new CFileSystem;
  84. pFileSystem->Init();
  85. if (!(SUCCEEDED(pFileSystem->Open( szFileSysName ))))
  86. {
  87. delete pFileSystem;
  88. return GetFileVersion(szFileName);
  89. }
  90. // open the title information file (#SYSTEM)
  91. CSubFileSystem* pSubFileSystem = new CSubFileSystem(pFileSystem);
  92. hr = pSubFileSystem->OpenSub("#SYSTEM");
  93. if (FAILED(hr))
  94. {
  95. pFileSystem->Close();
  96. delete pFileSystem;
  97. return GetFileVersion(szFileName);
  98. }
  99. // check the version of the title information file (#SYSTEM)
  100. DWORD dwVersion;
  101. DWORD cbRead;
  102. hr = pSubFileSystem->ReadSub(&dwVersion, sizeof(dwVersion), &cbRead);
  103. if (FAILED(hr) || cbRead != sizeof(dwVersion)) {
  104. pFileSystem->Close();
  105. delete pFileSystem;
  106. delete pSubFileSystem;
  107. return GetFileVersion(szFileName);
  108. }
  109. // read in each and every item (skip those tags we don't care about)
  110. SYSTEM_TAG tag;
  111. SYSTEM_FLAGS Settings; // simple title information settings
  112. for(;;) {
  113. // get the tag type
  114. hr = pSubFileSystem->ReadSub(&tag, sizeof(SYSTEM_TAG), &cbRead);
  115. if (FAILED(hr) || cbRead != sizeof(SYSTEM_TAG))
  116. break;
  117. // handle each tag according to it's type
  118. switch (tag.tag) {
  119. // where all of our simple settings are stored
  120. case TAG_SYSTEM_FLAGS: {
  121. memset( &Settings , 0 , sizeof(SYSTEM_FLAGS));
  122. DWORD cbSettings = sizeof(Settings);
  123. DWORD cbTag = tag.cbTag;
  124. DWORD cbReadIn = 0;
  125. if( cbTag > cbSettings )
  126. cbReadIn = cbSettings;
  127. else
  128. cbReadIn = cbTag;
  129. hr = pSubFileSystem->ReadSub( &Settings, cbReadIn, &cbRead );
  130. if( cbTag > cbSettings )
  131. hr = pSubFileSystem->SeekSub( cbTag-cbSettings, SEEK_CUR );
  132. delete pSubFileSystem;
  133. pFileSystem->Close();
  134. delete pFileSystem;
  135. return Settings.FileTime.dwHighDateTime;
  136. }
  137. // skip those we don't care about or don't know about
  138. default: {
  139. hr = pSubFileSystem->SeekSub( tag.cbTag, SEEK_CUR );
  140. break;
  141. }
  142. }
  143. if (FAILED(hr)) {
  144. pFileSystem->Close();
  145. delete pFileSystem;
  146. delete pSubFileSystem;
  147. return GetFileVersion(szFileName);
  148. }
  149. }
  150. delete pSubFileSystem;
  151. pFileSystem->Close();
  152. delete pFileSystem;
  153. return GetFileVersion(szFileName);
  154. }
  155. DWORD GetFileVersion(const TCHAR *szFileName)
  156. {
  157. FILETIME FileTime1, FileTime2, FileTime3;
  158. DWORD dw = 0;
  159. HANDLE fHandle;
  160. fHandle = CreateFile(szFileName, GENERIC_READ , FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
  161. if (fHandle != INVALID_HANDLE_VALUE)
  162. if (GetFileTime( fHandle, &FileTime1, &FileTime2, &FileTime3) == TRUE)
  163. dw = FileTime3.dwHighDateTime;
  164. CloseHandle(fHandle);
  165. return dw;
  166. }
  167. LANGID GetLangId(const TCHAR *szFileName)
  168. {
  169. HANDLE hFile = CreateFile( szFileName, GENERIC_READ, FILE_SHARE_READ,
  170. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL );
  171. if( hFile == INVALID_HANDLE_VALUE )
  172. return 0;
  173. DWORD dwFileStamp = 0;
  174. LCID FileLocale = 0;
  175. DWORD dwRead = 0;
  176. SetFilePointer( hFile, 4*sizeof(UINT), NULL, FILE_BEGIN );
  177. ReadFile( hFile, (void*) &dwFileStamp, sizeof( dwFileStamp ), &dwRead, NULL );
  178. ReadFile( hFile, (void*) &FileLocale, sizeof( FileLocale ), &dwRead, NULL );
  179. CloseHandle( hFile );
  180. return (LANGID) FileLocale;
  181. }