A modded EditSaber for making beat saber maps.
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.

79 lines
2.3 KiB

  1. // Fill out your copyright notice in the Description page of Project Settings.
  2. #pragma once
  3. #include "Http.h"
  4. #include "FileDownloader.generated.h"
  5. /**
  6. * Possible results from a download request.
  7. */
  8. UENUM(BlueprintType, Category = "HTTP")
  9. enum class EDownloadResult : uint8
  10. {
  11. Success,
  12. DownloadFailed,
  13. SaveFailed,
  14. DirectoryCreationFailed
  15. };
  16. DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnResult, const EDownloadResult, Result);
  17. DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnProgress, const int32, BytesSent, const int32, BytesReceived, const int32, ContentLength);
  18. /**
  19. * Download a file from a URL and save it locally.
  20. */
  21. UCLASS(BlueprintType, Category = "HTTP")
  22. class MEDIOCREMAPPER_API UFileDownloader : public UObject
  23. {
  24. GENERATED_BODY()
  25. public:
  26. /**
  27. * Bind to know when the download is complete (even if it fails).
  28. */
  29. UPROPERTY(BlueprintAssignable, Category = "HTTP")
  30. FOnResult OnResult;
  31. /**
  32. * Bind to know when the download is complete (even if it fails).
  33. */
  34. UPROPERTY(BlueprintAssignable, Category = "HTTP")
  35. FOnProgress OnProgress;
  36. /**
  37. * The URL used to start this download.
  38. */
  39. UPROPERTY(BlueprintReadOnly, Category = "HTTP")
  40. FString FileUrl;
  41. /**
  42. * The path set to save the downloaded file.
  43. */
  44. UPROPERTY(BlueprintReadOnly, Category = "HTTP")
  45. FString FileSavePath;
  46. UFileDownloader();
  47. ~UFileDownloader();
  48. /**
  49. * Instantiates a FileDownloader object, starts downloading and saves it when done.
  50. *
  51. * @return The FileDownloader object. Bind to it's OnResult event to know when it's done downloading.
  52. */
  53. UFUNCTION(BlueprintCallable, Meta = (DisplayName = "Create Downloader"), Category = "HTTP")
  54. static UFileDownloader* MakeDownloader();
  55. /**
  56. * Starts downloading a file and saves it when done. Bind to the OnResult
  57. * event to know when the download is done (preferrably, before calling this function).
  58. *
  59. * @param Url The file Url to be downloaded.
  60. * @param SavePath The absolute path and file name to save the downloaded file.
  61. * @return Returns itself.
  62. */
  63. UFUNCTION(BlueprintCallable, Category = "HTTP")
  64. UFileDownloader* DownloadFile(const FString& Url, FString SavePath);
  65. private:
  66. void OnReady(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
  67. void OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived);
  68. };