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.

258 lines
6.9 KiB

  1. #pragma once
  2. extern const wstring ASM_NAMESPACE_URI;
  3. #define AWFUL_SPACE_HACK TRUE
  4. #include "msxml2.h"
  5. typedef ::ATL::CComPtr<MSXML2::IXMLDOMDocument2> ISXSManifestPtr;
  6. extern ::ATL::CComPtr<IClassFactory> g_XmlDomClassFactory;
  7. class CPostbuildProcessListEntry
  8. {
  9. private:
  10. wstring manifestFullPath;
  11. wstring manifestFileName;
  12. wstring manifestPathOnly;
  13. public:
  14. wstring version;
  15. wstring name;
  16. wstring language;
  17. ISXSManifestPtr DocumentPointer;
  18. wstring getManifestFullPath() const { return manifestFullPath; }
  19. wstring getManifestFileName() const { return manifestFileName; }
  20. wstring getManifestPathOnly() const { return manifestPathOnly; }
  21. void setManifestLocation( wstring root, wstring where );
  22. bool operator==(const CPostbuildProcessListEntry& right) const
  23. {
  24. return !(*this < right) && !(right < *this);
  25. }
  26. static bool wstringPointerLessThan(const std::wstring* x, const std::wstring* y)
  27. {
  28. return x->compare(*y) < 0;
  29. }
  30. bool operator<(const CPostbuildProcessListEntry& right) const
  31. {
  32. // the order is arbitrary,
  33. const std::wstring* leftwstrings[] =
  34. { &this->name, &this->version, &this->language, &this->manifestFullPath, &this->manifestFileName, &this->manifestPathOnly };
  35. const std::wstring* rightwstrings[] =
  36. { &right.name, &right.version, &right.language, &right.manifestFullPath, &right.manifestFileName, &right.manifestPathOnly };
  37. return std::lexicographical_compare(
  38. leftwstrings, leftwstrings + NUMBER_OF(leftwstrings),
  39. rightwstrings, rightwstrings + NUMBER_OF(rightwstrings),
  40. wstringPointerLessThan
  41. );
  42. }
  43. friend wostream& operator<<(wostream& ost, const CPostbuildProcessListEntry& thing );
  44. };
  45. class CSimpleIdentity {
  46. public:
  47. wstring wsVersion;
  48. wstring wsName;
  49. wstring wsLanguage;
  50. wstring wsProcessorArchitecture;
  51. wstring wsType;
  52. wstring wsPublicKeyToken;
  53. wstring wsManifestPath;
  54. class CUnknownIdentityThing {
  55. public:
  56. wstring wsNamespace;
  57. wstring wsName;
  58. wstring wsValue;
  59. CUnknownIdentityThing(wstring& a, wstring &b, wstring &c)
  60. : wsNamespace(a), wsName(b), wsValue(c) {
  61. }
  62. };
  63. CSimpleIdentity() { wsLanguage = wsProcessorArchitecture = L"*"; }
  64. std::vector<CUnknownIdentityThing> OtherValues;
  65. };
  66. class CParameters {
  67. public:
  68. bool m_fVerbose;
  69. bool m_fNoLogo;
  70. bool m_fUpdateHash;
  71. bool m_fCreateCdfs;
  72. bool m_fUsage;
  73. bool m_fDuringRazzle;
  74. bool m_fSingleItem;
  75. bool m_fCreateNewAssembly;
  76. wstring m_BinplaceLog;
  77. wstring m_CdfOutputPath;
  78. wstring m_AsmsRoot;
  79. CSimpleIdentity m_SingleEntry;
  80. CPostbuildProcessListEntry m_SinglePostbuildItem;
  81. std::vector<CSimpleIdentity> m_InjectDependencies;
  82. enum SetParametersResult {
  83. eCommandLine_nologo,
  84. eCommandLine_usage,
  85. eCommandLine_normal
  86. };
  87. CParameters();
  88. SetParametersResult SetComandLine(UINT uiParameters, WCHAR** wszParameters);
  89. private:
  90. std::vector<wstring> m_Parameters;
  91. bool ParseDependentString(const wstring& ws, CSimpleIdentity &target);
  92. bool ChunkifyParameters(UINT uiParameters, WCHAR **pwszParameters);
  93. };
  94. extern CParameters g_GlobalParameters;
  95. HRESULT
  96. SxspSimplifyGetAttribute(
  97. ::ATL::CComPtr<IXMLDOMNamedNodeMap> Attributes,
  98. wstring bstAttribName,
  99. wstring &bstDestination,
  100. wstring bstNamespaceURI = ASM_NAMESPACE_URI
  101. );
  102. HRESULT
  103. SxspSimplifyPutAttribute(
  104. ISXSManifestPtr Document,
  105. ::ATL::CComPtr<IXMLDOMNamedNodeMap> Attributes,
  106. const wstring bstAttribName,
  107. const wstring bstValue,
  108. const wstring bstNamespaceURI = ASM_NAMESPACE_URI
  109. );
  110. HRESULT
  111. SxspExtractPathPieces(
  112. _bstr_t bstSourceName,
  113. _bstr_t &bstPath,
  114. _bstr_t &bstName
  115. );
  116. HRESULT
  117. CreateDocumentNode(
  118. VARIANT vt,
  119. _bstr_t bstAttribName,
  120. _bstr_t bstNamespace,
  121. IXMLDOMNode **pNewNode
  122. );
  123. HRESULT
  124. ConstructXMLDOMObject(
  125. wstring SourceName,
  126. ISXSManifestPtr &result
  127. );
  128. enum ErrorLevel
  129. {
  130. ErrorFatal,
  131. ErrorWarning,
  132. ErrorSpew
  133. };
  134. inline void ReportError( ErrorLevel el, std::wstringstream& message )
  135. {
  136. if ((el == ErrorSpew) && g_GlobalParameters.m_fVerbose)
  137. {
  138. wcout << wstring(L"SPEW: ") << message.str() << endl;
  139. }
  140. else
  141. {
  142. if (el == ErrorWarning)
  143. {
  144. wcout << wstring(L"WARNING: ");
  145. }
  146. else
  147. {
  148. wcout << wstring(L"ERROR: ");
  149. }
  150. wcout << message.str() << endl;
  151. }
  152. }
  153. typedef vector<CPostbuildProcessListEntry> CPostbuildItemVector;
  154. extern CPostbuildItemVector PostbuildEntries;
  155. class CFileStreamBase : public IStream
  156. {
  157. public:
  158. CFileStreamBase()
  159. : m_cRef(0),
  160. m_hFile(INVALID_HANDLE_VALUE),
  161. m_bSeenFirstCharacter(false)
  162. { }
  163. virtual ~CFileStreamBase();
  164. bool OpenForRead( wstring pszPath );
  165. bool OpenForWrite( wstring pszPath );
  166. bool Close();
  167. // IUnknown methods:
  168. STDMETHODIMP_(ULONG) AddRef();
  169. STDMETHODIMP_(ULONG) Release();
  170. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  171. // ISequentialStream methods:
  172. STDMETHODIMP Read(void *pv, ULONG cb, ULONG *pcbRead);
  173. STDMETHODIMP Write(void const *pv, ULONG cb, ULONG *pcbWritten);
  174. // IStream methods:
  175. STDMETHODIMP Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
  176. STDMETHODIMP SetSize(ULARGE_INTEGER libNewSize);
  177. STDMETHODIMP CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten);
  178. STDMETHODIMP Commit(DWORD grfCommitFlags);
  179. STDMETHODIMP Revert();
  180. STDMETHODIMP LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  181. STDMETHODIMP UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  182. STDMETHODIMP Stat(STATSTG *pstatstg, DWORD grfStatFlag);
  183. STDMETHODIMP Clone(IStream **ppIStream);
  184. protected:
  185. LONG m_cRef;
  186. HANDLE m_hFile;
  187. bool m_bSeenFirstCharacter;
  188. private:
  189. CFileStreamBase(const CFileStreamBase &r); // intentionally not implemented
  190. CFileStreamBase &operator =(const CFileStreamBase &r); // intentionally not implemented
  191. };
  192. typedef std::map<wstring, wstring> StringStringMap;
  193. typedef std::map<wstring, wstring> StringStringPair;
  194. typedef wstring InvalidEquivalence;
  195. StringStringMap MapFromDefLine( const wstring& source, wchar_t wchBreakValue = L' ' );
  196. wstring JustifyPath( const wstring& path );
  197. std::string ConvertWString(const wstring& src);
  198. std::wstring ConvertString(const std::string& src);
  199. HRESULT UglifyXmlDocument(ISXSManifestPtr DocumentPtr);
  200. HRESULT PrettyFormatXmlDocument(ISXSManifestPtr DocumentPtr);