34#include <NDEVR/String.h>
35#include <NDEVR/Time.h>
36#include <NDEVR/StringView.h>
37#include <NDEVR/FileCachedData.h>
38#include <NDEVR/InfoPipe.h>
111 NDEVR_BASE_API
File(
const StringView& full_path);
181 [[nodiscard]] NDEVR_BASE_API
bool exists()
const;
201 [[nodiscard]] NDEVR_BASE_API
bool isDrive()
const;
206 [[nodiscard]] NDEVR_BASE_API
bool isHidden()
const;
211 [[nodiscard]] NDEVR_BASE_API
bool isOpen()
const;
228 [[nodiscard]] NDEVR_BASE_API StringView
getFolderName(
bool trailing_mark =
false)
const;
346 [[nodiscard]] NDEVR_BASE_API FILE*
filePtr()
const;
388 NDEVR_BASE_API
void create(
bool override_file)
const;
436 NDEVR_BASE_API
bool operator<<(
const HighCapacityBuffer<uint01>& values);
539 return static_cast<size_t>(
hash());
602 [[nodiscard]] NDEVR_BASE_API
static bool isPathSep(
const char& path);
608 [[nodiscard]] NDEVR_BASE_API
static bool isIDSep(
const char& path);
611 static constexpr char PathSep =
'\\';
612 static constexpr StringView
PathSepS =
"\\";
625 void checkError(
uint04 error)
const;
669 struct hash<
NDEVR::File>
676 std::size_t operator()(
const File& s)
const noexcept
678 return static_cast<size_t>(s.hash());
The equivelent of std::vector but with a bit more control.
Logic for searching for files based on some criteria.
uint04 max_recursion_level
Maximum directory depth for recursive searches.
Buffer< File > excluded_list
Files or directories to exclude from results.
void performSearch(const File ¤t_file, Buffer< File > &files, uint04 recursion_level) const
Recursively searches a directory for matching files.
Buffer< File > performSearch() const
Performs the file search and returns all matching files.
Buffer< File > files_recursively_to_search
Root files or directories to search within.
Buffer< String > search_extensions
File extensions to match during the search.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
FILE * open(OpenMode mode, bool append=false)
Opens the file with the specified mode.
uint01 m_file_ext_start
Index into the path string where the file extension begins.
OpenMode
Specifies the mode in which a file is opened.
@ e_ascii_write_safe
Open for ASCII text writing with safety checks.
@ e_binary_read_safe
Open for binary reading with safety checks.
@ e_binary_write
Open for binary writing.
@ e_ascii_write
Open for ASCII text writing.
@ e_binary_write_safe
Open for binary writing with safety checks.
@ e_undefined
Undefined or unset open mode.
@ e_ascii_read
Open for ASCII text reading.
@ e_ascii_read_safe
Open for ASCII text reading with safety checks.
@ e_binary_read
Open for binary reading.
void setInternalVars()
Recalculates internal cached path component indices from the current path string.
File & appendPath(const StringView &cs)
Appends a path component to this file path.
String getDriveDescription() const
Retrieves a human-readable description of the drive this file resides on.
void close()
Closes the file if it is open.
static bool isPathSep(const char &path)
Checks whether a character is a path separator.
static bool accessSort(const File &i, const File &j)
Comparison function for sorting files by last access time.
void expandEnvironmentalVars()
Expands any environment variables present in the file path.
uint08 availableDiskSpace(bool privelaged=true) const
Queries the available disk space on the drive containing this file.
String m_id
The path identifier string for this file.
bool operator<<(const StringView &value)
Writes a string to the file.
File & appendPath(const char *cs)
Appends a path component to this file path.
bool isHidden() const
Checks whether this file is hidden.
bool resolveNameFromMTPPath()
Resolves the display name from an MTP device path.
bool isOpen() const
Checks whether this file is currently open.
static constexpr char ExtSep
File extension separator character.
bool updateAccessedTime() const
Updates the last accessed time of the file to the current time.
File getParentDirectory() const
Gets the parent directory of this file.
void updateCache(const FileCachedData &cache)
Updates the cached file metadata with the provided data.
uint08 fileSize() const
Gets the size of the file in bytes.
Time getAccessTime() const
Gets the last access time of the file.
File(const File &file)
Copy constructor.
const String & pathID() const
Gets the path identifier string for this file.
bool isMTP() const
Checks whether this file path refers to an MTP (Media Transfer Protocol) device.
FileBuffer getChildrenMatching(const Buffer< StringView > &include_patterns, const Buffer< StringView > &exclude_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
Retrieves children matching include patterns while excluding others, using StringView patterns.
bool m_id_valid
Whether the cached path identifier is currently valid.
static FileBuffer SystemDrives()
Retrieves all system drives.
static FileBuffer MTPDevices()
Retrieves all connected MTP (Media Transfer Protocol) devices.
uint01 m_path_start
Index into the path string where the directory path begins.
FileCachedData m_cached_data
Cached file metadata such as size, times, and existence.
static bool createSort(const File &i, const File &j)
Comparison function for sorting files by creation time.
void setFromDisplayString(const StringView &display_string)
Sets this file path from a user-friendly display string.
size_t operator()() const
Functor operator for use as a hash key in standard containers.
static bool nameSort(const File &i, const File &j)
Comparison function for sorting files by name.
HighCapacityBuffer< uint01 > getDataExtended()
Reads the entire file contents into a high-capacity byte buffer for large files.
bool operator<<(const fltp08 &value)
Writes a 64-bit floating-point value to the file.
void updateCache() const
Updates the cached file metadata from the filesystem.
File(const String &full_path)
Constructs a File from a full path string.
File & operator=(const File &value)
Copy assignment operator.
File(File &&file) noexcept
Move constructor.
File & append(const char &s)
Appends a single character to the file path.
UUID getUUID() const
Gets a UUID that uniquely identifies this file on the filesystem.
void throwIfNotExist() const
Throws an exception if this file does not exist.
File & operator=(File &&value) noexcept
Move assignment operator.
FileBuffer getChildrenMatching(const Buffer< StringView > &include_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
Retrieves children of this directory matching any of the given StringView patterns.
void setFolderName(const StringView &folder_name)
Sets the folder name portion of the file path.
void removeOpenOwnership()
Releases ownership of the open file handle without closing it.
Time getCreationTime() const
Gets the creation time of the file.
bool moveTo(File &file, bool override_file, LogPtr log=LogPtr(), bool is_source_temp=false)
Moves this file to a new location.
void makeReadOnly(bool read_only)
Sets or clears the read-only attribute on this file.
File & operator=(String &value)
Assignment operator from a String reference.
bool operator<<(const HighCapacityBuffer< uint01 > &values)
Writes a high-capacity byte buffer to the file.
static constexpr char DriveSep
Drive separator character (e.g., "C:").
FileBuffer getChildrenMatching(const StringView &include_pattern, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
Retrieves children of this directory matching a pattern.
bool resolveMTPPath() const
Resolves the actual filesystem path from an MTP device path.
static constexpr StringView PathSepS
Platform-specific path separator string.
bool isDirectory() const
Checks whether this path refers to a directory.
bool copyTo(const File &cs, bool override_file, LogPtr log=LogPtr()) const
Copies this file to a destination.
void flush()
Flushes any buffered data to disk.
StringView getPath(uint01 file_parts) const
Retrieves a subset of the file path based on the specified parts.
FileBuffer getChildrenMatching(const Buffer< String > &include_patterns, const Buffer< String > &exclude_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
Retrieves children matching include patterns while excluding others.
bool operator<<(const fltp04 &value)
Writes a 32-bit floating-point value to the file.
StringView pathNameID() const
Gets a combined path and name identifier for this file.
uint01 m_file_name_start
Index into the path string where the file name begins.
FILE * filePtr() const
Returns the underlying C FILE pointer for this file.
void invalidateCache()
Invalidates the cached file metadata, forcing a refresh on next access.
bool operator<<(const Buffer< uint01 > &values)
Writes a byte buffer to the file.
const FileCachedData & currentCache() const
Returns the current cached file metadata.
void create(bool override_file) const
Creates the file or directory on disk.
String toDisplayString()
Converts this file path to a user-friendly display string.
static File TempFileFolder()
Gets the system temporary file folder.
String relativePathTo(const File &reference) const
Computes the relative path from this file to a reference file.
static bool isIDSep(const char &path)
Checks whether a character is an ID separator.
FILE * m_file_ptr
The underlying C file pointer, or nullptr if not open.
bool cachedExist() const
Checks whether the file exists using cached data rather than querying the filesystem.
File & append(const StringView &s)
Appends a string to the file path.
static bool DoesFileExist(const String &name)
Checks whether a file with the given name exists.
static constexpr char IDSep
ID separator character used in path identifiers.
void deleteFile(LogPtr log=LogPtr())
Deletes this file from disk.
StringView getFolderName(bool trailing_mark=false) const
Retrieves the folder name portion of the file path.
File()
Default constructor.
static constexpr char PathSep
Platform-specific path separator character.
Time getModifiedTime() const
Gets the last modified time of the file.
void getFileTimes(Time &modified_time, Time &creation_time, Time &access_time) const
Retrieves all three file timestamps at once.
File(const String &resource_name, const String &path_id)
Constructs a File from a resource name and path identifier.
static String FileSizeToString(uint08 file_size)
Converts a file size in bytes to a human-readable string (e.g., "1.5 MB").
File findNonExistingSuitableName() const
Generates a unique file name based on this path that does not conflict with existing files.
FilePart
Bitmask flags representing parts of a file path.
@ e_file_name
The file name without extension.
@ e_drive
The drive component of the path (e.g., "C:").
@ e_file_extension
The file extension (e.g., ".txt").
@ e_dir_path
The directory component of the path.
@ e_full_path
The complete file path including all components.
File & appendPath(const String &cs)
Appends a path component to this file path.
bool updateAccessedTime(Time access_time) const
Updates the last accessed time of the file to a specific time.
bool hasNullBytes(uint08 max_length=Constant< uint08 >::Max)
Checks whether the file contains null bytes within the specified range.
bool exists() const
Checks whether this file or directory exists on disk.
void removeInvalidChars()
Removes characters from the path that are invalid for the current filesystem.
FileBuffer getChildren() const
Retrieves all direct children of this directory.
Buffer< uint01 > getData()
Reads the entire file contents into a byte buffer.
File generateTempFile() const
Generates a temporary file path derived from this file's directory.
File(String &&full_path)
Constructs a File by moving a path string.
bool isDrive() const
Checks whether this path refers to a drive root.
void setPath(const StringView &path, uint01 part)
Sets a specific part of the file path.
OpenMode m_open_mode
The current open mode of the file.
bool parentDirectoryExists() const
Checks whether the parent directory of this file exists.
File(const StringView &full_path)
Constructs a File from a StringView of a full path.
FileBuffer getChildrenMatching(const Buffer< String > &include_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
Retrieves children of this directory matching any of the given patterns.
static bool typeSort(const File &i, const File &j)
Comparison function for sorting files by type (extension).
A light-weight base class for Log that allows processes to update, without the need for additional in...
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
The core String View class for the NDEVR API.
constexpr uint08 hash() const
Creates a simple, quick hash of the object.
constexpr String() noexcept
Constructor used to create an empty String*.
Represents a timestamp with utilities for manipulation and conversion.
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
The primary namespace for the NDEVR SDK.
AlocatingAlignedBuffer< File, 64 > FileBuffer
Buffer type for storing File objects with 64-byte alignment.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ creation_time
Timestamp when the object was created.
@ modified_time
Timestamp when the object was last modified.
@ file
The source file path associated with this object.
@ name
The display name of the object.
istream & operator>>(istream &in, StringView &string)
Stream extraction operator for reading into an StringView.
Data that is cached from a file into program memory to limit expensive file lookups.