-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 41865c3
Showing
9 changed files
with
450 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Binaries | ||
Intermediate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"FileVersion": 3, | ||
"Version": 1, | ||
"VersionName": "1.0", | ||
"FriendlyName": "Blueprint File SDK", | ||
"Description": "A simple plugin to interact with files and folders within blueprints.", | ||
"Category": "Blueprints", | ||
"CreatedBy": "Incanta Games", | ||
"CreatedByURL": "https://incanta.games", | ||
"DocsURL": "https://github.com/IncantaGames/unreal-bp-file-sdk", | ||
"MarketplaceURL": "", | ||
"SupportURL": "https://discord.gg/5hFrK2D", | ||
"CanContainContent": false, | ||
"IsBetaVersion": false, | ||
"IsExperimentalVersion": false, | ||
"Installed": false, | ||
"Modules": [ | ||
{ | ||
"Name": "FileSDK", | ||
"Type": "Runtime", | ||
"LoadingPhase": "PreLoadingScreen" | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Some copyright should be here... | ||
|
||
using UnrealBuildTool; | ||
|
||
public class FileSDK : ModuleRules { | ||
public FileSDK(ReadOnlyTargetRules Target) : base(Target) { | ||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; | ||
|
||
PublicIncludePaths.AddRange( | ||
new string[] { | ||
} | ||
); | ||
|
||
|
||
PrivateIncludePaths.AddRange( | ||
new string[] { | ||
} | ||
); | ||
|
||
|
||
PublicDependencyModuleNames.AddRange( | ||
new string[] | ||
{ | ||
"Core", | ||
} | ||
); | ||
|
||
|
||
PrivateDependencyModuleNames.AddRange( | ||
new string[] | ||
{ | ||
"CoreUObject", | ||
"Engine", | ||
"Slate", | ||
"SlateCore", | ||
} | ||
); | ||
|
||
|
||
DynamicallyLoadedModuleNames.AddRange( | ||
new string[] | ||
{ | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#include "FileSDK.h" | ||
|
||
#define LOCTEXT_NAMESPACE "FFileSDKModule" | ||
|
||
DEFINE_LOG_CATEGORY(LogFileSDK); | ||
|
||
void FFileSDKModule::StartupModule() { | ||
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module | ||
} | ||
|
||
void FFileSDKModule::ShutdownModule() { | ||
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, | ||
// we call this function before unloading the module. | ||
} | ||
|
||
#undef LOCTEXT_NAMESPACE | ||
|
||
IMPLEMENT_MODULE(FFileSDKModule, FileSDK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#include "FileSDKBPLibrary.h" | ||
#include "FileSDK.h" | ||
|
||
#include "HAL/FileManagerGeneric.h" | ||
|
||
UFileSDKBPLibrary::UFileSDKBPLibrary( | ||
const FObjectInitializer& ObjectInitializer | ||
) : Super(ObjectInitializer) { | ||
// | ||
} | ||
|
||
void UFileSDKBPLibrary::CreateFile( | ||
FString FileName, | ||
bool ClearContentsIfExists, | ||
bool CreateDirectoryTree | ||
) { | ||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); | ||
|
||
FString directoryName = FPaths::GetPath(FileName); | ||
bool directoryExists = PlatformFile.DirectoryExists(*directoryName); | ||
|
||
if (!directoryExists && CreateDirectoryTree) { | ||
FFileManagerGeneric::Get().MakeDirectory(*directoryName, true); | ||
} else if (!directoryExists) { | ||
UE_LOG( | ||
LogFileSDK, | ||
Fatal, | ||
TEXT("Cannot create file %s because directory %s doesn't exist. Ensure the directory exists before or enable 'CreateDirectoryTree'"), | ||
*FileName, | ||
*directoryName | ||
); | ||
} | ||
|
||
bool fileExists = PlatformFile.FileExists(*FileName); | ||
|
||
if ((ClearContentsIfExists && fileExists) || !fileExists) { | ||
FFileHelper::SaveStringToFile(FString(), *FileName); | ||
} | ||
} | ||
|
||
bool UFileSDKBPLibrary::DeleteFile(FString FileName) { | ||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); | ||
|
||
if (PlatformFile.FileExists(*FileName)) { | ||
return FFileManagerGeneric::Get().Delete(*FileName); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
bool UFileSDKBPLibrary::CreateDirectory( | ||
FString DirectoryName, | ||
bool CreateDirectoryTree | ||
) { | ||
return FFileManagerGeneric::Get().MakeDirectory(*DirectoryName, CreateDirectoryTree); | ||
} | ||
|
||
bool UFileSDKBPLibrary::DeleteDirectory( | ||
FString DirectoryName, | ||
bool Recursive | ||
) { | ||
return FFileManagerGeneric::Get().DeleteDirectory(*DirectoryName, false, Recursive); | ||
} | ||
|
||
bool UFileSDKBPLibrary::RenameFileOrDirectory( | ||
FString Source, | ||
FString Destination | ||
) { | ||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); | ||
|
||
return PlatformFile.MoveFile(*Destination, *Source); | ||
} | ||
|
||
bool UFileSDKBPLibrary::CopyFile( | ||
FString Source, | ||
FString Destination | ||
) { | ||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); | ||
|
||
return PlatformFile.CopyFile(*Destination, *Source); | ||
} | ||
|
||
bool UFileSDKBPLibrary::CopyDirectory( | ||
FString Source, | ||
FString Destination, | ||
bool OverwriteDestination | ||
) { | ||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); | ||
|
||
return PlatformFile.CopyDirectoryTree(*Destination, *Source, OverwriteDestination); | ||
} | ||
|
||
bool UFileSDKBPLibrary::ReadStringFromFile(FString FileName, FString & Content) { | ||
return FFileHelper::LoadFileToString(Content, *FileName); | ||
} | ||
|
||
bool UFileSDKBPLibrary::WriteStringToFile(FString FileName, FString Content, bool Append) { | ||
if (Append) { | ||
return FFileHelper::SaveStringToFile( | ||
Content, | ||
*FileName, | ||
FFileHelper::EEncodingOptions::AutoDetect, | ||
&IFileManager::Get(), | ||
std::ios_base::app | ||
); | ||
} else { | ||
return FFileHelper::SaveStringToFile(Content, *FileName); | ||
} | ||
} | ||
|
||
bool UFileSDKBPLibrary::WriteBytesToFile(FString FileName, TArray<uint8> Content) { | ||
return FFileHelper::SaveArrayToFile(Content, *FileName); | ||
} | ||
|
||
bool UFileSDKBPLibrary::ReadBytesFromFile(FString FileName, TArray<uint8> & Content) { | ||
return FFileHelper::LoadFileToArray(Content, *FileName); | ||
} | ||
|
||
TArray<FString> UFileSDKBPLibrary::GetFilesFromDirectory( | ||
FString DirectoryToSearch, | ||
FString FilterFilesWithExtension, | ||
bool SearchSubfolders | ||
) { | ||
TArray<FString> FileNames; | ||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); | ||
|
||
if (SearchSubfolders) { | ||
PlatformFile.FindFilesRecursively( | ||
FileNames, | ||
*DirectoryToSearch, | ||
*FilterFilesWithExtension | ||
); | ||
} else { | ||
PlatformFile.FindFiles( | ||
FileNames, | ||
*DirectoryToSearch, | ||
*FilterFilesWithExtension | ||
); | ||
} | ||
|
||
return FileNames; | ||
} | ||
|
||
void UFileSDKBPLibrary::GetFileOrDirectoryInfo(FString Path, FFileInfo & Info) { | ||
IPlatformFile & PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); | ||
|
||
FFileStatData data = PlatformFile.GetStatData(*Path); | ||
|
||
Info.CreationTime = data.CreationTime; | ||
Info.AccessTime = data.AccessTime; | ||
Info.ModificationTime = data.ModificationTime; | ||
Info.FileSize = data.FileSize; | ||
Info.bIsDirectory = data.bIsDirectory; | ||
Info.bIsReadOnly = data.bIsReadOnly; | ||
Info.bIsValid = data.bIsValid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include "FileInfo.generated.h" | ||
|
||
USTRUCT(BlueprintType) | ||
struct FFileInfo { | ||
GENERATED_USTRUCT_BODY(); | ||
|
||
/** The time that the file or directory was originally created, or FDateTime::MinValue if the creation time is unknown */ | ||
UPROPERTY(BlueprintReadOnly) | ||
FDateTime CreationTime; | ||
|
||
/** The time that the file or directory was last accessed, or FDateTime::MinValue if the access time is unknown */ | ||
UPROPERTY(BlueprintReadOnly) | ||
FDateTime AccessTime; | ||
|
||
/** The time the the file or directory was last modified, or FDateTime::MinValue if the modification time is unknown */ | ||
UPROPERTY(BlueprintReadOnly) | ||
FDateTime ModificationTime; | ||
|
||
/** Size of the file (in bytes), or -1 if the file size is unknown */ | ||
UPROPERTY(BlueprintReadOnly) | ||
int64 FileSize; | ||
|
||
/** True if this data is for a directory, false if it's for a file */ | ||
UPROPERTY(BlueprintReadOnly) | ||
bool bIsDirectory; | ||
|
||
/** True if this file is read-only */ | ||
UPROPERTY(BlueprintReadOnly) | ||
bool bIsReadOnly; | ||
|
||
/** True if file or directory was found, false otherwise. Note that this value being true does not ensure that the other members are filled in with meaningful data, as not all file systems have access to all of this data */ | ||
UPROPERTY(BlueprintReadOnly) | ||
bool bIsValid; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "Modules/ModuleManager.h" | ||
|
||
DECLARE_LOG_CATEGORY_EXTERN(LogFileSDK, Log, All); | ||
|
||
class FFileSDKModule : public IModuleInterface { | ||
public: | ||
|
||
/** IModuleInterface implementation */ | ||
virtual void StartupModule() override; | ||
virtual void ShutdownModule() override; | ||
}; |
Oops, something went wrong.