mirror of
https://github.com/Theaninova/BeatLanguageMapper.git
synced 2026-01-03 09:02:48 +00:00
Mk2
uh stuff. i'm putting it in the readme.
This commit is contained in:
@@ -102,10 +102,20 @@ bool UBPFileIO::DeleteFile(const FString & File)
|
||||
|
||||
bool UBPFileIO::DeleteDirectory(const FString & Directory)
|
||||
{
|
||||
if (!FPlatformFileManager::Get().GetPlatformFile().DeleteDirectory(*Directory))
|
||||
if (!FPlatformFileManager::Get().GetPlatformFile().DeleteDirectoryRecursively(*Directory))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int UBPFileIO::getFileSize(const FString & File)
|
||||
{
|
||||
return FPlatformFileManager::Get().GetPlatformFile().FileSize(*File);
|
||||
}
|
||||
|
||||
int UBPFileIO::getTimestamp(const FString & File)
|
||||
{
|
||||
return FPlatformFileManager::Get().GetPlatformFile().GetTimeStamp(*File).ToUnixTimestamp();
|
||||
}
|
||||
@@ -43,4 +43,11 @@ class MEDIOCREMAPPER_API UBPFileIO : public UBlueprintFunctionLibrary
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "File IO")
|
||||
static bool DeleteDirectory(const FString& Directory);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "File IO")
|
||||
static int getFileSize(const FString& File);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "File IO")
|
||||
static int getTimestamp(const FString& File);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "BP_BPMChange.h"
|
||||
|
||||
|
||||
// Sets default values
|
||||
ABP_BPMChange::ABP_BPMChange()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ABP_BPMChange::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void ABP_BPMChange::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "BP_BPMChange.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class MEDIOCREMAPPER_API ABP_BPMChange : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
ABP_BPMChange();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
|
||||
|
||||
};
|
||||
21
Source/MediocreMapper/ColorConverter.cpp
Normal file
21
Source/MediocreMapper/ColorConverter.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "ColorConverter.h"
|
||||
|
||||
int UColorConverter::ColortoInt(FLinearColor color)
|
||||
{
|
||||
int r = color.R * 255;
|
||||
int g = color.G * 255;
|
||||
int b = color.B * 255;
|
||||
return 2000000000+((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
|
||||
}
|
||||
|
||||
FLinearColor UColorConverter::InttoColor(int color)
|
||||
{
|
||||
color = color - 2000000000;
|
||||
FLinearColor outColor;
|
||||
outColor.B = (float)(color & 0xFF)/0xFE;
|
||||
outColor.G = (float)(color >> 8 & 0xFF)/0xFE;
|
||||
outColor.R = (float)(color >> 16 & 0xFF)/0xFE;
|
||||
return outColor;
|
||||
}
|
||||
24
Source/MediocreMapper/ColorConverter.h
Normal file
24
Source/MediocreMapper/ColorConverter.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "ColorConverter.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class MEDIOCREMAPPER_API UColorConverter : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Color to Int"), Category = "RGB Integers")
|
||||
static int ColortoInt(FLinearColor color);
|
||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Int to Color"), Category = "RGB Integers")
|
||||
static FLinearColor InttoColor(int color);
|
||||
|
||||
|
||||
};
|
||||
89
Source/MediocreMapper/FileDownloader.cpp
Normal file
89
Source/MediocreMapper/FileDownloader.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
#include "FileDownloader.h"
|
||||
#include "BeatSaberEditor.h"
|
||||
#include "PlatformFilemanager.h"
|
||||
#include "GenericPlatform/GenericPlatformFile.h"
|
||||
#include "Paths.h"
|
||||
UFileDownloader::UFileDownloader():
|
||||
FileUrl(TEXT(""))
|
||||
, FileSavePath(TEXT(""))
|
||||
{
|
||||
}
|
||||
|
||||
UFileDownloader::~UFileDownloader()
|
||||
{
|
||||
}
|
||||
|
||||
UFileDownloader* UFileDownloader::MakeDownloader()
|
||||
{
|
||||
UFileDownloader* Downloader = NewObject<UFileDownloader>();
|
||||
return Downloader;
|
||||
}
|
||||
|
||||
UFileDownloader* UFileDownloader::DownloadFile(const FString& Url, FString SavePath)
|
||||
{
|
||||
FileUrl = Url;
|
||||
FileSavePath = SavePath;
|
||||
|
||||
TSharedRef< IHttpRequest > HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetVerb("GET");
|
||||
HttpRequest->SetURL(Url);
|
||||
HttpRequest->OnProcessRequestComplete().BindUObject(this, &UFileDownloader::OnReady);
|
||||
HttpRequest->OnRequestProgress().BindUObject(this, &UFileDownloader::OnProgress_Internal);
|
||||
|
||||
// Execute the request
|
||||
HttpRequest->ProcessRequest();
|
||||
AddToRoot();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void UFileDownloader::OnReady(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||
{
|
||||
RemoveFromRoot();
|
||||
Request->OnProcessRequestComplete().Unbind();
|
||||
|
||||
if (Response.IsValid() && EHttpResponseCodes::IsOk(Response->GetResponseCode()))
|
||||
{
|
||||
// SAVE FILE
|
||||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
|
||||
|
||||
// create save directory if not existent
|
||||
FString Path, Filename, Extension;
|
||||
FPaths::Split(FileSavePath, Path, Filename, Extension);
|
||||
if (!PlatformFile.DirectoryExists(*Path))
|
||||
{
|
||||
if(!PlatformFile.CreateDirectoryTree(*Path))
|
||||
{
|
||||
OnResult.Broadcast(EDownloadResult::DirectoryCreationFailed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// open/create the file
|
||||
IFileHandle* FileHandle = PlatformFile.OpenWrite(*FileSavePath);
|
||||
if (FileHandle)
|
||||
{
|
||||
// write the file
|
||||
FileHandle->Write(Response->GetContent().GetData(), Response->GetContentLength());
|
||||
// Close the file
|
||||
delete FileHandle;
|
||||
|
||||
OnResult.Broadcast(EDownloadResult::Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnResult.Broadcast(EDownloadResult::SaveFailed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnResult.Broadcast(EDownloadResult::DownloadFailed);
|
||||
}
|
||||
}
|
||||
|
||||
void UFileDownloader::OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived)
|
||||
{
|
||||
int32 FullSize = Request->GetContentLength();
|
||||
OnProgress.Broadcast(BytesSent, BytesReceived, FullSize);
|
||||
}
|
||||
80
Source/MediocreMapper/FileDownloader.h
Normal file
80
Source/MediocreMapper/FileDownloader.h
Normal file
@@ -0,0 +1,80 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Http.h"
|
||||
#include "FileDownloader.generated.h"
|
||||
|
||||
/**
|
||||
* Possible results from a download request.
|
||||
*/
|
||||
UENUM(BlueprintType, Category = "HTTP")
|
||||
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);
|
||||
|
||||
/**
|
||||
* Download a file from a URL and save it locally.
|
||||
*/
|
||||
UCLASS(BlueprintType, Category = "HTTP")
|
||||
class MEDIOCREMAPPER_API UFileDownloader : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Bind to know when the download is complete (even if it fails).
|
||||
*/
|
||||
UPROPERTY(BlueprintAssignable, Category = "HTTP")
|
||||
FOnResult OnResult;
|
||||
/**
|
||||
* Bind to know when the download is complete (even if it fails).
|
||||
*/
|
||||
UPROPERTY(BlueprintAssignable, Category = "HTTP")
|
||||
FOnProgress OnProgress;
|
||||
|
||||
/**
|
||||
* The URL used to start this download.
|
||||
*/
|
||||
UPROPERTY(BlueprintReadOnly, Category = "HTTP")
|
||||
FString FileUrl;
|
||||
/**
|
||||
* The path set to save the downloaded file.
|
||||
*/
|
||||
UPROPERTY(BlueprintReadOnly, Category = "HTTP")
|
||||
FString FileSavePath;
|
||||
|
||||
UFileDownloader();
|
||||
~UFileDownloader();
|
||||
|
||||
/**
|
||||
* 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, Meta = (DisplayName = "Create Downloader"), Category = "HTTP")
|
||||
static UFileDownloader* MakeDownloader();
|
||||
|
||||
/**
|
||||
* Starts downloading a file and saves it when done. Bind to the OnResult
|
||||
* event to know when the download is done (preferrably, before calling this function).
|
||||
*
|
||||
* @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 = "HTTP")
|
||||
UFileDownloader* DownloadFile(const FString& Url, FString SavePath);
|
||||
|
||||
private:
|
||||
|
||||
void OnReady(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||
void OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived);
|
||||
};
|
||||
@@ -8,7 +8,7 @@ public class MediocreMapper : ModuleRules
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ProceduralMeshComponent" });
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ProceduralMeshComponent", "HTTP" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
|
||||
22
Source/MediocreMapper/Updater.cpp
Normal file
22
Source/MediocreMapper/Updater.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "Updater.h"
|
||||
#include "FileManagerGeneric.h"
|
||||
#include "Paths.h"
|
||||
#include <windows.h>
|
||||
|
||||
bool UUpdater::updateUpdater()
|
||||
{
|
||||
FString source = FPaths::GameDir()+"Updates/MediocreMapper/MediocreUpdater.exe";
|
||||
FString target = FPaths::GameDir() +"MediocreUpdater.exe";
|
||||
UE_LOG(LogTemp, Warning, TEXT("%s"), *source);
|
||||
if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*source))
|
||||
{
|
||||
IFileManager& fManager = FFileManagerGeneric::Get();
|
||||
fManager.Copy(*source,*target,true,true);
|
||||
return FPlatformFileManager::Get().GetPlatformFile().FileExists(*target);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
21
Source/MediocreMapper/Updater.h
Normal file
21
Source/MediocreMapper/Updater.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "Updater.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class MEDIOCREMAPPER_API UUpdater : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "UpdateUpdater"), Category = "updaterUpdater")
|
||||
static bool updateUpdater();
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user