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.

176 lines
5.2 KiB

  1. //
  2. // ParseInf.h
  3. //
  4. // Code that parses network INF files
  5. //
  6. #pragma once
  7. #ifndef _FAUXMFC
  8. #pragma message("error --- The Millennium depgen can't deal with this")
  9. //#include <afxtempl.h>
  10. #endif
  11. #include "SortStr.h"
  12. #include "NetConn.h"
  13. #include <pshpack1.h>
  14. struct INF_LAYOUT_FILE
  15. {
  16. DWORD dwNameOffset; // byte offset of filename from beginning of string data
  17. BYTE iDisk; // disk number within layout
  18. BYTE iLayout; // layout file number
  19. };
  20. #include <poppack.h>
  21. struct SOURCE_DISK_INFO
  22. {
  23. WORD wDiskID; // loword = disk number, hiword = layout file number
  24. CString strCabFile;
  25. CString strDescription;
  26. };
  27. struct DRIVER_FILE_INFO
  28. {
  29. BYTE nTargetDir; // LDID_* value for target directory, e.g. LDID_WIN
  30. CHAR szFileTitle[1]; // file name, followed by target subdirectory
  31. };
  32. #define MAKE_DISK_ID(iDiskNumber, iLayoutFile) MAKEWORD(iDiskNumber, iLayoutFile)
  33. typedef CTypedPtrArray<CPtrArray, SOURCE_DISK_INFO*> CSourceDiskArray;
  34. //typedef CTypedPtrArray<CPtrArray, DRIVER_FILE_INFO*> CDriverFileArray;
  35. class CDriverFileArray : public CTypedPtrArray<CPtrArray, DRIVER_FILE_INFO*>
  36. {
  37. public:
  38. ~CDriverFileArray();
  39. };
  40. //////////////////////////////////////////////////////////////////////////////
  41. // Utility functions
  42. int GetFullInfPath(LPCTSTR pszPartialPath, LPTSTR pszBuf, int cchBuf);
  43. BOOL ModifyInf_NoVersionConflict(LPCTSTR pszInfFile);
  44. BOOL ModifyInf_NoCopyFiles(LPCTSTR pszInfFile);
  45. BOOL ModifyInf_RequireExclude(LPCTSTR pszInfFile, LPCTSTR pszRequire, LPCTSTR pszExclude);
  46. BOOL ModifyInf_NoCopyAndRequireExclude(LPCTSTR pszInfFile, LPCTSTR pszRequire, LPCTSTR pszExclude);
  47. BOOL RestoreInfBackup(LPCTSTR pszInfFile);
  48. BOOL GetDeviceCopyFiles(LPCTSTR pszInfFileName, LPCTSTR pszDeviceID, CDriverFileArray& rgDriverFiles);
  49. int GetStandardTargetPath(int iDirNumber, LPCTSTR pszTargetSubDir, LPTSTR pszBuf);
  50. int GetDriverTargetPath(const DRIVER_FILE_INFO* pFileInfo, LPTSTR pszBuf);
  51. BOOL CheckInfSectionInstallation(LPCTSTR pszInfFile, LPCTSTR pszInfSection);
  52. BOOL InstallInfSection(LPCTSTR pszInfFile, LPCTSTR pszInfSection, BOOL bWait);
  53. //////////////////////////////////////////////////////////////////////////////
  54. class CInfParser
  55. {
  56. public:
  57. CInfParser();
  58. ~CInfParser();
  59. BOOL LoadInfFile(LPCTSTR pszInfFile, LPCTSTR pszSeparators = ",;=");
  60. BOOL Rewind();
  61. BOOL GotoNextLine();
  62. BOOL GetToken(CString& strTok);
  63. BOOL GetLineTokens(CStringArray& sa);
  64. BOOL GetSectionLineTokens(CStringArray& sa);
  65. BOOL GotoSection(LPCTSTR pszSection);
  66. int GetProfileInt(LPCTSTR pszSection, LPCSTR pszKey, int nDefault = 0);
  67. BOOL GetDestinationDir(LPCTSTR pszSectionName, BYTE* pbDirNumber, LPTSTR pszSubDir, UINT cchSubDir);
  68. BOOL GetFilesFromInstallSection(LPCTSTR pszSection, CDriverFileArray& rgAllFiles);
  69. void GetFilesFromCopyFilesSections(const CStringArray& rgCopyFiles, CDriverFileArray& rgAllFiles);
  70. int GetNextSourceFile(LPTSTR pszBuf, BYTE* pDiskNumber);
  71. void ReadSourceFilesSection(INF_LAYOUT_FILE* prgFiles, int cFiles);
  72. void ScanSourceFileList(int* pcFiles, int* pcchAllFileNames);
  73. void AddLayoutFiles(LPCTSTR pszInfFile, CInfParser& parser);
  74. CString m_strFileName;
  75. protected:
  76. LPTSTR m_pszFileData;
  77. DWORD m_cbFile;
  78. DWORD m_iPos;
  79. CString m_strSeparators;
  80. CString m_strExtSeparators;
  81. };
  82. class CInfLayoutFiles
  83. {
  84. public:
  85. CInfLayoutFiles();
  86. ~CInfLayoutFiles();
  87. BOOL Add(LPCTSTR pszInfFile, BOOL bLayoutFile = FALSE);
  88. BOOL Add(CInfParser& parser, BOOL bLayoutFile = FALSE);
  89. void Sort();
  90. SOURCE_DISK_INFO* FindDriverFileSourceDisk(LPCTSTR pszDriverFileTitle);
  91. #ifdef _DEBUG
  92. void Dump();
  93. #endif
  94. protected:
  95. static int __cdecl CompareInfLayoutFiles(const void* pEl1, const void* pEl2);
  96. static LPTSTR s_pStringData;
  97. protected:
  98. INF_LAYOUT_FILE* m_prgFiles;
  99. LPTSTR m_pStringData;
  100. int m_cFiles;
  101. int m_cbStringData;
  102. CSortedStringArray m_rgLayoutFileNames;
  103. // List of source disks generated from all layout files
  104. CSourceDiskArray m_rgSourceDisks;
  105. #ifdef _DEBUG
  106. BOOL m_bSorted;
  107. #endif
  108. };
  109. class CInfFileList
  110. {
  111. public:
  112. CInfFileList();
  113. ~CInfFileList();
  114. BOOL AddBaseFiles(LPCTSTR pszInfFile);
  115. BOOL AddDeviceFiles(LPCTSTR pszInfFile, LPCTSTR pszDeviceID);
  116. int BuildSourceFileList();
  117. void SetDriverSourceDir(LPCTSTR pszSourceDir);
  118. BOOL FindWindowsCD(HWND hwndParent);
  119. BOOL CopySourceFiles(HWND hwndParent, LPCTSTR pszDestDir, PROGRESS_CALLBACK pfnProgress, LPVOID pvProgressParam);
  120. protected:
  121. BOOL CheckWindowsCD(LPCTSTR pszDirectory);
  122. BOOL PromptWindowsCD(HWND hwndParent, LPCTSTR pszInitialDir, LPTSTR pszResultDir);
  123. protected:
  124. // List of all files listed in [SourceDisksFiles] of all INFs and related layouts
  125. CInfLayoutFiles m_rgLayoutFiles;
  126. // List of all files that are required for the device to function
  127. CDriverFileArray m_rgDriverFiles;
  128. // Files that need to be present for windows installer to complete installation
  129. CSortedStringArray m_rgCabFiles; // cab files from Windows CD
  130. CSortedStringArray m_rgSourceFiles; // source files needed from driver dir
  131. // Where we'll look first for system files, before prompting user for Windows CD
  132. CString m_strDriverSourceDir;
  133. // Where we look for Windows files
  134. CString m_strWindowsCD;
  135. };