DownloadWorker.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <DownloadController.h>
  9. #include <DownloadWorker.h>
  10. #include <PythonBindings.h>
  11. namespace O3DE::ProjectManager
  12. {
  13. DownloadWorker::DownloadWorker()
  14. : QObject()
  15. {
  16. }
  17. void DownloadWorker::StartDownload()
  18. {
  19. auto objectDownloadProgress = [=](int bytesDownloaded, int totalBytes)
  20. {
  21. emit UpdateProgress(bytesDownloaded, totalBytes);
  22. };
  23. IPythonBindings::DetailedOutcome objectInfoResult;
  24. if (m_downloadType == DownloadController::DownloadObjectType::Gem)
  25. {
  26. objectInfoResult = PythonBindingsInterface::Get()->DownloadGem(m_objectName, m_destinationPath , objectDownloadProgress, /*force*/ true);
  27. }
  28. else if (m_downloadType == DownloadController::DownloadObjectType::Project)
  29. {
  30. objectInfoResult = PythonBindingsInterface::Get()->DownloadProject(m_objectName, m_destinationPath, objectDownloadProgress, /*force*/ true);
  31. }
  32. else if (m_downloadType == DownloadController::DownloadObjectType::Template)
  33. {
  34. objectInfoResult = PythonBindingsInterface::Get()->DownloadTemplate(m_objectName, m_destinationPath, objectDownloadProgress, /*force*/ true);
  35. }
  36. else
  37. {
  38. AZ_Error("DownloadWorker", false, "Unknown download object type %d", m_downloadType);
  39. }
  40. if (objectInfoResult.IsSuccess())
  41. {
  42. emit Done("", "");
  43. }
  44. else
  45. {
  46. emit Done(objectInfoResult.GetError().first.c_str(), objectInfoResult.GetError().second.c_str());
  47. }
  48. }
  49. void DownloadWorker::SetObjectToDownload(const QString& objectName, const QString& destinationPath, DownloadController::DownloadObjectType objectType, bool downloadNow)
  50. {
  51. m_objectName = objectName;
  52. m_destinationPath = destinationPath;
  53. m_downloadType = objectType;
  54. if (downloadNow)
  55. {
  56. StartDownload();
  57. }
  58. }
  59. } // namespace O3DE::ProjectManager