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.

307 lines
7.3 KiB

  1. #include "stdinc.h"
  2. HRESULT
  3. SxspExtractPathPieces(
  4. _bstr_t bstSourceName,
  5. _bstr_t &bstPath,
  6. _bstr_t &bstName
  7. )
  8. {
  9. HRESULT hr = S_OK;
  10. PCWSTR cwsOriginal = static_cast<PCWSTR>(bstSourceName);
  11. PWSTR cwsSlashSpot;
  12. cwsSlashSpot = wcsrchr( cwsOriginal, L'\\' );
  13. if ( cwsSlashSpot )
  14. {
  15. *cwsSlashSpot = L'\0';
  16. bstName = _bstr_t( cwsSlashSpot + 1 );
  17. bstPath = cwsSlashSpot;
  18. }
  19. else
  20. {
  21. bstPath = L"";
  22. bstName = bstSourceName;
  23. }
  24. return hr;
  25. }
  26. HRESULT
  27. SxspSimplifyPutAttribute(
  28. ATL::CComPtr<IXMLDOMDocument> Document,
  29. ATL::CComPtr<IXMLDOMNamedNodeMap> Attributes,
  30. const string AttribName,
  31. const string Value,
  32. const string NamespaceURI
  33. )
  34. {
  35. ATL::CComPtr<IXMLDOMNode> pAttribNode;
  36. ATL::CComPtr<IXMLDOMAttribute> pAttribActual;
  37. ATL::CComPtr<IXMLDOMNode> pTempNode;
  38. HRESULT hr;
  39. //
  40. // Get the attribute from our namespace
  41. //
  42. hr = Attributes->getQualifiedItem(
  43. _bstr_t(AttribName.c_str()),
  44. _bstr_t(NamespaceURI.c_str()),
  45. &pAttribNode);
  46. if ( SUCCEEDED( hr ) )
  47. {
  48. //
  49. // If we had success, but the attribute node is null, then we have to
  50. // go create one, which is tricky.
  51. //
  52. if ( pAttribNode == NULL )
  53. {
  54. VARIANT vt;
  55. vt.vt = VT_INT;
  56. vt.intVal = NODE_ATTRIBUTE;
  57. //
  58. // Do the actual creation part
  59. //
  60. hr = Document->createNode(
  61. vt,
  62. _bstr_t(AttribName.c_str()),
  63. _bstr_t(NamespaceURI.c_str()),
  64. &pTempNode);
  65. if ( FAILED( hr ) )
  66. {
  67. stringstream ss;
  68. ss << "Can't create the new attribute node " << AttribName;
  69. ReportError( ErrorFatal, ss );
  70. goto lblGetOut;
  71. }
  72. //
  73. // Now we go and put that item into the map.
  74. //
  75. if ( FAILED( hr = Attributes->setNamedItem( pTempNode, &pAttribNode ) ) )
  76. goto lblGetOut;
  77. }
  78. hr = pAttribNode->put_text( _bstr_t(Value.c_str()) );
  79. }
  80. lblGetOut:
  81. // SAFERELEASE( pAttribNode );
  82. // SAFERELEASE( pTempNode );
  83. return hr;
  84. }
  85. HRESULT
  86. SxspSimplifyGetAttribute(
  87. ATL::CComPtr<IXMLDOMNamedNodeMap> Attributes,
  88. string AttribName,
  89. string &Destination,
  90. string NamespaceURI
  91. )
  92. {
  93. ATL::CComPtr<IXMLDOMNode> NodeValue;
  94. HRESULT hr = S_OK;
  95. BSTR _bst_pretemp;
  96. Destination = "";
  97. if ( FAILED( hr = Attributes->getNamedItem(
  98. _bstr_t(AttribName.c_str()),
  99. // _bstr_t(NamespaceURI.c_str()),
  100. &NodeValue
  101. ) ) )
  102. {
  103. goto lblBopOut;
  104. }
  105. else if ( NodeValue == NULL )
  106. {
  107. goto lblBopOut;
  108. }
  109. else
  110. {
  111. if ( FAILED( hr = NodeValue->get_text( &_bst_pretemp ) ) )
  112. {
  113. goto lblBopOut;
  114. }
  115. Destination = (char*)_bstr_t(_bst_pretemp,FALSE);
  116. }
  117. lblBopOut:
  118. return hr;
  119. }
  120. ostream& operator<<(
  121. ostream& ost,
  122. const CPostbuildProcessListEntry& thing
  123. )
  124. {
  125. ost << "(path=" << thing.manifestFullPath.c_str()
  126. << " name=" << thing.name.c_str()
  127. << " version=" << thing.version.c_str()
  128. << " language=" << thing.language.c_str() << ")";
  129. return ost;
  130. }
  131. bool g_bDisplaySpew = false, g_bDisplayWarnings = true;
  132. bool FileExists( const string& str )
  133. {
  134. return ( GetFileAttributesA( str.c_str() ) != -1 );
  135. }
  136. string JustifyPath( const string& str )
  137. {
  138. vector<CHAR> vec;
  139. DWORD dwCount = GetLongPathNameA( str.c_str(), NULL, 0 );
  140. if ( dwCount == 0 ) dwCount = ::GetLastError();
  141. vec.resize( dwCount );
  142. GetLongPathNameA( str.c_str(), &vec.front(), vec.size() );
  143. return string( &vec.front() );
  144. }
  145. string FudgePath( const string& path, const string& asmsroot )
  146. {
  147. string temp = path;
  148. //
  149. // At the moment, fudging doesn't do anything useful.
  150. //
  151. return temp;
  152. }
  153. void CPostbuildProcessListEntry::setManifestLocation( string root, string where )
  154. {
  155. manifestFullPath = root + "\\" + where;
  156. manifestPathOnly = manifestFullPath.substr( 0, manifestFullPath.find_last_of( '\\' ) );
  157. manifestFileName = manifestFullPath.substr( manifestFullPath.find_last_of( '\\' ) + 1 );
  158. if ( !FileExists( manifestFullPath ) )
  159. {
  160. stringstream ss;
  161. ss << "Referenced manifest " << where << " does not exist.";
  162. ReportError(ErrorSpew, ss);
  163. }
  164. }
  165. string g_AsmsBuildRootPath;
  166. //
  167. // Converts a series of strings, foo=bar chunklets, space-seperated, into a map
  168. // from 'foo' to 'bar'
  169. //
  170. StringStringMap
  171. MapFromDefLine( const wstring& source )
  172. {
  173. wstring::const_iterator here = source.begin();
  174. StringStringMap rvalue;
  175. //
  176. //
  177. // The tricky bit is that there could be spaces in quoted strings...
  178. //
  179. while ( here != source.end() )
  180. {
  181. wstring tag, value;
  182. wchar_t end_of_value = L' ';
  183. wstring::const_iterator equals;
  184. //
  185. // Look for an equals first
  186. //
  187. equals = find( here, source.end(), '=' );
  188. //
  189. // If there is no equals sign, stop.
  190. //
  191. if (equals == source.end())
  192. break;
  193. tag.assign( here, equals );
  194. //
  195. // Hop over the equals
  196. //
  197. here = equals;
  198. here++;
  199. //
  200. // If the equals sign was the last character in the string, stop.
  201. //
  202. if (here == source.end())
  203. break;
  204. //
  205. // Is 'here' at an open quote? Then extract everything to the next
  206. // quote, remembering to skip this quote as well
  207. //
  208. if ( *here == L'\"' )
  209. {
  210. end_of_value = L'\"';
  211. here++;
  212. //
  213. // If the quote was the last character in the string, stop.
  214. //
  215. if (here == source.end())
  216. break;
  217. }
  218. //
  219. // Now go and look for the end of the string, or a quote or a space.
  220. //
  221. wstring::const_iterator fullstring = find( here, source.end(), end_of_value );
  222. value.assign( here, fullstring );
  223. //
  224. // If it was a quote or a space, skip it. If end of string, stay put.
  225. //
  226. if (fullstring != source.end())
  227. here = fullstring + 1;
  228. rvalue.insert( pair<wstring,wstring>( tag, value ) );
  229. //
  230. // Skip whitespace, but stop if we hit the end of the string.
  231. //
  232. while (here != source.end() && (*here == L' ' || *here == L'\t' || *here == '\n' || *here == '\r' || iswspace(*here)))
  233. here++;
  234. }
  235. return rvalue;
  236. }
  237. wstring SwitchStringRep( const string& source )
  238. {
  239. vector<WCHAR> wch;
  240. wch.resize( MultiByteToWideChar( CP_ACP, 0, source.c_str(), source.size(), NULL, 0 ) );
  241. MultiByteToWideChar( CP_ACP, 0, source.c_str(), source.size(), &wch.front(), wch.size() );
  242. return wstring( wch.begin(), wch.end() );
  243. }
  244. string SwitchStringRep( const wstring& source )
  245. {
  246. vector<CHAR> wch;
  247. wch.resize( WideCharToMultiByte( CP_ACP, 0, source.c_str(), source.size(), NULL, 0, NULL, NULL ) );
  248. WideCharToMultiByte( CP_ACP, 0, source.c_str(), source.size(), &wch.front(), wch.size(), NULL, NULL );
  249. return string( wch.begin(), wch.end() );
  250. }