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.

221 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998 - 1998.
  5. //
  6. // File: section.hxx
  7. //
  8. // Contents: CSection definition
  9. //
  10. // Classes: CSection
  11. //
  12. // Functions:
  13. //
  14. // History: 22-Sep-99 PhilipLa Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __SECTION_HXX__
  18. #define __SECTION_HXX__
  19. #include "filelist.hxx"
  20. class CSection
  21. {
  22. public:
  23. inline CSection();
  24. inline ~CSection();
  25. inline const TCHAR * GetSectionTitle(void) const;
  26. inline DWORD SetSectionTitle(const TCHAR *ptsName);
  27. inline const TCHAR * GetSectionPath(void) const;
  28. inline DWORD SetSectionPath(const TCHAR *ptsName);
  29. inline DWORD GetSectionPathLength(void) const;
  30. inline const TCHAR * GetSectionDest(void) const;
  31. inline DWORD SetSectionDest(const TCHAR *ptsDest);
  32. inline DWORD GetSectionDestLength(void) const;
  33. inline DWORD SetName(const TCHAR *ptsName,
  34. DWORD *pdwIndex,
  35. BOOL fDeconstruct);
  36. inline DWORD SetDestination(const TCHAR *ptsName, DWORD dwIndex);
  37. inline ULONG GetNameCount(void) const;
  38. inline const TCHAR * GetFullFileName(ULONG i) const;
  39. inline const TCHAR * GetDestination(ULONG i) const;
  40. inline void AddToList(CSection *pcsSection);
  41. inline CSection * GetNextSection(void) const;
  42. private:
  43. TCHAR _tsSectionName[MAX_PATH + 1];
  44. TCHAR _tsSectionPath[MAX_PATH + 1];
  45. DWORD _dwSectionPathLength;
  46. TCHAR _tsSectionDest[MAX_PATH + 1];
  47. DWORD _dwSectionDestLength;
  48. CFileList _cfl;
  49. CSection *_pcsNext;
  50. };
  51. inline CSection::CSection()
  52. {
  53. _tsSectionName[0] = 0;
  54. _tsSectionPath[0] = 0;
  55. _tsSectionDest[0] = 0;
  56. _dwSectionPathLength = 0;
  57. _dwSectionDestLength = 0;
  58. _pcsNext = NULL;
  59. }
  60. inline CSection::~CSection()
  61. {
  62. FreeFileList(_cfl.GetNextFileList());
  63. }
  64. inline const TCHAR * CSection::GetSectionTitle(void) const
  65. {
  66. return _tsSectionName;
  67. }
  68. inline DWORD CSection::SetSectionTitle(const TCHAR *ptsName)
  69. {
  70. DWORD dwLen = _tcslen(ptsName);
  71. if (dwLen > MAX_PATH)
  72. {
  73. if (DebugOutput)
  74. Win32Printf(LogFile, "Error: ptsName too long %s\r\n", ptsName);
  75. return ERROR_FILENAME_EXCED_RANGE;
  76. }
  77. _tcscpy(_tsSectionName, ptsName);
  78. //Go through some additional trickery to remove trailing backslashes,
  79. //since the output .inf file uses a backslash as a line continuation
  80. //character
  81. if (_tsSectionName[dwLen - 1] == TEXT('\\'))
  82. {
  83. _tsSectionName[dwLen - 1] = 0;
  84. }
  85. return ERROR_SUCCESS;
  86. }
  87. inline const TCHAR * CSection::GetSectionPath(void) const
  88. {
  89. return _tsSectionPath;
  90. }
  91. inline DWORD CSection::SetSectionPath(const TCHAR *ptsName)
  92. {
  93. DWORD dwLen = _tcslen(ptsName);
  94. if (dwLen > MAX_PATH)
  95. {
  96. if (DebugOutput)
  97. Win32Printf(LogFile, "Error: ptsName too long %s\r\n", ptsName);
  98. return ERROR_FILENAME_EXCED_RANGE;
  99. }
  100. _tcscpy(_tsSectionPath, ptsName);
  101. _dwSectionPathLength = _tcslen(_tsSectionPath);
  102. if (_tsSectionPath[_dwSectionPathLength - 1] == TEXT('\\'))
  103. {
  104. _tsSectionPath[_dwSectionPathLength - 1] = 0;
  105. _dwSectionPathLength--;
  106. }
  107. return ERROR_SUCCESS;
  108. }
  109. inline DWORD CSection::GetSectionPathLength(void) const
  110. {
  111. return _dwSectionPathLength;
  112. }
  113. inline const TCHAR * CSection::GetSectionDest(void) const
  114. {
  115. return _tsSectionDest;
  116. }
  117. inline DWORD CSection::SetSectionDest(const TCHAR *ptsName)
  118. {
  119. DWORD dwLen = _tcslen(ptsName);
  120. if (dwLen > MAX_PATH)
  121. {
  122. if (DebugOutput)
  123. Win32Printf(LogFile, "Error: ptsName too long %s\r\n", ptsName);
  124. return ERROR_FILENAME_EXCED_RANGE;
  125. }
  126. _tcscpy(_tsSectionDest, ptsName);
  127. _dwSectionDestLength = _tcslen(_tsSectionDest);
  128. if (_tsSectionDest[_dwSectionDestLength - 1] == TEXT('\\'))
  129. {
  130. _tsSectionDest[_dwSectionDestLength - 1] = 0;
  131. _dwSectionDestLength--;
  132. }
  133. return ERROR_SUCCESS;
  134. }
  135. inline DWORD CSection::GetSectionDestLength(void) const
  136. {
  137. return _dwSectionDestLength;
  138. }
  139. inline DWORD CSection::SetName(const TCHAR *ptsName,
  140. DWORD *pdwIndex,
  141. BOOL fDeconstruct)
  142. {
  143. return _cfl.SetName(ptsName, pdwIndex, fDeconstruct);
  144. }
  145. inline DWORD CSection::SetDestination(const TCHAR *ptsName, DWORD dwIndex)
  146. {
  147. return _cfl.SetDestination(ptsName, dwIndex);
  148. }
  149. inline ULONG CSection::GetNameCount(void) const
  150. {
  151. return _cfl.GetNameCount();
  152. }
  153. inline const TCHAR * CSection::GetFullFileName(ULONG i) const
  154. {
  155. return _cfl.GetFullName(i);
  156. }
  157. inline const TCHAR * CSection::GetDestination(ULONG i) const
  158. {
  159. return _cfl.GetDestination(i);
  160. }
  161. inline void CSection::AddToList(CSection *pcsNew)
  162. {
  163. CSection *pcs = this;
  164. while (pcs->_pcsNext != NULL)
  165. {
  166. pcs = pcs->_pcsNext;
  167. }
  168. pcs->_pcsNext = pcsNew;
  169. }
  170. inline CSection * CSection::GetNextSection(void) const
  171. {
  172. return _pcsNext;
  173. }
  174. inline void FreeSectionList(CSection *pcs)
  175. {
  176. CSection *pcsNext;
  177. while (pcs != NULL)
  178. {
  179. pcsNext = pcs->GetNextSection();
  180. delete pcs;
  181. pcs = pcsNext;
  182. }
  183. }
  184. #endif // #ifndef __SECTION_HXX__