Windows NT 4.0 source code leak
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.

228 lines
4.8 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. bkhlpfil.c
  5. Abstract:
  6. Routines to manipulate help files and help file names.
  7. Author:
  8. Ted Miller (tedm) 5-Jan-1995
  9. Revision History:
  10. --*/
  11. #include "books.h"
  12. //
  13. // Fixed name of the help file. This is dependent on whether
  14. // this is server or workstation and is set in FixupNames().
  15. //
  16. PWSTR HelpFileName;
  17. //
  18. // Path on CD-ROM where online books files are located.
  19. // We "just know" this value.
  20. //
  21. PWSTR PathOfBooksFilesOnCd = L"\\SUPPORT\\BOOKS";
  22. VOID
  23. FormHelpfilePaths(
  24. IN WCHAR Drive, OPTIONAL
  25. IN PWSTR Path,
  26. IN PWSTR FilenamePrepend, OPTIONAL
  27. OUT PWSTR Filename,
  28. OUT PWSTR Directory OPTIONAL
  29. )
  30. /*++
  31. Routine Description:
  32. Form the full pathname of the main online books help file
  33. and of the directory containing the help file (ie, the pathname
  34. of the help file without the filename part).
  35. The filename part of the name is determined by the server/workstation
  36. setting and is fixed.
  37. Arguments:
  38. Drive - if specified, supplies the drive letter of the drive
  39. on which the help file is located. If not specified, the
  40. file is assumed to be on a UNC or other path as described
  41. by Path.
  42. Path - supplies the path component of the location of the
  43. help file name. This can be relative to a drive (if Drive is specified)
  44. of a complete path component (Drive is not specified).
  45. FilenamePrepend - if specified, supplies a string to be prepended
  46. to the generated full pathname of the helpfile. This is useful
  47. when generating command lines.
  48. Filename - receives the full pathname of the help file. The caller must
  49. ensure that the buffer is large enough.
  50. Directory - if specified, receives the full path of the directory
  51. in which the helpfile is located. The caller must ensure that the
  52. buffer is large enough.
  53. Return Value:
  54. None.
  55. --*/
  56. {
  57. if(Drive) {
  58. wsprintf(
  59. Filename,
  60. L"%s%c:%s\\%s",
  61. FilenamePrepend ? FilenamePrepend : L"",
  62. Drive,
  63. Path,
  64. HelpFileName
  65. );
  66. if(Directory) {
  67. wsprintf(Directory,L"%c:%s",Drive,Path);
  68. }
  69. } else {
  70. wsprintf(
  71. Filename,
  72. L"%s%s\\%s",
  73. FilenamePrepend ? FilenamePrepend : L"",
  74. Path,
  75. HelpFileName
  76. );
  77. if(Directory) {
  78. lstrcpy(Directory,Path);
  79. }
  80. }
  81. }
  82. BOOL
  83. CheckHelpfilePresent(
  84. IN PWSTR Path
  85. )
  86. /*++
  87. Routine Description:
  88. Determine if the relevent helpfile (a fixed name depending on
  89. whether this is workstation or server) is accessible.
  90. Arguments:
  91. Path - supplies the path to the helpfile (a full path that does not
  92. include the filename part and should not end with a backslash).
  93. Return Value:
  94. Boolean value indicating whether the file is accessible.
  95. --*/
  96. {
  97. WCHAR Filename[MAX_PATH];
  98. FormHelpfilePaths(0,Path,NULL,Filename,NULL);
  99. return DoesFileExist(Filename);
  100. }
  101. VOID
  102. FireUpWinhelp(
  103. IN WCHAR Drive, OPTIONAL
  104. IN PWSTR Path
  105. )
  106. /*++
  107. Routine Description:
  108. Invoke winhlp32.exe on the relevent online books helpfile.
  109. This routine also stores the helpfile location in the
  110. application profile if winhlp32 could be successfully executed.
  111. Arguments:
  112. Drive - if specified, supplies the drive letter of the drive
  113. on which the help file is located. If not specified, the
  114. file is assumed to be on a UNC or other path as described
  115. by Path.
  116. Path - supplies the path component of the location of the
  117. help file name. This can be relative to a drive (if Drive is specified)
  118. of a complete path component (Drive is not specified).
  119. Return Value:
  120. None. If winhlp32 cannot be started a fatal error is generated
  121. and this routine does not return to its caller.
  122. --*/
  123. {
  124. WCHAR CommandLine[MAX_PATH];
  125. WCHAR CurrentDirectory[MAX_PATH];
  126. BOOL b;
  127. STARTUPINFO StartInfo;
  128. PROCESS_INFORMATION ProcInfo;
  129. FormHelpfilePaths(
  130. Drive,
  131. Path,
  132. L"winhlp32 ",
  133. CommandLine,
  134. CurrentDirectory
  135. );
  136. ZeroMemory(&StartInfo,sizeof(StartInfo));
  137. StartInfo.cb = sizeof(STARTUPINFO);
  138. b = CreateProcess(
  139. NULL,
  140. CommandLine,
  141. NULL,
  142. NULL,
  143. FALSE,
  144. 0,
  145. NULL,
  146. CurrentDirectory,
  147. &StartInfo,
  148. &ProcInfo
  149. );
  150. if(b) {
  151. CloseHandle(ProcInfo.hThread);
  152. CloseHandle(ProcInfo.hProcess);
  153. //
  154. // Remember the location of the help file.
  155. //
  156. MySetProfileValue(BooksProfileLocation,CurrentDirectory);
  157. return;
  158. } else {
  159. MyError(NULL,IDS_CANT_START_WINHELP,TRUE);
  160. }
  161. }