diff --git a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp index 8db294611..eb5469b47 100644 --- a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp @@ -229,7 +229,7 @@ bool AndroidPlatformTools::OnPostProcess(CookingData& data) } // Copy fresh Gradle project template - if (FileSystem::CopyDirectory(data.OriginalOutputPath, platformDataPath / TEXT("Project"), true)) + if (FileSystem::CopyDirectory(data.OriginalOutputPath, platformDataPath / TEXT("Project"))) { LOG(Error, "Failed to deploy Gradle project to {0} from {1}", data.OriginalOutputPath, platformDataPath); return true; diff --git a/Source/Editor/Cooker/Platform/UWP/UWPPlatformTools.cpp b/Source/Editor/Cooker/Platform/UWP/UWPPlatformTools.cpp index ebbf9840c..789b810e9 100644 --- a/Source/Editor/Cooker/Platform/UWP/UWPPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/UWP/UWPPlatformTools.cpp @@ -123,7 +123,7 @@ bool UWPPlatformTools::OnDeployBinaries(CookingData& data) const auto srcAssetsPath = uwpDataPath / TEXT("Assets"); if (!FileSystem::DirectoryExists(dstAssetsPath)) { - if (FileSystem::CopyDirectory(dstAssetsPath, srcAssetsPath, true)) + if (FileSystem::CopyDirectory(dstAssetsPath, srcAssetsPath)) { data.Error(TEXT("Failed to copy Assets directory.")); return true; diff --git a/Source/Editor/Cooker/Platform/iOS/iOSPlatformTools.cpp b/Source/Editor/Cooker/Platform/iOS/iOSPlatformTools.cpp index a54676a64..45ea18ed2 100644 --- a/Source/Editor/Cooker/Platform/iOS/iOSPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/iOS/iOSPlatformTools.cpp @@ -203,7 +203,7 @@ bool iOSPlatformTools::OnPostProcess(CookingData& data) return true; // Copy fresh XCode project template - if (FileSystem::CopyDirectory(data.OriginalOutputPath, platformDataPath / TEXT("Project"), true)) + if (FileSystem::CopyDirectory(data.OriginalOutputPath, platformDataPath / TEXT("Project"))) { LOG(Error, "Failed to deploy XCode project to {0} from {1}", data.OriginalOutputPath, platformDataPath); return true; diff --git a/Source/Editor/Cooker/Steps/DeployDataStep.cpp b/Source/Editor/Cooker/Steps/DeployDataStep.cpp index b1a3201cd..84a36e5c6 100644 --- a/Source/Editor/Cooker/Steps/DeployDataStep.cpp +++ b/Source/Editor/Cooker/Steps/DeployDataStep.cpp @@ -156,12 +156,12 @@ bool DeployDataStep::Perform(CookingData& data) FileSystem::CopyFile(dstDotnet / TEXT("THIRD-PARTY-NOTICES.TXT"), srcDotnet / TEXT("THIRD-PARTY-NOTICES.TXT")); if (usAOT) { - failed |= EditorUtilities::CopyDirectoryIfNewer(dstDotnet, srcDotnet / TEXT("shared/Microsoft.NETCore.App") / version, true); + failed |= EditorUtilities::CopyDirectoryIfNewer(dstDotnet, srcDotnet / TEXT("shared/Microsoft.NETCore.App") / version); } else { #if 1 - failed |= EditorUtilities::CopyDirectoryIfNewer(dstDotnet / TEXT("host/fxr") / version, srcDotnet / TEXT("host/fxr") / version, true); + failed |= EditorUtilities::CopyDirectoryIfNewer(dstDotnet / TEXT("host/fxr") / version, srcDotnet / TEXT("host/fxr") / version); #else // TODO: hostfxr for target platform should be copied from nuget package location: microsoft.netcore.app.runtime.//runtimes//native/hostfxr.dll String dstHostfxr = dstDotnet / TEXT("host/fxr") / version; @@ -330,7 +330,7 @@ bool DeployDataStep::Perform(CookingData& data) data.Error(TEXT("Missing Mono runtime data files.")); return true; } - if (FileSystem::CopyDirectory(dstMono, srcMono, true)) + if (FileSystem::CopyDirectory(dstMono, srcMono)) { data.Error(TEXT("Failed to copy Mono runtime data files.")); return true; @@ -416,7 +416,7 @@ bool DeployDataStep::Perform(CookingData& data) for (auto& e : buildSettings.AdditionalAssetFolders) { String path = FileSystem::ConvertRelativePathToAbsolute(Globals::ProjectFolder, e); - if (FileSystem::DirectoryGetFiles(files, path, TEXT("*"), DirectorySearchOption::AllDirectories)) + if (FileSystem::DirectoryGetFiles(files, path)) { data.Error(TEXT("Failed to find additional assets to deploy.")); return true; diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 09253851c..d0bfe2765 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -141,7 +141,7 @@ bool Editor::CheckProjectUpgrade() FileSystem::DeleteDirectory(tempSourceSetup); FileSystem::CreateDirectory(tempSourceSetup); Array files; - FileSystem::DirectoryGetFiles(files, sourceFolder, TEXT("*"), DirectorySearchOption::AllDirectories); + FileSystem::DirectoryGetFiles(files, sourceFolder); bool useEditorModule = false; for (auto& file : files) { @@ -159,7 +159,7 @@ bool Editor::CheckProjectUpgrade() FileSystem::CopyFile(tempSourceFile, file); } FileSystem::DeleteDirectory(sourceFolder); - FileSystem::CopyDirectory(sourceFolder, tempSourceSetup, true); + FileSystem::CopyDirectory(sourceFolder, tempSourceSetup); FileSystem::DeleteDirectory(tempSourceSetup); // Generate module files @@ -364,7 +364,7 @@ bool Editor::BackupProject() LOG(Info, "Backup project to \"{0}\"", dstPath); // Copy everything - return FileSystem::CopyDirectory(dstPath, Globals::ProjectFolder, true); + return FileSystem::CopyDirectory(dstPath, Globals::ProjectFolder); } int32 Editor::LoadProduct() diff --git a/Source/Editor/Utilities/EditorUtilities.h b/Source/Editor/Utilities/EditorUtilities.h index 2357f995a..ed57d01ab 100644 --- a/Source/Editor/Utilities/EditorUtilities.h +++ b/Source/Editor/Utilities/EditorUtilities.h @@ -79,5 +79,5 @@ public: static bool ReplaceInFile(const StringView& file, const Dictionary& replaceMap); static bool CopyFileIfNewer(const StringView& dst, const StringView& src); - static bool CopyDirectoryIfNewer(const StringView& dst, const StringView& src, bool withSubDirectories); + static bool CopyDirectoryIfNewer(const StringView& dst, const StringView& src, bool withSubDirectories = true); }; diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index 92e1baf7b..37e77fa64 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -1067,7 +1067,7 @@ bool findAsset(const Guid& id, const String& directory, Array& tmpCache, { // Get all asset files tmpCache.Clear(); - if (FileSystem::DirectoryGetFiles(tmpCache, directory, TEXT("*"), DirectorySearchOption::AllDirectories)) + if (FileSystem::DirectoryGetFiles(tmpCache, directory)) { if (FileSystem::DirectoryExists(directory)) LOG(Error, "Cannot query files in folder '{0}'.", directory); diff --git a/Source/Engine/Platform/Android/AndroidFileSystem.cpp b/Source/Engine/Platform/Android/AndroidFileSystem.cpp index f73048d5b..1cea6715e 100644 --- a/Source/Engine/Platform/Android/AndroidFileSystem.cpp +++ b/Source/Engine/Platform/Android/AndroidFileSystem.cpp @@ -167,18 +167,18 @@ bool AndroidFileSystem::DirectoryGetFiles(Array& results, const String& return getFilesFromDirectoryAll(results, pathANSI.Get(), searchPatternANSI.Get()); } -bool AndroidFileSystem::GetChildDirectories(Array& results, const String& directory) +bool AndroidFileSystem::GetChildDirectories(Array& results, const String& path) { size_t pathLength; struct stat statPath, statEntry; struct dirent* entry; - const StringAsANSI<> pathANSI(*directory, directory.Length()); - const char* path = pathANSI.Get(); + const StringAsANSI<> pathANSI(*path, path.Length()); + const char* pathStr = pathANSI.Get(); // Stat for the path - stat(path, &statPath); + stat(pathStr, &statPath); - // If path does not exists or is not dir - exit with status -1 + // If path does not exist or is not dir - exit with status -1 if (S_ISDIR(statPath.st_mode) == 0) { // Is not directory @@ -186,7 +186,7 @@ bool AndroidFileSystem::GetChildDirectories(Array& results, const String } // If not possible to read the directory for this user - DIR* dir = opendir(path); + DIR* dir = opendir(pathStr); if (dir == nullptr) { // Cannot open directory @@ -194,7 +194,7 @@ bool AndroidFileSystem::GetChildDirectories(Array& results, const String } // The length of the path - pathLength = strlen(path); + pathLength = strlen(pathStr); // Iteration through entries in the directory while ((entry = readdir(dir)) != nullptr) @@ -204,20 +204,20 @@ bool AndroidFileSystem::GetChildDirectories(Array& results, const String continue; // Determinate a full path of an entry - char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); - strcpy(full_path, path); - strcat(full_path, "/"); - strcat(full_path, entry->d_name); + char fullPath[256]; + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(fullPath)); + strcpy(fullPath, pathStr); + strcat(fullPath, "/"); + strcat(fullPath, entry->d_name); // Stat for the entry - stat(full_path, &statEntry); + stat(fullPath, &statEntry); // Check for directory if (S_ISDIR(statEntry.st_mode) != 0) { // Add directory - results.Add(String(full_path)); + results.Add(String(fullPath)); } } diff --git a/Source/Engine/Platform/Android/AndroidFileSystem.h b/Source/Engine/Platform/Android/AndroidFileSystem.h index 0f3b0158c..6e986dc5b 100644 --- a/Source/Engine/Platform/Android/AndroidFileSystem.h +++ b/Source/Engine/Platform/Android/AndroidFileSystem.h @@ -12,12 +12,11 @@ class FLAXENGINE_API AndroidFileSystem : public FileSystemBase { public: - static bool CreateDirectory(const StringView& path); static bool DeleteDirectory(const String& path, bool deleteContents = true); static bool DirectoryExists(const StringView& path); - static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern, DirectorySearchOption option = DirectorySearchOption::AllDirectories); - static bool GetChildDirectories(Array& results, const String& directory); + static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern = TEXT("*"), DirectorySearchOption option = DirectorySearchOption::AllDirectories); + static bool GetChildDirectories(Array& results, const String& path); static bool FileExists(const StringView& path); static bool DeleteFile(const StringView& path); static uint64 GetFileSize(const StringView& path); @@ -25,25 +24,10 @@ public: static bool SetReadOnly(const StringView& path, bool isReadOnly); static bool MoveFile(const StringView& dst, const StringView& src, bool overwrite = false); static bool CopyFile(const StringView& dst, const StringView& src); - -public: - - /// - /// Gets last time when file has been modified (in UTC). - /// - /// The file path to check. - /// The last write time or DateTime::MinValue() if cannot get data. static DateTime GetFileLastEditTime(const StringView& path); - - /// - /// Gets the special folder path. - /// - /// The folder type. - /// The result full path. static void GetSpecialFolderPath(const SpecialFolder type, String& result); private: - static bool getFilesFromDirectoryTop(Array& results, const char* path, const char* searchPattern); static bool getFilesFromDirectoryAll(Array& results, const char* path, const char* searchPattern); }; diff --git a/Source/Engine/Platform/Apple/AppleFileSystem.cpp b/Source/Engine/Platform/Apple/AppleFileSystem.cpp index c3e34c683..6c87428cc 100644 --- a/Source/Engine/Platform/Apple/AppleFileSystem.cpp +++ b/Source/Engine/Platform/Apple/AppleFileSystem.cpp @@ -145,19 +145,19 @@ bool AppleFileSystem::DirectoryGetFiles(Array& results, const String& pa return getFilesFromDirectoryAll(results, pathANSI.Get(), searchPatternANSI.Get()); } -bool AppleFileSystem::GetChildDirectories(Array& results, const String& directory) +bool AppleFileSystem::GetChildDirectories(Array& results, const String& path) { size_t pathLength; DIR* dir; struct stat statPath, statEntry; struct dirent* entry; - const StringAsANSI<> pathANSI(*directory, directory.Length()); - const char* path = pathANSI.Get(); + const StringAsANSI<> pathANSI(*path, path.Length()); + const char* pathStr = pathANSI.Get(); // Stat for the path - stat(path, &statPath); + stat(pathStr, &statPath); - // If path does not exists or is not dir - exit with status -1 + // If path does not exist or is not dir - exit with status -1 if (S_ISDIR(statPath.st_mode) == 0) { // Is not directory @@ -165,14 +165,14 @@ bool AppleFileSystem::GetChildDirectories(Array& results, const String& } // If not possible to read the directory for this user - if ((dir = opendir(path)) == NULL) + if ((dir = opendir(pathStr)) == NULL) { // Cannot open directory return true; } // The length of the path - pathLength = strlen(path); + pathLength = strlen(pathStr); // Iteration through entries in the directory while ((entry = readdir(dir)) != NULL) @@ -182,20 +182,20 @@ bool AppleFileSystem::GetChildDirectories(Array& results, const String& continue; // Determinate a full path of an entry - char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); - strcpy(full_path, path); - strcat(full_path, "/"); - strcat(full_path, entry->d_name); + char fullPath[256]; + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(fullPath)); + strcpy(fullPath, path); + strcat(fullPath, "/"); + strcat(fullPath, entry->d_name); // Stat for the entry - stat(full_path, &statEntry); + stat(fullPath, &statEntry); // Check for directory if (S_ISDIR(statEntry.st_mode) != 0) { // Add directory - results.Add(String(full_path)); + results.Add(String(fullPath)); } } diff --git a/Source/Engine/Platform/Apple/AppleFileSystem.h b/Source/Engine/Platform/Apple/AppleFileSystem.h index 620945b3e..88440cd58 100644 --- a/Source/Engine/Platform/Apple/AppleFileSystem.h +++ b/Source/Engine/Platform/Apple/AppleFileSystem.h @@ -12,13 +12,12 @@ class FLAXENGINE_API AppleFileSystem : public FileSystemBase { public: - // [FileSystemBase] static bool CreateDirectory(const StringView& path); static bool DeleteDirectory(const String& path, bool deleteContents = true); static bool DirectoryExists(const StringView& path); - static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern, DirectorySearchOption option = DirectorySearchOption::AllDirectories); - static bool GetChildDirectories(Array& results, const String& directory); + static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern = TEXT("*"), DirectorySearchOption option = DirectorySearchOption::AllDirectories); + static bool GetChildDirectories(Array& results, const String& path); static bool FileExists(const StringView& path); static bool DeleteFile(const StringView& path); static uint64 GetFileSize(const StringView& path); @@ -26,25 +25,10 @@ public: static bool SetReadOnly(const StringView& path, bool isReadOnly); static bool MoveFile(const StringView& dst, const StringView& src, bool overwrite = false); static bool CopyFile(const StringView& dst, const StringView& src); - -public: - - /// - /// Gets last time when file has been modified (in UTC). - /// - /// The file path to check. - /// The last write time or DateTime::MinValue() if cannot get data. static DateTime GetFileLastEditTime(const StringView& path); - - /// - /// Gets the special folder path. - /// - /// The folder type. - /// The result full path. static void GetSpecialFolderPath(const SpecialFolder type, String& result); private: - static bool getFilesFromDirectoryTop(Array& results, const char* path, const char* searchPattern); static bool getFilesFromDirectoryAll(Array& results, const char* path, const char* searchPattern); }; diff --git a/Source/Engine/Platform/Base/FileSystemBase.cpp b/Source/Engine/Platform/Base/FileSystemBase.cpp index 759771bb9..763f8d3d0 100644 --- a/Source/Engine/Platform/Base/FileSystemBase.cpp +++ b/Source/Engine/Platform/Base/FileSystemBase.cpp @@ -195,7 +195,7 @@ String FileSystemBase::ConvertAbsolutePathToRelative(const String& basePath, con return output; } -bool FileSystemBase::CopyFile(const String& dst, const String& src) +bool FileSystemBase::CopyFile(const StringView& dst, const StringView& src) { // Open and create files const auto srcFile = File::Open(src, FileMode::OpenExisting, FileAccess::Read); @@ -247,7 +247,7 @@ uint64 FileSystemBase::GetDirectorySize(const StringView& path) { uint64 result = 0; Array files; - FileSystem::DirectoryGetFiles(files, path, TEXT("*"), DirectorySearchOption::AllDirectories); + FileSystem::DirectoryGetFiles(files, path); for (const String& file : files) result += FileSystem::GetFileSize(file); return result; diff --git a/Source/Engine/Platform/Base/FileSystemBase.h b/Source/Engine/Platform/Base/FileSystemBase.h index 4fc59b4a3..61084bf48 100644 --- a/Source/Engine/Platform/Base/FileSystemBase.h +++ b/Source/Engine/Platform/Base/FileSystemBase.h @@ -43,8 +43,133 @@ API_INJECT_CODE(cpp, "#include \"Engine/Platform/FileSystem.h\""); API_CLASS(Static, Name="FileSystem", Tag="NativeInvokeUseName") class FLAXENGINE_API FileSystemBase { -DECLARE_SCRIPTING_TYPE_MINIMAL(FileSystemBase); + DECLARE_SCRIPTING_TYPE_MINIMAL(FileSystemBase); + /// + /// Creates a new directory. + /// + /// Directory path + /// True if failed to create directory, otherwise false. + static bool CreateDirectory(const StringView& path) = delete; + + /// + /// Deletes an existing directory. + /// + /// Directory path + /// True if delete all subdirectories and files, otherwise false. + /// True if failed to delete directory, otherwise false. + static bool DeleteDirectory(const String& path, bool deleteContents = true) = delete; + + /// + /// Checks if directory exists. + /// + /// Directory path. + /// True if directory exists, otherwise false. + static bool DirectoryExists(const StringView& path) = delete; + + /// + /// Finds the paths of files that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories. + /// + /// Output list with all found file paths. Items are appended without clearing the list first. + /// Path of the directory to search in it. + /// Custom search pattern to use during that operation Use asterisk character (*) for name-based filtering (eg. `*.txt` to find all files with `.txt` extension).. + /// Additional search options that define rules. + /// True if an error occurred, otherwise false. + static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern = TEXT("*"), DirectorySearchOption option = DirectorySearchOption::AllDirectories) = delete; + + /// + /// Finds the paths of directories that are inside the specified directory. + /// + /// Output list with all found directory paths. Items are appended without clearing the list first. + /// Path of the directory to search in it. + /// True if an error occurred, otherwise false. + static bool GetChildDirectories(Array& results, const String& path) = delete; + + /// + /// Copies the directory. + /// + /// Destination path. + /// Source directory path. + /// True if copy subdirectories of the source folder, otherwise only top-level files will be cloned. + /// True if failed, otherwise false. + static bool CopyDirectory(const String& dst, const String& src, bool withSubDirectories = true); + + /// + /// Gets the size of the directory (in bytes) defined by size of all files contained by it. + /// + /// Directory path. + /// Amount of bytes in directory, or 0 if failed. + static uint64 GetDirectorySize(const StringView& path); + +public: + /// + /// Checks if a given file exists. + /// + /// File path to check. + /// True if file exists, otherwise false. + static bool FileExists(const StringView& path) = delete; + + /// + /// Deletes an existing file. + /// + /// File path + /// True if operation failed, otherwise false. + static bool DeleteFile(const StringView& path) = delete; + + /// + /// Gets the size of the file (in bytes). + /// + /// File path + /// Amount of bytes in file, or 0 if failed. + static uint64 GetFileSize(const StringView& path) = delete; + + /// + /// Checks if file is read-only. + /// + /// File path. + /// True if file is read-only, otherwise false. Returns false if failed or path is invalid. + static bool IsReadOnly(const StringView& path) = delete; + + /// + /// Sets file read-only flag. + /// + /// File path. + /// Read-only flag value to set. + /// True if operation failed, otherwise false. + static bool SetReadOnly(const StringView& path, bool isReadOnly) = delete; + + /// + /// Moves the file. + /// + /// Destination path. + /// Source file path. + /// True if allow overriding destination file if it already exists, otherwise action will fail. + /// True if failed, otherwise false. + static bool MoveFile(const StringView& dst, const StringView& src, bool overwrite = false) = delete; + + /// + /// Copies the file. + /// + /// Destination path. + /// Source file path. + /// True if failed, otherwise false. + static bool CopyFile(const StringView& dst, const StringView& src); + + /// + /// Gets last time when file has been modified (in UTC). + /// + /// The file path to check. + /// The last write time or DateTime::MinValue() if cannot get data. + static DateTime GetFileLastEditTime(const StringView& path) = delete; + + /// + /// Gets the special folder path. + /// + /// The folder type. + /// The result full path. + static void GetSpecialFolderPath(const SpecialFolder type, String& result) = delete; + +public: /// /// Displays a standard dialog box that prompts the user to open a file(s). /// @@ -97,28 +222,26 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(FileSystemBase); API_FUNCTION() static bool ShowFileExplorer(const StringView& path); public: - static void SaveBitmapToFile(byte* data, uint32 width, uint32 height, uint32 bitsPerPixel, const uint32 padding, const String& path); public: - static bool AreFilePathsEqual(const StringView& path1, const StringView& path2); /// - /// Normalize input path for valid path name for current platform file system + /// Normalizes input path for valid path name for current platform file system. /// /// Path to normalize static void NormalizePath(String& path); /// - /// Check if path type is relative + /// Checks if path type is relative. /// /// Input path to check /// True if input path is relative one, otherwise false static bool IsRelative(const StringView& path); /// - /// Retrieves file extension (without a dot) + /// Retrieves file extension (without a dot). /// /// Input path to process /// File extension @@ -131,22 +254,15 @@ public: static void GetTempFilePath(String& tmpPath); public: - - static bool CopyFile(const String& dst, const String& src); - static bool CopyDirectory(const String& dst, const String& src, bool withSubDirectories); - static uint64 GetDirectorySize(const StringView& path); - -public: - /// - /// Converts path relative to the engine startup folder into absolute path + /// Converts path relative to the engine startup folder into absolute path. /// /// Path relative to the engine directory /// Absolute path static String ConvertRelativePathToAbsolute(const String& path); /// - /// Converts path relative to basePath into absolute path + /// Converts path relative to basePath into absolute path. /// /// Base path /// Path relative to basePath @@ -154,14 +270,14 @@ public: static String ConvertRelativePathToAbsolute(const String& basePath, const String& path); /// - /// Converts absolute path into relative path to engine startup folder + /// Converts absolute path into relative path to engine startup folder. /// /// Absolute path /// Relative path static String ConvertAbsolutePathToRelative(const String& path); /// - /// Converts absolute path into relative path to basePath + /// Converts absolute path into relative path to basePath. /// /// Base path /// Absolute path @@ -169,6 +285,5 @@ public: static String ConvertAbsolutePathToRelative(const String& basePath, const String& path); private: - static bool DirectoryCopyHelper(const String& dst, const String& src, bool withSubDirectories); }; diff --git a/Source/Engine/Platform/Linux/LinuxFileSystem.cpp b/Source/Engine/Platform/Linux/LinuxFileSystem.cpp index 26ee15a48..728b2c41b 100644 --- a/Source/Engine/Platform/Linux/LinuxFileSystem.cpp +++ b/Source/Engine/Platform/Linux/LinuxFileSystem.cpp @@ -291,17 +291,17 @@ bool LinuxFileSystem::DirectoryGetFiles(Array& results, const String& pa return getFilesFromDirectoryAll(results, pathANSI.Get(), searchPatternANSI.Get()); } -bool LinuxFileSystem::GetChildDirectories(Array& results, const String& directory) +bool LinuxFileSystem::GetChildDirectories(Array& results, const String& path) { size_t pathLength; DIR* dir; struct stat statPath, statEntry; struct dirent* entry; - const StringAsUTF8<> pathANSI(*directory, directory.Length()); - const char* path = pathANSI.Get(); + const StringAsUTF8<> pathANSI(*path, path.Length()); + const char* pathStr = pathANSI.Get(); // Stat for the path - stat(path, &statPath); + stat(pathStr, &statPath); // If path does not exists or is not dir - exit with status -1 if (S_ISDIR(statPath.st_mode) == 0) @@ -311,14 +311,14 @@ bool LinuxFileSystem::GetChildDirectories(Array& results, const String& } // If not possible to read the directory for this user - if ((dir = opendir(path)) == NULL) + if ((dir = opendir(pathStr)) == NULL) { // Cannot open directory return true; } // The length of the path - pathLength = strlen(path); + pathLength = strlen(pathStr); // Iteration through entries in the directory while ((entry = readdir(dir)) != NULL) @@ -328,20 +328,20 @@ bool LinuxFileSystem::GetChildDirectories(Array& results, const String& continue; // Determinate a full path of an entry - char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); - strcpy(full_path, path); - strcat(full_path, "/"); - strcat(full_path, entry->d_name); + char fullPath[256]; + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(fullPath)); + strcpy(fullPath, path); + strcat(fullPath, "/"); + strcat(fullPath, entry->d_name); // Stat for the entry - stat(full_path, &statEntry); + stat(fullPath, &statEntry); // Check for directory if (S_ISDIR(statEntry.st_mode) != 0) { // Add directory - results.Add(String(full_path)); + results.Add(String(fullPath)); } } diff --git a/Source/Engine/Platform/Linux/LinuxFileSystem.h b/Source/Engine/Platform/Linux/LinuxFileSystem.h index cf360f4d2..fbb204ec6 100644 --- a/Source/Engine/Platform/Linux/LinuxFileSystem.h +++ b/Source/Engine/Platform/Linux/LinuxFileSystem.h @@ -12,7 +12,6 @@ class FLAXENGINE_API LinuxFileSystem : public FileSystemBase { public: - // [FileSystemBase] static bool ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array& filenames); static bool ShowBrowseFolderDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& title, String& path); @@ -20,8 +19,8 @@ public: static bool CreateDirectory(const StringView& path); static bool DeleteDirectory(const String& path, bool deleteContents = true); static bool DirectoryExists(const StringView& path); - static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern, DirectorySearchOption option = DirectorySearchOption::AllDirectories); - static bool GetChildDirectories(Array& results, const String& directory); + static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern = TEXT("*"), DirectorySearchOption option = DirectorySearchOption::AllDirectories); + static bool GetChildDirectories(Array& results, const String& path); static bool FileExists(const StringView& path); static bool DeleteFile(const StringView& path); static bool MoveFileToRecycleBin(const StringView& path); @@ -30,25 +29,10 @@ public: static bool SetReadOnly(const StringView& path, bool isReadOnly); static bool MoveFile(const StringView& dst, const StringView& src, bool overwrite = false); static bool CopyFile(const StringView& dst, const StringView& src); - -public: - - /// - /// Gets last time when file has been modified (in UTC). - /// - /// The file path to check. - /// The last write time or DateTime::MinValue() if cannot get data. static DateTime GetFileLastEditTime(const StringView& path); - - /// - /// Gets the special folder path. - /// - /// The folder type. - /// The result full path. static void GetSpecialFolderPath(const SpecialFolder type, String& result); - -private: +private: static bool UrnEncodePath(const char *path, char *result, int maxLength); static bool getFilesFromDirectoryTop(Array& results, const char* path, const char* searchPattern); static bool getFilesFromDirectoryAll(Array& results, const char* path, const char* searchPattern); diff --git a/Source/Engine/Platform/Mac/MacFileSystem.h b/Source/Engine/Platform/Mac/MacFileSystem.h index 0ea6a26cb..8cd8c45f4 100644 --- a/Source/Engine/Platform/Mac/MacFileSystem.h +++ b/Source/Engine/Platform/Mac/MacFileSystem.h @@ -12,7 +12,6 @@ class FLAXENGINE_API MacFileSystem : public AppleFileSystem { public: - // [AppleFileSystem] static bool ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array& filenames); static bool ShowSaveFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array& filenames); diff --git a/Source/Engine/Platform/UWP/UWPFileSystem.h b/Source/Engine/Platform/UWP/UWPFileSystem.h index 08807d4e1..4d55c6d00 100644 --- a/Source/Engine/Platform/UWP/UWPFileSystem.h +++ b/Source/Engine/Platform/UWP/UWPFileSystem.h @@ -12,12 +12,7 @@ class FLAXENGINE_API UWPFileSystem : public Win32FileSystem { public: - - /// - /// Gets the special folder path. - /// - /// The folder type. - /// The result full path. + // [FileSystemBase] static void GetSpecialFolderPath(const SpecialFolder type, String& result); }; diff --git a/Source/Engine/Platform/Win32/Win32FileSystem.cpp b/Source/Engine/Platform/Win32/Win32FileSystem.cpp index ed11e0f90..396e37363 100644 --- a/Source/Engine/Platform/Win32/Win32FileSystem.cpp +++ b/Source/Engine/Platform/Win32/Win32FileSystem.cpp @@ -129,11 +129,11 @@ bool Win32FileSystem::DirectoryGetFiles(Array& results, const String& pa return getFilesFromDirectoryAll(results, path, searchPattern); } -bool Win32FileSystem::GetChildDirectories(Array& results, const String& directory) +bool Win32FileSystem::GetChildDirectories(Array& results, const String& path) { // Try to find first file WIN32_FIND_DATA info; - String pattern = directory / TEXT('*'); + String pattern = path / TEXT('*'); const HANDLE handle = FindFirstFileW(*pattern, &info); if (INVALID_HANDLE_VALUE == handle) { @@ -151,7 +151,7 @@ bool Win32FileSystem::GetChildDirectories(Array& results, const String& if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Add directory - results.Add(directory / info.cFileName); + results.Add(path / info.cFileName); } } while (FindNextFileW(handle, &info) != 0); FindClose(handle); diff --git a/Source/Engine/Platform/Win32/Win32FileSystem.h b/Source/Engine/Platform/Win32/Win32FileSystem.h index 42ac5f4a1..fccde5cd2 100644 --- a/Source/Engine/Platform/Win32/Win32FileSystem.h +++ b/Source/Engine/Platform/Win32/Win32FileSystem.h @@ -11,81 +11,23 @@ /// class FLAXENGINE_API Win32FileSystem : public FileSystemBase { - // TODO: fix docs - public: - - // Creates a new directory - // @param path Directory path - // @returns True if cannot create directory, otherwise false + // [FileSystemBase] static bool CreateDirectory(const StringView& path); - - // Deletes an existing directory - // @param path Directory path - // @param deleteSubdirectories True if delete all subdirectories and files, otherwise false - // @returns True if cannot delete directory, otherwise false static bool DeleteDirectory(const String& path, bool deleteContents = true); - - // Check if directory exists - // @param path Directory path to check - // @returns True if directory exists, otherwise false static bool DirectoryExists(const StringView& path); - - // Finds the names of files (including their paths) that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories - // @param results When this method completes, this list contains list of all filenames that match the specified search pattern - // @param path Path of the directory to search in it - // @param searchPattern Custom search pattern to use during that operation - // @param option Additional search options - // @returns True if an error occurred, otherwise false - static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern, DirectorySearchOption option = DirectorySearchOption::AllDirectories); - - // Finds the names of directories (including their paths) that are inside the specified directory - // @param results When this method completes, this list contains list of all filenames that match the specified search pattern - // @param directory Path of the directory to search in it - // @returns True if an error occurred, otherwise false - static bool GetChildDirectories(Array& results, const String& directory); - -public: - - // Check if file exists - // @param path File path to check - // @returns True if file exists, otherwise false + static bool DirectoryGetFiles(Array& results, const String& path, const Char* searchPattern = TEXT("*"), DirectorySearchOption option = DirectorySearchOption::AllDirectories); + static bool GetChildDirectories(Array& results, const String& path); static bool FileExists(const StringView& path); - - // Deletes an existing file - // @param path File path - // @returns True if cannot delete file, otherwise false static bool DeleteFile(const StringView& path); - - // Tries to get size of the file - // @param path File path to check - // @returns Amount of bytes in file static uint64 GetFileSize(const StringView& path); - - // Check if file is read-only - // @param path File path to check - // @returns True if file is read-only static bool IsReadOnly(const StringView& path); - - // Sets file read-only flag - // @param path File path - // @returns True if cannot update file static bool SetReadOnly(const StringView& path, bool isReadOnly); - - // Move file - // @param dst Destination path - // @param src Source path - // @returns True if cannot move file static bool MoveFile(const StringView& dst, const StringView& src, bool overwrite = false); - - // Clone file - // @param dst Destination path - // @param src Source path - // @returns True if cannot copy file static bool CopyFile(const StringView& dst, const StringView& src); + static DateTime GetFileLastEditTime(const StringView& path); public: - /// /// Converts the UNIX style line endings into DOS style (from \n into \r\n). /// @@ -93,17 +35,7 @@ public: /// The output result. static void ConvertLineEndingsToDos(const StringView& text, Array& output); -public: - - /// - /// Gets last time when file has been modified (in UTC). - /// - /// The file path to check. - /// The last write time or DateTime::MinValue() if cannot get data. - static DateTime GetFileLastEditTime(const StringView& path); - private: - static bool getFilesFromDirectoryTop(Array& results, const String& directory, const Char* searchPattern); static bool getFilesFromDirectoryAll(Array& results, const String& directory, const Char* searchPattern); }; diff --git a/Source/Engine/Platform/Windows/WindowsFileSystem.h b/Source/Engine/Platform/Windows/WindowsFileSystem.h index 28fa9069c..8a51d5ee7 100644 --- a/Source/Engine/Platform/Windows/WindowsFileSystem.h +++ b/Source/Engine/Platform/Windows/WindowsFileSystem.h @@ -12,7 +12,6 @@ class FLAXENGINE_API WindowsFileSystem : public Win32FileSystem { public: - /// /// Moves a file to the recycle bin with possible undo instead of removing it permanently. /// @@ -20,26 +19,15 @@ public: /// True if cannot perform that operation, otherwise false. static bool MoveFileToRecycleBin(const StringView& path); -public: - static bool AreFilePathsEqual(const StringView& path1, const StringView& path2); public: - - /// - /// Gets the special folder path. - /// - /// The folder type. - /// The result full path. - static void GetSpecialFolderPath(const SpecialFolder type, String& result); - -public: - // [Win32FileSystem] static bool ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array& filenames); static bool ShowSaveFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array& filenames); static bool ShowBrowseFolderDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& title, String& path); static bool ShowFileExplorer(const StringView& path); + static void GetSpecialFolderPath(const SpecialFolder type, String& result); }; #endif diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index dab426190..408fcb887 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -380,7 +380,7 @@ bool ModelTool::GenerateModelSDF(Model* inputModel, ModelData* modelData, float sdf.ResolutionScale = resolutionScale; sdf.LOD = lodIndex; const int32 maxMips = 3; - const int32 mipCount = Math::Min(MipLevelsCount(resolution.X, resolution.Y, resolution.Z, true), maxMips); + const int32 mipCount = Math::Min(MipLevelsCount(resolution.X, resolution.Y, resolution.Z), maxMips); PixelFormat format = PixelFormat::R16_UNorm; int32 formatStride = 2; float formatMaxValue = MAX_uint16;