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.

160 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. file.h
  5. Abstract:
  6. Contains the input file abstraction
  7. Author:
  8. Mike Cirello
  9. Vijay Jayaseelan (vijayj)
  10. Revision History:
  11. 03 March 2001 :
  12. Rewamp the whole source to make it more maintainable
  13. (particularly readable)
  14. --*/
  15. #pragma once
  16. #include "BuildHive.h"
  17. #include "RegWriter.h"
  18. #include <setupapi.hpp>
  19. #include <io.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include "msg.h"
  23. #include <libmsg.h>
  24. using namespace std;
  25. //
  26. // Registry Mapper
  27. //
  28. class RegistryMapper {
  29. public:
  30. //
  31. // member functions
  32. //
  33. void AddEntry(const std::wstring &Key, const std::wstring &Value);
  34. void AddSection(Section<WCHAR> &MapSection);
  35. bool GetMappedRegistry(const std::wstring &Key, std::wstring &Registry);
  36. static void AddWorker(SectionValues<WCHAR> &Values, PVOID ContextData);
  37. friend std::ostream& operator<<(std::ostream& os, RegistryMapper &rhs);
  38. protected:
  39. //
  40. // data members
  41. //
  42. std::map< std::wstring, std::wstring > KeyToRegistryMap;
  43. };
  44. //
  45. // Input file abstraction
  46. //
  47. class File {
  48. public:
  49. //
  50. // constructor & destructor
  51. //
  52. File(PCTSTR pszTargetFile, bool bModify);
  53. virtual ~File();
  54. //
  55. // member functions
  56. //
  57. void AddInfSection(PCTSTR fileName, PCTSTR section, PCTSTR action, bool Prepend = false);
  58. void ProcessNlsRegistryEntries(void);
  59. DWORD ProcessSections();
  60. static DWORD SaveAll();
  61. DWORD Cleanup();
  62. //
  63. // inline methods
  64. //
  65. RegWriter& GetRegWriter() { return regWriter; }
  66. PCTSTR GetTarget() { return targetFile.c_str(); }
  67. RegistryMapper* SetRegistryMapper(RegistryMapper *RegMapper) {
  68. RegistryMapper *OldMapper = CurrentRegMapper;
  69. CurrentRegMapper = RegMapper;
  70. return OldMapper;
  71. }
  72. RegistryMapper* GetRegistryMapper() { return CurrentRegMapper; }
  73. private:
  74. //
  75. // data members
  76. //
  77. wstring targetFile;
  78. bool modify;
  79. int luid;
  80. TCHAR wKey[1024];
  81. StringList infList;
  82. HandleList handleList;
  83. HINF hFile;
  84. SP_INF_INFORMATION infInfo;
  85. RegWriter regWriter;
  86. RegistryMapper *CurrentRegMapper;
  87. //
  88. // static data
  89. //
  90. static TCHAR targetDirectory[1024];
  91. static FileList files;
  92. static int ctr;
  93. //
  94. // methods
  95. //
  96. File* GetFile(PCTSTR fileName,bool modify);
  97. DWORD AddRegNew(PCTSTR section,HINF h);
  98. DWORD AddRegExisting(PCTSTR section,HINF h);
  99. DWORD DelRegExisting(PCTSTR section,HINF h);
  100. DWORD AddSection(PCTSTR pszSection,HINF hInfFile);
  101. DWORD DelSection(PCTSTR SectionName, HINF InfHandle);
  102. DWORD SetDirectory(PCTSTR pszSection,HINF hInfFile);
  103. DWORD GetFlags(PCTSTR buffer);
  104. void ProcessNlsRegistryEntriesForSection(InfFileW &ConfigInf, InfFileW &IntlInf,
  105. InfFileW &FontInf,const std::wstring &SectionName);
  106. void ProcessNlsRegistryEntriesForLanguage(InfFileW &ConfigInf, InfFileW &IntlInf,
  107. InfFileW &FontInf,const std::wstring &Language);
  108. void ProcessNlsRegistryEntriesForLangGroup(InfFileW &ConfigInf, InfFileW &IntlInf,
  109. InfFileW &FontInf,const std::wstring &LanguageGroup);
  110. };
  111. //
  112. // Determines if the given file (or directory) is present
  113. //
  114. template <class T>
  115. bool
  116. IsFilePresent(const std::basic_string<T> &FileName) {
  117. bool Result = false;
  118. if (sizeof(T) == sizeof(CHAR)) {
  119. Result = (::_access((PCSTR)FileName.c_str(), 0) == 0);
  120. } else {
  121. Result = (::_waccess((PCWSTR)FileName.c_str(), 0) == 0);
  122. }
  123. return Result;
  124. }