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.

85 lines
1.8 KiB

  1. #include "stdafx.h"
  2. #include <iucommon.h>
  3. #include <trust.h>
  4. #include <logging.h>
  5. #include <fileutil.h>
  6. #include "iudl.h"
  7. #include <download.h>
  8. #include <UrlAgent.h>
  9. extern HANDLE g_hEngineLoadQuit;
  10. extern CIUUrlAgent *g_pIUUrlAgent;
  11. HRESULT IUDownloadFile(LPCTSTR pszDownloadUrl,
  12. LPCTSTR pszLocalFile,
  13. BOOL fDecompress,
  14. BOOL fCheckTrust,
  15. DWORD dwFlags)
  16. {
  17. LOG_Block("IUDownloadFile()");
  18. HRESULT hr = S_OK;
  19. if (FAILED(hr = g_pIUUrlAgent->IsIdentFromPolicy()))
  20. {
  21. goto done;
  22. }
  23. if (S_FALSE == hr)
  24. {
  25. hr = S_OK;
  26. }
  27. else // S_OK
  28. {
  29. dwFlags |= WUDF_DONTALLOWPROXY;
  30. LOG_Internet(_T("WUDF_DONTALLOWPROXY set"));
  31. }
  32. // do the download
  33. hr = DownloadFileLite(pszDownloadUrl, pszLocalFile, g_hEngineLoadQuit, dwFlags);
  34. if (FAILED(hr))
  35. goto done;
  36. // check for decompress requested
  37. if (fCheckTrust)
  38. {
  39. if (FAILED(hr = VerifyFileTrust(pszLocalFile, NULL, ReadWUPolicyShowTrustUI())))
  40. {
  41. LOG_ErrorMsg(hr);
  42. // The file was not trusted.. delete it.
  43. DeleteFile(pszLocalFile);
  44. goto done;
  45. }
  46. }
  47. if (fDecompress)
  48. {
  49. TCHAR *pszLocalDir = NULL;
  50. DWORD cchNeed = _tcslen(pszLocalFile) + 1;
  51. __try { pszLocalDir = (LPTSTR)_alloca(cchNeed * sizeof(TCHAR)); }
  52. __except(EXCEPTION_EXECUTE_HANDLER) { pszLocalDir = NULL; }
  53. if (pszLocalDir == NULL)
  54. {
  55. LOG_ErrorMsg(ERROR_OUTOFMEMORY);
  56. hr = E_OUTOFMEMORY;
  57. goto done;
  58. }
  59. hr=StringCchCopyEx(pszLocalDir,cchNeed,pszLocalFile,NULL,NULL,MISTSAFE_STRING_FLAGS);
  60. if(FAILED(hr))
  61. {
  62. LOG_ErrorMsg(hr);
  63. goto done;
  64. }
  65. PathRemoveFileSpec(pszLocalDir);
  66. IUExtractFiles(pszLocalFile, pszLocalDir);
  67. }
  68. done:
  69. return hr;
  70. }