mirror of
https://github.com/Theaninova/BeatLanguageMapper.git
synced 2026-01-20 17:03:49 +00:00
Mk2Rev1
various bugfixes and such. also bookmarks, temp song loaderm and undo overhaul with near complete multiplayer, but menu items disabled. i really wish i could split this into multiple commits, but i don't know how to work unreal.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ModuleManager.h"
|
||||
|
||||
|
||||
/**
|
||||
* The public interface to this module. In most cases, this interface is only public to sibling modules
|
||||
* within this plugin.
|
||||
*/
|
||||
class IWindowsFileUtility : public IModuleInterface
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Singleton-like access to this module's interface. This is just for convenience!
|
||||
* Beware of calling this during the shutdown phase, though. Your module might have been unloaded already.
|
||||
*
|
||||
* @return Returns singleton instance, loading the module on demand if needed
|
||||
*/
|
||||
static inline IWindowsFileUtility& Get()
|
||||
{
|
||||
return FModuleManager::LoadModuleChecked< IWindowsFileUtility >("WindowsFileUtility");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true.
|
||||
*
|
||||
* @return True if the module is loaded and ready to use
|
||||
*/
|
||||
static inline bool IsAvailable()
|
||||
{
|
||||
return FModuleManager::Get().IsModuleLoaded("WindowsFileUtility");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WFUFileListInterface.generated.h"
|
||||
|
||||
UINTERFACE(MinimalAPI)
|
||||
class UWFUFileListInterface : public UInterface
|
||||
{
|
||||
GENERATED_UINTERFACE_BODY()
|
||||
};
|
||||
|
||||
class WINDOWSFILEUTILITY_API IWFUFileListInterface
|
||||
{
|
||||
GENERATED_IINTERFACE_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Called when a file has been found inside the folder of choice
|
||||
* @param FileName of the found file.
|
||||
* @param Size in bytes of the found file.
|
||||
* @param FilePath of the file that was found
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category = FolderWatchEvent)
|
||||
void OnListFileFound(const FString& FileName, int32 ByteCount, const FString& FilePath);
|
||||
|
||||
/**
|
||||
* Called when a directory has been found inside the folder of choice
|
||||
* @param DirectoryName of the found directory.
|
||||
* @param FilePath of the file that was found
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category = FolderWatchEvent)
|
||||
void OnListDirectoryFound(const FString& DirectoryName, const FString& FilePath);
|
||||
|
||||
/**
|
||||
* Called when the listing operation has completed.
|
||||
* @param DirectoryPath Path of the directory
|
||||
* @param Files array of files found
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category = FolderWatchEvent)
|
||||
void OnListDone(const FString& DirectoryPath, const TArray<FString>& Files, const TArray<FString>& Folders);
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WFUFolderWatchInterface.generated.h"
|
||||
|
||||
UINTERFACE(MinimalAPI)
|
||||
class UWFUFolderWatchInterface : public UInterface
|
||||
{
|
||||
GENERATED_UINTERFACE_BODY()
|
||||
};
|
||||
|
||||
class WINDOWSFILEUTILITY_API IWFUFolderWatchInterface
|
||||
{
|
||||
GENERATED_IINTERFACE_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Called when a file inside the folder has changed
|
||||
* @param FilePath Path of the file that has changed
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category = FolderWatchEvent)
|
||||
void OnFileChanged(const FString& FileName, const FString& FilePath);
|
||||
|
||||
/**
|
||||
* Called when a directory inside the folder has changed
|
||||
* @param FilePath Path of the file that has changed
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category = FolderWatchEvent)
|
||||
void OnDirectoryChanged(const FString& DirectoryName, const FString& DirectoryPath);
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
Long duration lambda wrapper, which are generally not supported by the taskgraph system. New thread per lambda and they will auto-delete upon
|
||||
completion.
|
||||
*/
|
||||
class WINDOWSFILEUTILITY_API WFULambdaRunnable : public FRunnable
|
||||
{
|
||||
private:
|
||||
/** Thread to run the worker FRunnable on */
|
||||
FRunnableThread* Thread;
|
||||
|
||||
// Used to give each thread a unique stat group
|
||||
static uint64 ThreadNumber;
|
||||
|
||||
//Lambda function pointer
|
||||
TFunction< void()> FunctionPointer;
|
||||
|
||||
// A queued threadpool used to run lambda's in the background. This has lazy initialization and is meant to be used with
|
||||
// - AddLambdaToQueue
|
||||
// - RemoveLAmbdaFromQueue
|
||||
static FQueuedThreadPool* ThreadPool;
|
||||
public:
|
||||
//Constructor / Destructor
|
||||
WFULambdaRunnable(TFunction< void()> InFunction);
|
||||
virtual ~WFULambdaRunnable();
|
||||
|
||||
// Begin FRunnable interface.
|
||||
virtual uint32 Run() override;
|
||||
virtual void Exit() override;
|
||||
// End FRunnable interface
|
||||
|
||||
// Initializes the queued thread pool. This is called lazily when the first task is added to the queue
|
||||
// but can also be called by hand to initialize with a specific number of threads. The default number
|
||||
// of threads is FPlatformMisc::NumberOfIOWorkerThreadsToSpawn() which last I checked was hard-coded
|
||||
// at 4. <NOTE> that if you want to call this by hand, you need to do so before ever calling AddLambdaToQueue.
|
||||
static void InitThreadPool(int32 NumberOfThreads);
|
||||
|
||||
/** Makes sure this thread has stopped properly */
|
||||
void EnsureCompletion();
|
||||
|
||||
// Runs the passed lambda on the background thread, new thread per call
|
||||
static WFULambdaRunnable* RunLambdaOnBackGroundThread(TFunction< void()> InFunction);
|
||||
|
||||
// Adds a lambda to be ran on the queued thread pool. Returns a pointer to IQueuedWork which
|
||||
// can be used to later remove the queued job from the pool assuming it hasn't been processed.
|
||||
static IQueuedWork* AddLambdaToQueue(TFunction< void()> InFunction);
|
||||
|
||||
// Removes a lambda from the thread queue
|
||||
static bool RemoveLambdaFromQueue(IQueuedWork* Work);
|
||||
|
||||
// Runs a short lambda on the game thread via task graph system
|
||||
static FGraphEventRef RunShortLambdaOnGameThread(TFunction< void()> InFunction);
|
||||
|
||||
private:
|
||||
// This was yanked from Engine/Source/Runtime/Core/Public/Async/Async.h (originally called AsyncPool(..)). FQueuedThreadPool doesn't have
|
||||
// much documentation, so using the engine code as reference, pretty much everyone seems to use this templated function to queue up work.
|
||||
// It was modified to return an IQueuedWork instead of a TFuture to be more convenient for actually removing items from the queue.
|
||||
template<typename ResultType>
|
||||
static IQueuedWork* AsyncLambdaPool(FQueuedThreadPool& ThreadPool, TFunction<ResultType()> Function, TFunction<void()> CompletionCallback = TFunction<void()>())
|
||||
{
|
||||
TPromise<ResultType> Promise(MoveTemp(CompletionCallback));
|
||||
TFuture<ResultType> Future = Promise.GetFuture();
|
||||
IQueuedWork* Work = new TAsyncQueuedWork<ResultType>(MoveTemp(Function), MoveTemp(Promise));
|
||||
ThreadPool.AddQueuedWork(Work);
|
||||
return Work;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include "WFULambdaRunnable.h"
|
||||
#include "WindowsFileUtilityFunctionLibrary.generated.h"
|
||||
|
||||
//Struct to Track which delegate is watching files
|
||||
struct FWatcher
|
||||
{
|
||||
UObject* Delegate;
|
||||
|
||||
FString Path;
|
||||
|
||||
WFULambdaRunnable* Runnable = nullptr;
|
||||
|
||||
FThreadSafeBool ShouldRun = true;
|
||||
|
||||
};
|
||||
|
||||
inline bool operator==(const FWatcher& lhs, const FWatcher& rhs)
|
||||
{
|
||||
return lhs.Delegate == rhs.Delegate;
|
||||
}
|
||||
|
||||
UCLASS(ClassGroup = WindowsFileUtility, Blueprintable)
|
||||
class WINDOWSFILEUTILITY_API UWindowsFileUtilityFunctionLibrary : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_UCLASS_BODY()
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static bool DoesFileExist(const FString& FullPath);
|
||||
|
||||
/*Expects full path including name. you can use this function to rename files.*/
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static bool MoveFileTo(const FString& From, const FString& To);
|
||||
|
||||
/*Expects full path including folder name.*/
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static bool CreateDirectoryAt(const FString& FullPath);
|
||||
|
||||
/*Deletes file (not directory). Expects full path.*/
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static bool DeleteFileAt(const FString& FullPath);
|
||||
|
||||
/*Deletes empty folders only. Expects full path.*/
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static bool DeleteEmptyFolder(const FString& FullPath);
|
||||
|
||||
/*Dangerous function, not exposed to blueprint. */
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static bool DeleteFolderRecursively(const FString& FullPath);
|
||||
|
||||
/** Watch a folder for change. WatcherDelegate should respond to FolderWatchInterface*/
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static void WatchFolder(const FString& FullPath, UObject* WatcherDelegate);
|
||||
|
||||
/** Stop watching a folder for change. WatcherDelegate should respond to FolderWatchInterface*/
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static void StopWatchingFolder(const FString& FullPath, UObject* WatcherDelegate);
|
||||
|
||||
/** List the contents, expects UFileListInterface*/
|
||||
UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
|
||||
static void ListContentsOfFolder(const FString& FullPath, UObject* ListDelegate);
|
||||
|
||||
//Convenience C++ callback
|
||||
static void ListContentsOfFolderToCallback(const FString& FullPath, TFunction<void(const TArray<FString>&, const TArray<FString>&)> OnListCompleteCallback);
|
||||
|
||||
//Todo: add watch folder with threadsafe boolean passthrough
|
||||
//static void ListContentsOfFolderToCallback(const FString& FullPath, TFunction<void(const TArray<FString>&, const TArray<FString>&)> OnListCompleteCallback);
|
||||
|
||||
private:
|
||||
static void WatchFolderOnBgThread(const FString& FullPath, const FWatcher* Watcher);
|
||||
static TMap<FString, TArray<FWatcher>> Watchers;
|
||||
};
|
||||
Reference in New Issue
Block a user