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.

213 lines
6.3 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: script.cpp
  7. //
  8. // Contents: Functions for working with Darwin files, both packages,
  9. // transforms and scripts.
  10. //
  11. // Classes:
  12. //
  13. // Functions: BuildScriptAndGetActInfo
  14. //
  15. // History: 1-14-1998 stevebl Created
  16. //
  17. //---------------------------------------------------------------------------
  18. #include "precomp.hxx"
  19. //+--------------------------------------------------------------------------
  20. //
  21. // Function: RegDeleteTree
  22. //
  23. // Synopsis: deletes a registry key and all of its children
  24. //
  25. // Arguments: [hKey] - handle to the key's parent
  26. // [szSubKey] - name of the key to be deleted
  27. //
  28. // Returns: ERROR_SUCCESS
  29. //
  30. // History: 1-14-1998 stevebl Moved from old project
  31. //
  32. //---------------------------------------------------------------------------
  33. LONG RegDeleteTree(HKEY hKey, TCHAR * szSubKey)
  34. {
  35. HKEY hKeyNew;
  36. LONG lResult = RegOpenKey(hKey, szSubKey, &hKeyNew);
  37. if (lResult != ERROR_SUCCESS)
  38. {
  39. return lResult;
  40. }
  41. TCHAR szName[256];
  42. szName[0] = 0;
  43. while (ERROR_SUCCESS == RegEnumKey(hKeyNew, 0, szName, 256))
  44. {
  45. RegDeleteTree(hKeyNew, szName);
  46. }
  47. RegCloseKey(hKeyNew);
  48. return RegDeleteKey(hKey, szSubKey);
  49. }
  50. //+--------------------------------------------------------------------------
  51. //
  52. // Function: BuildScriptAndGetActInfo
  53. //
  54. // Synopsis: Builds the script file and fills in the ACTINFO structure
  55. // member in the PACKAGEDETAIL structure.
  56. //
  57. // Arguments: [szScriptRoot] - [in] the subdirectory that the script file
  58. // should be place in.
  59. // [pd] - [in/out] package detail structure - see
  60. // notes for complete list of fields that
  61. // should be filled in and the list of fields
  62. // that are set on return
  63. //
  64. // Returns: S_OK - success
  65. // <other> - error
  66. //
  67. // Modifies: all fields under pd.pActInfo (only on success)
  68. // also modifies pd.pInstallInfo->cScriptLen
  69. //
  70. // History: 1-14-1998 stevebl Created
  71. //
  72. // Notes: On input:
  73. // pd.cSources must be >= 1.
  74. // pd.pszSourceList[] contains the MSI package and the list of
  75. // (if any) transforms to be applied.
  76. // pd.pPlatformInfo should be completely filled in (only one
  77. // locale).
  78. // pd.pInstallInfo->pszScriptFile contains the name of the
  79. // script file to be generated.
  80. //
  81. // On output:
  82. // The script file will be generated under the appropriate name
  83. // and in the appropriate directory.
  84. // pd.pActInfo will be completely filled in.
  85. //
  86. //---------------------------------------------------------------------------
  87. HRESULT BuildScriptAndGetActInfo(PACKAGEDETAIL & pd, BOOL bFileExtensionsOnly)
  88. {
  89. DebugMsg((DM_VERBOSE, TEXT("BuldScriptAndGetActInfo called with bFileExtensionsOnly == %u"), bFileExtensionsOnly));
  90. CHourglass hourglass;
  91. HRESULT hr;
  92. UINT uMsiStatus;
  93. LONG error;
  94. int i;
  95. CString szScriptPath = pd.pInstallInfo->pszScriptPath;
  96. CString szTransformList = L"";
  97. CClassCollection Classes( &pd );
  98. if (pd.cSources > 1)
  99. {
  100. CString szSource = pd.pszSourceList[0];
  101. int nChars = 1 + szSource.ReverseFind(L'\\');
  102. BOOL fTransformsAtSource = TRUE;
  103. for (i = 1; i < pd.cSources && TRUE == fTransformsAtSource; i++)
  104. {
  105. if (0 == wcsncmp(szSource, pd.pszSourceList[i], nChars))
  106. {
  107. // make sure there isn't a sub-path
  108. int n = nChars;
  109. while (0 != pd.pszSourceList[i][n] && TRUE == fTransformsAtSource)
  110. {
  111. if (pd.pszSourceList[i][n] == L'\\')
  112. {
  113. fTransformsAtSource = FALSE;
  114. }
  115. n++;
  116. }
  117. }
  118. else
  119. {
  120. fTransformsAtSource = FALSE;
  121. }
  122. }
  123. if (fTransformsAtSource)
  124. {
  125. szTransformList = L"@";
  126. }
  127. else
  128. {
  129. szTransformList = L"|";
  130. nChars = 0;
  131. }
  132. for (i = 1; i < pd.cSources; i++)
  133. {
  134. if (i > 1)
  135. {
  136. szTransformList += L";";
  137. }
  138. szTransformList += &pd.pszSourceList[i][nChars];
  139. }
  140. }
  141. // disable MSI ui
  142. MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
  143. // build the script file
  144. TCHAR szTempPath[MAX_PATH];
  145. TCHAR szTempFileName[MAX_PATH];
  146. if (0 != GetTempPath(sizeof(szTempPath) / sizeof(szTempPath[0]), szTempPath))
  147. {
  148. if (0 == GetTempFileName(szTempPath, TEXT("ADE"), 0, szTempFileName))
  149. {
  150. goto Failure;
  151. }
  152. DWORD dwPlatform;
  153. if ( CAppData::Is64Bit( &pd ) )
  154. {
  155. dwPlatform = MSIARCHITECTUREFLAGS_IA64;
  156. }
  157. else
  158. {
  159. dwPlatform = MSIARCHITECTUREFLAGS_X86;
  160. }
  161. uMsiStatus = MsiAdvertiseProductEx(
  162. pd.pszSourceList[0],
  163. szTempFileName,
  164. szTransformList,
  165. LANGIDFROMLCID(pd.pPlatformInfo->prgLocale[0]),
  166. dwPlatform,
  167. 0);
  168. if (uMsiStatus)
  169. {
  170. DeleteFile(szTempFileName);
  171. DebugMsg((DM_WARNING, TEXT("MsiAdvertiseProduct failed with %u"), uMsiStatus));
  172. LogADEEvent(EVENTLOG_ERROR_TYPE, EVENT_ADE_GENERATESCRIPT_ERROR, HRESULT_FROM_WIN32(uMsiStatus), pd.pszSourceList[0]);
  173. // an error occurred
  174. return HRESULT_FROM_WIN32((long)uMsiStatus);
  175. }
  176. // fill in the ActInfo
  177. hr = Classes.GetClasses( bFileExtensionsOnly );
  178. if ( SUCCEEDED( hr ) )
  179. {
  180. if (!CopyFile(szTempFileName, szScriptPath, FALSE))
  181. {
  182. hr = HRESULT_FROM_WIN32(GetLastError());
  183. DeleteFile(szTempFileName);
  184. return hr;
  185. }
  186. }
  187. DeleteFile(szTempFileName);
  188. }
  189. else
  190. {
  191. Failure:
  192. hr = HRESULT_FROM_WIN32(GetLastError());
  193. }
  194. return hr;
  195. }