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.

213 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. spfontup.c
  5. Abstract:
  6. Code to handle upgrading fonts.
  7. Around build 1150 or so, fonts were moved from the system
  8. directory to the fonts directory to be compatible with win95.
  9. In Setup, we want to preserve the user's existing font situation
  10. (ie, only upgrade the fonts that he already had, etc) and at
  11. the same time layout.inf/txtsetup.sif needed to be changed to
  12. put/locate the font files in fonts instead of system.
  13. So what we do is 'precopy' all font files from the system dir
  14. to the fonts. Then when the rest of the upgrade runs, it does
  15. the usual thing (upgrading font files according to how they are
  16. marked for upgrade in txtsetup.sif).
  17. Later when GDI runs it will take care of cleaning up wierd references
  18. to fonts (lile .fots that points to .ttfs that were not in the
  19. system dir).
  20. Author:
  21. Ted Miller (tedm) 16-Oct-195
  22. Revision History:
  23. --*/
  24. #include "spprecmp.h"
  25. #pragma hdrstop
  26. BOOLEAN
  27. SpFontSystemDirEnumCallback(
  28. IN PCWSTR Directory,
  29. IN PFILE_BOTH_DIR_INFORMATION FileInfo,
  30. OUT PULONG ReturnData,
  31. IN PVOID Pointer
  32. )
  33. /*++
  34. Routine Description:
  35. This routine is called by the file enumerator as a callback for
  36. each file found in the system directory. We examine the file
  37. and if it's a font file, we copy it to the fonts directory.
  38. Arguments:
  39. Directory - supplies the full NT path to the system directory.
  40. FileInfo - supplies find data for a file in the system dir.
  41. ReturnData - receives an error code if an error occurs.
  42. We ignore errors in this routine and thus we always
  43. just fill this in with NO_ERROR.
  44. Pointer - An optional pointer. Not used in this function.
  45. Return Value:
  46. Always TRUE.
  47. --*/
  48. {
  49. ULONG Len;
  50. PWSTR temp,p;
  51. PWSTR SourceFilename,TargetFilename;
  52. NTSTATUS Status;
  53. ReturnData = NO_ERROR;
  54. ASSERT(NTUpgrade == UpgradeFull);
  55. if(NTUpgrade != UpgradeFull) {
  56. return(FALSE);
  57. }
  58. //
  59. // Ignore directories.
  60. //
  61. if(FileInfo->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  62. return(TRUE);
  63. }
  64. //
  65. // Break out the filename, which is not nul terminated
  66. // in the dir information structure.
  67. // Form the fully qualified source filename.
  68. //
  69. // Note how we use the temporary buffer. Be careful if you
  70. // change this code.
  71. //
  72. temp = TemporaryBuffer + (sizeof(TemporaryBuffer) / sizeof(WCHAR) / 2);
  73. Len = FileInfo->FileNameLength/sizeof(WCHAR);
  74. wcsncpy(temp,FileInfo->FileName,Len);
  75. temp[Len] = 0;
  76. wcscpy(TemporaryBuffer,Directory);
  77. SpConcatenatePaths(TemporaryBuffer,temp);
  78. SourceFilename = SpDupStringW(TemporaryBuffer);
  79. //
  80. // Check to see whether we care about this file.
  81. //
  82. if (SourceFilename) {
  83. temp = wcsrchr(SourceFilename,L'\\');
  84. } else {
  85. temp = NULL;
  86. }
  87. if(temp) {
  88. temp++;
  89. Len = wcslen(temp);
  90. } else {
  91. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_WARNING_LEVEL, "SETUP: That's strange: system dir font enum got file %ws\n",SourceFilename));
  92. return(TRUE);
  93. }
  94. //
  95. // At this point temp points at the filename part and len is its length.
  96. // See whether we care about this file.
  97. //
  98. if((Len > 4)
  99. && ( !_wcsicmp(temp+Len-4,L".ttf")
  100. || !_wcsicmp(temp+Len-4,L".fot")
  101. || !_wcsicmp(temp+Len-4,L".ttc")
  102. || !_wcsicmp(temp+Len-4,L".fon")
  103. || !_wcsicmp(temp+Len-4,L".jfr")))
  104. {
  105. //
  106. // Font file. Needs to be moved.
  107. // Locate the backslash just prior to SYSTEM in the source filename.
  108. //
  109. for(p=temp-2; (p>SourceFilename) && (*p != L'\\'); --p) {
  110. ;
  111. }
  112. if(p > SourceFilename) {
  113. *p = 0;
  114. wcscpy(TemporaryBuffer,SourceFilename);
  115. *p = L'\\';
  116. wcscat(TemporaryBuffer,L"\\FONTS\\");
  117. wcscat(TemporaryBuffer,temp);
  118. TargetFilename = SpDupStringW(TemporaryBuffer);
  119. SpDisplayStatusText(SP_STAT_FONT_UPGRADE,DEFAULT_STATUS_ATTRIBUTE,temp);
  120. //
  121. // Copy the file. Note that if it's one of our fonts,
  122. // it will get overwritten with the latest version anyway,
  123. // so we're not worried about whether the target file is
  124. // already there in the fonts directory and newer, etc.
  125. // Ignore errors.
  126. //
  127. Status = SpCopyFileUsingNames(SourceFilename,TargetFilename,0,COPY_DELETESOURCE);
  128. SpDisplayStatusText(SP_STAT_EXAMINING_CONFIG,DEFAULT_STATUS_ATTRIBUTE);
  129. SpMemFree(TargetFilename);
  130. } else {
  131. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_WARNING_LEVEL, "SETUP: That's strange: system dir font enum got file %ws\n",SourceFilename));
  132. }
  133. }
  134. SpMemFree(SourceFilename);
  135. return(TRUE);
  136. }
  137. VOID
  138. SpPrepareFontsForUpgrade(
  139. IN PCWSTR SystemDirectory
  140. )
  141. /*++
  142. Routine Description:
  143. Prepares the system to upgrade fonts by copying all font files
  144. that are in the system directory into the fonts directory.
  145. Note: this routine should only be called in the upgrade case.
  146. Arguments:
  147. Return Value:
  148. Always TRUE.
  149. --*/
  150. {
  151. ULONG x;
  152. ASSERT(NTUpgrade == UpgradeFull);
  153. if(NTUpgrade != UpgradeFull) {
  154. return;
  155. }
  156. SpDisplayStatusText(SP_STAT_EXAMINING_CONFIG,DEFAULT_STATUS_ATTRIBUTE);
  157. SpEnumFiles(SystemDirectory,SpFontSystemDirEnumCallback,&x, NULL);
  158. }