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.

240 lines
7.4 KiB

  1. // ===========================================================================
  2. // File: JSETUP.CXX
  3. // implements CJavaSetup
  4. //
  5. #include <cdlpch.h>
  6. #include <pkgguid.h>
  7. // ---------------------------------------------------------------------------
  8. // %%Function: CJavaSetup::CJavaSetup
  9. // ---------------------------------------------------------------------------
  10. CJavaSetup::CJavaSetup(
  11. CDownload *pdl,
  12. LPCWSTR szPackageName,
  13. LPCWSTR szNameSpace,
  14. IXMLElement *pPackage,
  15. DWORD dwVersionMS,
  16. DWORD dwVersionLS,
  17. DWORD flags,
  18. HRESULT *phr)
  19. :
  20. m_pdl(pdl),
  21. m_dwVersionMS(dwVersionMS),
  22. m_dwVersionLS(dwVersionLS),
  23. m_flags(flags),
  24. m_state(INSTALL_INIT)
  25. {
  26. DEBUG_ENTER((DBG_DOWNLOAD,
  27. None,
  28. "CJavaSetup::CJavaSetup",
  29. "this=%#x, %#x, %.80wq, %.80wq, %#x, %#x, %#x, %#x, %#x",
  30. this, pdl, szPackageName, szNameSpace, pPackage, dwVersionMS, dwVersionLS, flags, phr
  31. ));
  32. *phr = S_OK;
  33. if (szPackageName) {
  34. DWORD len = lstrlenW(szPackageName) +1;
  35. m_szPackageName = new WCHAR [len]; // make private copy
  36. if (m_szPackageName)
  37. StrCpyW(m_szPackageName, szPackageName);
  38. else
  39. *phr = E_OUTOFMEMORY;
  40. } else {
  41. m_szPackageName = NULL;
  42. }
  43. if (szNameSpace) {
  44. DWORD len = lstrlenW(szNameSpace) +1;
  45. m_szNameSpace = new WCHAR [len]; // make private copy
  46. if (m_szNameSpace)
  47. StrCpyW(m_szNameSpace, szNameSpace);
  48. else
  49. *phr = E_OUTOFMEMORY;
  50. } else {
  51. m_szNameSpace = NULL;
  52. }
  53. m_pPackage = pPackage;
  54. if (pPackage) {
  55. pPackage->AddRef();
  56. }
  57. DEBUG_LEAVE(0);
  58. } // CJavaSetup
  59. // ---------------------------------------------------------------------------
  60. // %%Function: CJavaSetup::~CJavaSetup
  61. // ---------------------------------------------------------------------------
  62. CJavaSetup::~CJavaSetup()
  63. {
  64. DEBUG_ENTER((DBG_DOWNLOAD,
  65. None,
  66. "CJavaSetup::~CJavaSetup",
  67. "this=%#x",
  68. this
  69. ));
  70. SAFEDELETE(m_szPackageName);
  71. SAFEDELETE(m_szNameSpace);
  72. SAFERELEASE(m_pPackage);
  73. DEBUG_LEAVE(0);
  74. } // ~CJavaSetup
  75. // ---------------------------------------------------------------------------
  76. // %%Function: CJavaSetup::DoSetup
  77. // ---------------------------------------------------------------------------
  78. HRESULT
  79. CJavaSetup::DoSetup()
  80. {
  81. DEBUG_ENTER((DBG_DOWNLOAD,
  82. Hresult,
  83. "CJavaSetup::DoSetup",
  84. "this=%#x",
  85. this
  86. ));
  87. Assert(m_pdl);
  88. CCodeDownload *pcdl = m_pdl->GetCodeDownload();
  89. Assert(pcdl);
  90. HWND hWnd = pcdl->GetClientBinding()->GetHWND();
  91. HRESULT hr = S_OK;
  92. CList<CJavaSetup*,CJavaSetup*> *pjsList = m_pdl->GetJavaSetupList();
  93. PACKAGEINSTALLINFO *PackageInfo = NULL;
  94. LPCWSTR pwszNameSpace = NULL;
  95. int i;
  96. if (SUCCEEDED(hr)) {
  97. // call the pkg mgr to install the package.
  98. int nCntjs = pjsList->GetCount(), njs = 0;
  99. POSITION pos = pjsList->GetHeadPosition();
  100. BOOL bInstallReqd = FALSE;
  101. // find the first setup that needs to be installed and then record
  102. // its namespace. We will then instal all packages in the CDownload
  103. // that macth that namespace and then return. On each call we will
  104. // install all pkgs in a namespace till all setups are done.
  105. for (i=0; i<nCntjs; i++) {
  106. CJavaSetup *pjs = pjsList->GetNext(pos);
  107. Assert(pjs != NULL);
  108. if (pjs->GetState() != INSTALL_DONE) {
  109. pwszNameSpace = pjs->GetNameSpace();
  110. bInstallReqd = TRUE;
  111. break;
  112. }
  113. }
  114. if (!bInstallReqd)
  115. {
  116. DEBUG_LEAVE(hr);
  117. return hr;
  118. }
  119. PackageInfo = new PACKAGEINSTALLINFO[nCntjs];
  120. if (PackageInfo == NULL) {
  121. hr = E_OUTOFMEMORY;
  122. goto Exit;
  123. }
  124. PACKAGESECURITYINFO PkgSecInfo;
  125. ZeroMemory(PackageInfo,sizeof(PACKAGEINSTALLINFO)*nCntjs);
  126. ZeroMemory(&PkgSecInfo,sizeof(PkgSecInfo));
  127. pos = pjsList->GetHeadPosition();
  128. for (i=0; i<nCntjs; i++) {
  129. CJavaSetup *pjs = pjsList->GetNext(pos);
  130. Assert(pjs != NULL);
  131. // when installing multiple packages, if some are installed they should be skipped.
  132. if (pjs->GetPackageFlags() & CJS_FLAG_NOSETUP) {
  133. pjs->SetState(INSTALL_DONE);
  134. continue;
  135. }
  136. if ((pjs->GetState() != INSTALL_DONE) &&
  137. ((pjs->GetNameSpace() == pwszNameSpace) ||
  138. ( pwszNameSpace && pjs->GetNameSpace() &&
  139. (StrCmpIW(pjs->GetNameSpace(), pwszNameSpace) == 0)))) {
  140. pcdl->CodeDownloadDebugOut(DEB_CODEDL, TRUE, ID_CDLDBG_JAVA_PKG_SETUP, pjs->GetPackageName(), (pwszNameSpace)?pwszNameSpace:L"Global");
  141. PACKAGEINSTALLINFO *CurPackageInfo = &PackageInfo[njs];
  142. CurPackageInfo->cbStruct = sizeof(PACKAGEINSTALLINFO);
  143. CurPackageInfo->pszPackageName = pjs->GetPackageName();
  144. pjs->GetPackageVersion(CurPackageInfo->dwVersionMS, CurPackageInfo->dwVersionLS);
  145. CurPackageInfo->pszDistributionUnit = pcdl->GetMainDistUnit(); // Should be same dist unit
  146. CurPackageInfo->pUnknown = (IUnknown *)(pjs->GetPackageXMLElement());
  147. if (pjs->GetPackageFlags() & CJS_FLAG_SYSTEM) {
  148. CurPackageInfo->dwFlags |= JPMPII_SYSTEMCLASS; // Already true by zeroing
  149. } else {
  150. CurPackageInfo->dwFlags |= JPMPII_NONSYSTEMCLASS;
  151. }
  152. if (pjs->GetPackageFlags() & CJS_FLAG_NEEDSTRUSTEDSOURCE) {
  153. CurPackageInfo->dwFlags |= JPMPII_NEEDSTRUSTEDSOURCE;
  154. }
  155. njs++;
  156. pjs->SetState(INSTALL_DONE);
  157. }
  158. }
  159. Assert(pos == NULL); // Should be exact count.
  160. // if nothing actually needs to be installed, skip calling InstallPackage
  161. if (njs == 0)
  162. goto Exit;
  163. PkgSecInfo.cbStruct = sizeof(PkgSecInfo);
  164. PJAVA_TRUST pjt = m_pdl->GetJavaTrust();
  165. if (pjt) {
  166. PkgSecInfo.pCapabilities = pjt->pbJavaPermissions;
  167. PkgSecInfo.cbCapabilities = pjt->cbJavaPermissions;
  168. PkgSecInfo.pSigner = pjt->pbSigner;
  169. PkgSecInfo.cbSigner = pjt->cbSigner;
  170. PkgSecInfo.fAllPermissions = pjt->fAllPermissions;
  171. }
  172. WCHAR szCabName[MAX_PATH];
  173. if (!MultiByteToWideChar(CP_ACP, 0, m_pdl->GetFileName(), -1, szCabName, MAX_PATH)) {
  174. hr = HRESULT_FROM_WIN32(GetLastError());
  175. goto Exit;
  176. }
  177. hr = pcdl->GetPackageManager()->InstallPackage(szCabName, pwszNameSpace,
  178. JPMINST_CAB,&PackageInfo[0],njs,0, &PkgSecInfo);
  179. }
  180. Exit:
  181. SAFEDELETE(PackageInfo);
  182. if (FAILED(hr)) {
  183. pcdl->CodeDownloadDebugOut(DEB_CODEDL, TRUE, ID_CDLDBG_JAVA_PKG_FAILED, hr);
  184. }
  185. DEBUG_LEAVE(hr);
  186. return hr;
  187. }