// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Types/BaseTypes.h"
#include "Engine/Platform/Types.h"
///
/// Specifies whether to search the current directory, or the current directory and all subdirectories.
///
enum class DirectorySearchOption
{
///
/// Includes the current directory and all its subdirectories in a search operation.This option includes reparse points such as mounted drives and symbolic links in the search.
///
AllDirectories,
///
/// Includes only the current directory in a search operation.
///
TopDirectoryOnly,
};
///
/// Special system folder types.
///
enum class SpecialFolder
{
Desktop,
Documents,
Pictures,
AppData,
LocalAppData,
ProgramData,
Temporary,
};
API_INJECT_CODE(cpp, "#include \"Engine/Platform/FileSystem.h\"");
///
/// Platform implementation of filesystem service.
///
API_CLASS(Static, Name="FileSystem", Tag="NativeInvokeUseName")
class FLAXENGINE_API FileSystemBase
{
DECLARE_SCRIPTING_TYPE_MINIMAL(FileSystemBase);
///
/// Displays a standard dialog box that prompts the user to open a file(s).
///
/// The parent window or null.
/// The initial directory.
/// The file filter string as null-terminated pairs of name and list of extensions. Multiple file extensions must be separated with semicolon.
/// True if allow multiple files to be selected, otherwise use single-file mode.
/// The dialog title.
/// The output names of the files picked by the user.
/// True if failed, otherwise false.
///
/// Example file filters:
/// "All Files\0*.*"
/// "All Files\0*.*\0Image Files\0*.png;*.jpg"
///
API_FUNCTION() static bool ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, API_PARAM(Out) Array& filenames);
///
/// Displays a standard dialog box that prompts the user to save a file(s).
///
/// The parent window.
/// The initial directory.
/// The file filter string as null-terminated pairs of name and list of extensions. Multiple file extensions must be separated with semicolon.
/// True if allow multiple files to be selected, otherwise use single-file mode.
/// The title.
/// The output names of the files picked by the user.
/// True if failed, otherwise false.
///
/// Example file filters:
/// "All Files\0*.*"
/// "All Files\0*.*\0Image Files\0*.png;*.jpg"
///
API_FUNCTION() static bool ShowSaveFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, API_PARAM(Out) Array& filenames);
///
/// Displays a standard dialog box that prompts the user to select a folder.
///
/// The parent window.
/// The initial directory.
/// The dialog title.
/// The output path.
/// True if failed, otherwise false.
API_FUNCTION() static bool ShowBrowseFolderDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& title, API_PARAM(Out) String& path);
///
/// Opens a standard file explorer application and navigates to the given directory.
///
/// The path.
/// True if failed, otherwise false.
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
///
/// Path to normalize
static void NormalizePath(String& path);
///
/// Check 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)
///
/// Input path to process
/// File extension
static String GetExtension(const StringView& path);
///
/// Gets the file path to the temporary file that can be created and used.
///
/// The temporary path.
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
///
/// Path relative to the engine directory
/// Absolute path
static String ConvertRelativePathToAbsolute(const String& path);
///
/// Converts path relative to basePath into absolute path
///
/// Base path
/// Path relative to basePath
/// Absolute path
static String ConvertRelativePathToAbsolute(const String& basePath, const String& path);
///
/// 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
///
/// Base path
/// Absolute path
/// Relative path
static String ConvertAbsolutePathToRelative(const String& basePath, const String& path);
private:
static bool DirectoryCopyHelper(const String& dst, const String& src, bool withSubDirectories);
};