mirror of
https://github.com/storytold/RuntimeFilesDownloader.git
synced 2026-10-09 00:09:42 +00:00
minor design changes
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
"Version": 1,
|
||||
"VersionName": "1.0",
|
||||
"FriendlyName": "RuntimeFilesDownloader",
|
||||
"Description": "Runtime Files Downloader plugin for Unreal Engine, which allows you to download any files via the HTTP protocol to the device memory.",
|
||||
"Description": "Runtime Files Downloader for Unreal Engine. Allows you to download any files via HTTP protocol on runtime and save in device storage",
|
||||
"Category": "Code Plugins",
|
||||
"CreatedBy": "Respirant",
|
||||
"CreatedByURL": "https://github.com/Respirant/RuntimeFilesDownloader",
|
||||
"DocsURL": "https://unreal.blog/runtime-files-downloader",
|
||||
"DocsURL": "https://github.com/Respirant/RuntimeFilesDownloader",
|
||||
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/e7e6df6d6e9c46f0ae35163eab67ff9a",
|
||||
"SupportURL": "https://telegram.me/Respirant",
|
||||
"CanContainContent": false,
|
||||
|
||||
+20
-21
@@ -1,31 +1,31 @@
|
||||
// Respirant 2020.
|
||||
|
||||
#include "RuntimeFilesDownloaderBPLibrary.h"
|
||||
#include "RuntimeFilesDownloaderLibrary.h"
|
||||
#include "RuntimeFilesDownloader.h"
|
||||
|
||||
URuntimeFilesDownloaderBPLibrary::URuntimeFilesDownloaderBPLibrary(const FObjectInitializer& ObjectInitializer)
|
||||
URuntimeFilesDownloaderLibrary::URuntimeFilesDownloaderLibrary(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
URuntimeFilesDownloaderBPLibrary::URuntimeFilesDownloaderBPLibrary() :
|
||||
URuntimeFilesDownloaderLibrary::URuntimeFilesDownloaderLibrary() :
|
||||
FileUrl(TEXT(""))
|
||||
, FileSavePath(TEXT(""))
|
||||
{
|
||||
}
|
||||
|
||||
URuntimeFilesDownloaderBPLibrary::~URuntimeFilesDownloaderBPLibrary()
|
||||
URuntimeFilesDownloaderLibrary::~URuntimeFilesDownloaderLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
URuntimeFilesDownloaderBPLibrary* URuntimeFilesDownloaderBPLibrary::CreateDownloader()
|
||||
URuntimeFilesDownloaderLibrary* URuntimeFilesDownloaderLibrary::CreateDownloader()
|
||||
{
|
||||
URuntimeFilesDownloaderBPLibrary* Downloader = NewObject<URuntimeFilesDownloaderBPLibrary>();
|
||||
URuntimeFilesDownloaderLibrary* Downloader = NewObject<URuntimeFilesDownloaderLibrary>();
|
||||
return Downloader;
|
||||
}
|
||||
|
||||
URuntimeFilesDownloaderBPLibrary* URuntimeFilesDownloaderBPLibrary::DownloadFile(const FString& URL, FString SavePath)
|
||||
URuntimeFilesDownloaderLibrary* URuntimeFilesDownloaderLibrary::DownloadFile(const FString& URL, FString SavePath)
|
||||
{
|
||||
FileUrl = URL;
|
||||
FileSavePath = SavePath;
|
||||
@@ -34,8 +34,8 @@ URuntimeFilesDownloaderBPLibrary* URuntimeFilesDownloaderBPLibrary::DownloadFile
|
||||
|
||||
HttpRequest->SetVerb("GET");
|
||||
HttpRequest->SetURL(URL);
|
||||
HttpRequest->OnProcessRequestComplete().BindUObject(this, &URuntimeFilesDownloaderBPLibrary::OnReady_Internal);
|
||||
HttpRequest->OnRequestProgress().BindUObject(this, &URuntimeFilesDownloaderBPLibrary::OnProgress_Internal);
|
||||
HttpRequest->OnProcessRequestComplete().BindUObject(this, &URuntimeFilesDownloaderLibrary::OnReady_Internal);
|
||||
HttpRequest->OnRequestProgress().BindUObject(this, &URuntimeFilesDownloaderLibrary::OnProgress_Internal);
|
||||
|
||||
// Execute the request
|
||||
HttpRequest->ProcessRequest();
|
||||
@@ -44,7 +44,13 @@ URuntimeFilesDownloaderBPLibrary* URuntimeFilesDownloaderBPLibrary::DownloadFile
|
||||
return this;
|
||||
}
|
||||
|
||||
void URuntimeFilesDownloaderBPLibrary::OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||
void URuntimeFilesDownloaderLibrary::OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived)
|
||||
{
|
||||
int32 FullSize = Request->GetContentLength();
|
||||
OnProgress.Broadcast(BytesSent, BytesReceived, FullSize);
|
||||
}
|
||||
|
||||
void URuntimeFilesDownloaderLibrary::OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||
{
|
||||
RemoveFromRoot();
|
||||
Request->OnProcessRequestComplete().Unbind();
|
||||
@@ -61,7 +67,7 @@ void URuntimeFilesDownloaderBPLibrary::OnReady_Internal(FHttpRequestPtr Request,
|
||||
{
|
||||
if (!PlatformFile.CreateDirectoryTree(*Path))
|
||||
{
|
||||
OnResult.Broadcast(EDownloadResult::DirectoryCreationFailed);
|
||||
OnResult.Broadcast(DownloadResult::DirectoryCreationFailed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -75,22 +81,15 @@ void URuntimeFilesDownloaderBPLibrary::OnReady_Internal(FHttpRequestPtr Request,
|
||||
// Close the file
|
||||
delete FileHandle;
|
||||
|
||||
OnResult.Broadcast(EDownloadResult::Success);
|
||||
OnResult.Broadcast(DownloadResult::SuccessDownloading);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnResult.Broadcast(EDownloadResult::SaveFailed);
|
||||
OnResult.Broadcast(DownloadResult::SaveFailed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnResult.Broadcast(EDownloadResult::DownloadFailed);
|
||||
OnResult.Broadcast(DownloadResult::DownloadFailed);
|
||||
}
|
||||
}
|
||||
|
||||
void URuntimeFilesDownloaderBPLibrary::OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived)
|
||||
{
|
||||
int32 FullSize = Request->GetContentLength();
|
||||
OnProgress.Broadcast(BytesSent, BytesReceived, FullSize);
|
||||
}
|
||||
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
// Respirant 2020.
|
||||
|
||||
#pragma once
|
||||
#include "Http.h"
|
||||
|
||||
#include "Misc/Paths.h"
|
||||
#include "HAL/PlatformFilemanager.h"
|
||||
|
||||
#include "GenericPlatform/GenericPlatformFile.h"
|
||||
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "RuntimeFilesDownloaderBPLibrary.generated.h"
|
||||
|
||||
UENUM(BlueprintType, Category = "RuntimeFilesDownloader")
|
||||
enum class EDownloadResult : uint8
|
||||
{
|
||||
Success,
|
||||
DownloadFailed,
|
||||
SaveFailed,
|
||||
DirectoryCreationFailed
|
||||
};
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnResult, const EDownloadResult, Result);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnProgress, const int32, BytesSent, const int32, BytesReceived, const int32, ContentLength);
|
||||
|
||||
UCLASS()
|
||||
class RUNTIMEFILESDOWNLOADER_API URuntimeFilesDownloaderBPLibrary : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_UCLASS_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Bind to know when the download is complete (even if it fails).
|
||||
*/
|
||||
UPROPERTY(BlueprintAssignable, Category = "RuntimeFilesDownloader")
|
||||
FOnResult OnResult;
|
||||
/**
|
||||
* Bind to know when the download is on progress.
|
||||
*/
|
||||
UPROPERTY(BlueprintAssignable, Category = "RuntimeFilesDownloader")
|
||||
FOnProgress OnProgress;
|
||||
|
||||
/**
|
||||
* The URL used to start this download.
|
||||
*/
|
||||
UPROPERTY(BlueprintReadOnly, Category = "RuntimeFilesDownloader")
|
||||
FString FileUrl;
|
||||
|
||||
/**
|
||||
* The path set to save the downloaded file.
|
||||
*/
|
||||
UPROPERTY(BlueprintReadOnly, Category = "RuntimeFilesDownloader")
|
||||
FString FileSavePath;
|
||||
|
||||
URuntimeFilesDownloaderBPLibrary();
|
||||
~URuntimeFilesDownloaderBPLibrary();
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a FileDownloader object, starts downloading and saves it when done.
|
||||
*
|
||||
* @return The FileDownloader object. Bind to it's OnResult event to know when it's done downloading.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "RuntimeFilesDownloader")
|
||||
static URuntimeFilesDownloaderBPLibrary* CreateDownloader();
|
||||
|
||||
/**
|
||||
* Starts downloading a file and saves it when done.
|
||||
*
|
||||
* @param Url The file Url to be downloaded.
|
||||
* @param SavePath The absolute path and file name to save the downloaded file.
|
||||
* @return Returns itself.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "RuntimeFilesDownloader")
|
||||
URuntimeFilesDownloaderBPLibrary* DownloadFile(const FString & URL, FString SavePath);
|
||||
|
||||
private:
|
||||
|
||||
void OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||
void OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived);
|
||||
};
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
// Respirant 2020.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Http.h"
|
||||
#include "Misc/Paths.h"
|
||||
#include "HAL/PlatformFilemanager.h"
|
||||
//#include "GenericPlatform/GenericPlatformFile.h"
|
||||
#include "RuntimeFilesDownloaderLibrary.generated.h"
|
||||
|
||||
/**
|
||||
* Possible results from a download request.
|
||||
*/
|
||||
UENUM(BlueprintType, Category = "RuntimeFilesDownloader")
|
||||
enum DownloadResult
|
||||
{
|
||||
SuccessDownloading UMETA(DisplayName = "Success"),
|
||||
DownloadFailed UMETA(DisplayName = "Download failed"),
|
||||
SaveFailed UMETA(DisplayName = "Save failed"),
|
||||
DirectoryCreationFailed UMETA(DisplayName = "Directory creation failed")
|
||||
};
|
||||
|
||||
/**
|
||||
* Declare delegate which will be called during the download process
|
||||
*/
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnProgress, const int32, BytesSent, const int32, BytesReceived, const int32, ContentLength);
|
||||
|
||||
/**
|
||||
* Declare a delegate that will be called on the download result
|
||||
*/
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnResult, TEnumAsByte < DownloadResult >, Result);
|
||||
|
||||
UCLASS(BlueprintType, Category = "RuntimeFilesDownloader")
|
||||
class RUNTIMEFILESDOWNLOADER_API URuntimeFilesDownloaderLibrary : public UObject
|
||||
{
|
||||
GENERATED_UCLASS_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Bind to know when the download is on progress.
|
||||
*/
|
||||
UPROPERTY(BlueprintAssignable, Category = "RuntimeFilesDownloader")
|
||||
FOnProgress OnProgress;
|
||||
|
||||
/**
|
||||
* Bind to know when the download is complete (even if it fails).
|
||||
*/
|
||||
UPROPERTY(BlueprintAssignable, Category = "RuntimeFilesDownloader")
|
||||
FOnResult OnResult;
|
||||
|
||||
/**
|
||||
* The URL used to start this download.
|
||||
*/
|
||||
UPROPERTY(BlueprintReadOnly, Category = "RuntimeFilesDownloader")
|
||||
FString FileUrl;
|
||||
|
||||
/**
|
||||
* The path set to save the downloaded file.
|
||||
*/
|
||||
UPROPERTY(BlueprintReadOnly, Category = "RuntimeFilesDownloader")
|
||||
FString FileSavePath;
|
||||
|
||||
/**
|
||||
* Basic class methods
|
||||
*/
|
||||
URuntimeFilesDownloaderLibrary();
|
||||
~URuntimeFilesDownloaderLibrary();
|
||||
|
||||
/**
|
||||
* Instantiates a FileDownloader object, starts downloading and saves it when done.
|
||||
*
|
||||
* @return The RuntimeFilesDownloader object. Bind to it's OnResult event to know when it is in the process of downloading and has been downloaded.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "RuntimeFilesDownloader")
|
||||
static URuntimeFilesDownloaderLibrary* CreateDownloader();
|
||||
|
||||
/**
|
||||
* Starts downloading a file and saves it when done.
|
||||
*
|
||||
* @param URL The file Url to be downloaded.
|
||||
* @param SavePath The absolute path and file name to save the downloaded file.
|
||||
* @return Returns itself.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "RuntimeFilesDownloader")
|
||||
URuntimeFilesDownloaderLibrary* DownloadFile(const FString & URL, FString SavePath);
|
||||
|
||||
private:
|
||||
/**
|
||||
* File downloading progress callback
|
||||
*/
|
||||
void OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived);
|
||||
|
||||
/**
|
||||
* File downloading finished callback
|
||||
*/
|
||||
void OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||
};
|
||||
@@ -19,6 +19,7 @@ public class RuntimeFilesDownloader : ModuleRules
|
||||
);
|
||||
|
||||
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user