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.

158 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. help.c
  5. Abstract:
  6. This file implements the code for the help file installation.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Wesley Witt (wesw) 17-Feb-1996
  11. --*/
  12. #include "wizard.h"
  13. #pragma hdrstop
  14. #define HELP_INDEX_TAG ":Index "
  15. #define HELP_INDEX_SEP '='
  16. #define CRLF "\r\n"
  17. #define FAX_HELP_STRING ":Index Fax Help=fax.hlp"
  18. #define FAX_HELP_TAG "Fax Help"
  19. #define HELP_INDEX_TAG_LEN 7
  20. #define FAX_HELP_TAG_LEN 8
  21. #define FAX_HELP_STRING_LEN 23
  22. #define CRLF_LEN 2
  23. BOOL
  24. InstallHelpFiles(
  25. VOID
  26. )
  27. {
  28. BOOL rVal = FALSE;
  29. TCHAR Buffer[MAX_PATH];
  30. HANDLE hFile = INVALID_HANDLE_VALUE;
  31. HANDLE hMap = NULL;
  32. LPSTR fPtr = NULL;
  33. LPSTR p,s;
  34. DWORD FileSize;
  35. INT cmp;
  36. ExpandEnvironmentStrings( TEXT("%windir%\\system32\\windows.cnt"), Buffer, sizeof(Buffer) );
  37. hFile = CreateFile(
  38. Buffer,
  39. GENERIC_READ | GENERIC_WRITE,
  40. 0,
  41. NULL,
  42. OPEN_EXISTING,
  43. 0,
  44. NULL
  45. );
  46. if (hFile == INVALID_HANDLE_VALUE) {
  47. goto exit;
  48. }
  49. FileSize = GetFileSize( hFile, NULL );
  50. if (FileSize == 0xffffffff) {
  51. goto exit;
  52. }
  53. hMap = CreateFileMapping(
  54. hFile,
  55. NULL,
  56. PAGE_READWRITE,
  57. 0,
  58. FileSize + 1024,
  59. NULL
  60. );
  61. if (!hMap) {
  62. goto exit;
  63. }
  64. fPtr = (LPSTR) MapViewOfFile(
  65. hMap,
  66. FILE_MAP_ALL_ACCESS,
  67. 0,
  68. 0,
  69. 0
  70. );
  71. if (!fPtr) {
  72. goto exit;
  73. }
  74. p = fPtr;
  75. while (p<fPtr+FileSize) {
  76. if (_strnicmp( p, HELP_INDEX_TAG, HELP_INDEX_TAG_LEN ) == 0) {
  77. p += HELP_INDEX_TAG_LEN;
  78. s = strchr( p, HELP_INDEX_SEP );
  79. if (s) {
  80. cmp = strncmp( p, FAX_HELP_TAG, s-p );
  81. if (cmp == 0) {
  82. //
  83. // fax help is already installed
  84. //
  85. goto exit;
  86. } else if (cmp > 0) {
  87. //
  88. // this is where we insert it
  89. //
  90. p -= HELP_INDEX_TAG_LEN;
  91. MoveMemory( p+FAX_HELP_STRING_LEN+CRLF_LEN, p, FileSize-(p-fPtr) );
  92. CopyMemory( p, FAX_HELP_STRING, FAX_HELP_STRING_LEN );
  93. p += FAX_HELP_STRING_LEN;
  94. CopyMemory( p, CRLF, CRLF_LEN );
  95. UnmapViewOfFile( fPtr );
  96. CloseHandle( hMap );
  97. fPtr = NULL;
  98. hMap = NULL;
  99. SetFilePointer( hFile, FileSize+FAX_HELP_STRING_LEN+CRLF_LEN, NULL, FILE_BEGIN );
  100. SetEndOfFile( hFile );
  101. break;
  102. }
  103. }
  104. }
  105. //
  106. // skip to the next line
  107. //
  108. while( *p != '\n' ) p++;
  109. p += 1;
  110. }
  111. ExpandEnvironmentStrings( TEXT("%windir%\\system32\\windows.gid"), Buffer, sizeof(Buffer) );
  112. MyDeleteFile( Buffer );
  113. ExpandEnvironmentStrings( TEXT("%windir%\\system32\\windows.fts"), Buffer, sizeof(Buffer) );
  114. MyDeleteFile( Buffer );
  115. ExpandEnvironmentStrings( TEXT("%windir%\\system32\\windows.ftg"), Buffer, sizeof(Buffer) );
  116. MyDeleteFile( Buffer );
  117. rVal = TRUE;
  118. exit:
  119. if (fPtr) {
  120. UnmapViewOfFile( fPtr );
  121. }
  122. if (hMap) {
  123. CloseHandle( hMap );
  124. }
  125. if (hFile) {
  126. CloseHandle( hFile );
  127. }
  128. return rVal;
  129. }