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.

73 lines
2.8 KiB

  1. #pragma once
  2. #include "WFULambdaRunnable.h"
  3. #include "WindowsFileUtilityFunctionLibrary.generated.h"
  4. //Struct to Track which delegate is watching files
  5. struct FWatcher
  6. {
  7. UObject* Delegate;
  8. FString Path;
  9. WFULambdaRunnable* Runnable = nullptr;
  10. FThreadSafeBool ShouldRun = true;
  11. };
  12. inline bool operator==(const FWatcher& lhs, const FWatcher& rhs)
  13. {
  14. return lhs.Delegate == rhs.Delegate;
  15. }
  16. UCLASS(ClassGroup = WindowsFileUtility, Blueprintable)
  17. class WINDOWSFILEUTILITY_API UWindowsFileUtilityFunctionLibrary : public UBlueprintFunctionLibrary
  18. {
  19. GENERATED_UCLASS_BODY()
  20. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  21. static bool DoesFileExist(const FString& FullPath);
  22. /*Expects full path including name. you can use this function to rename files.*/
  23. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  24. static bool MoveFileTo(const FString& From, const FString& To);
  25. /*Expects full path including folder name.*/
  26. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  27. static bool CreateDirectoryAt(const FString& FullPath);
  28. /*Deletes file (not directory). Expects full path.*/
  29. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  30. static bool DeleteFileAt(const FString& FullPath);
  31. /*Deletes empty folders only. Expects full path.*/
  32. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  33. static bool DeleteEmptyFolder(const FString& FullPath);
  34. /*Dangerous function, not exposed to blueprint. */
  35. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  36. static bool DeleteFolderRecursively(const FString& FullPath);
  37. /** Watch a folder for change. WatcherDelegate should respond to FolderWatchInterface*/
  38. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  39. static void WatchFolder(const FString& FullPath, UObject* WatcherDelegate);
  40. /** Stop watching a folder for change. WatcherDelegate should respond to FolderWatchInterface*/
  41. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  42. static void StopWatchingFolder(const FString& FullPath, UObject* WatcherDelegate);
  43. /** List the contents, expects UFileListInterface*/
  44. UFUNCTION(BlueprintCallable, Category = WindowsFileUtility)
  45. static void ListContentsOfFolder(const FString& FullPath, UObject* ListDelegate);
  46. //Convenience C++ callback
  47. static void ListContentsOfFolderToCallback(const FString& FullPath, TFunction<void(const TArray<FString>&, const TArray<FString>&)> OnListCompleteCallback);
  48. //Todo: add watch folder with threadsafe boolean passthrough
  49. //static void ListContentsOfFolderToCallback(const FString& FullPath, TFunction<void(const TArray<FString>&, const TArray<FString>&)> OnListCompleteCallback);
  50. private:
  51. static void WatchFolderOnBgThread(const FString& FullPath, const FWatcher* Watcher);
  52. static TMap<FString, TArray<FWatcher>> Watchers;
  53. };