API Documentation
Loading...
Searching...
No Matches
File.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: File
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/String.h>
35#include <NDEVR/Time.h>
36#include <NDEVR/FileCachedData.h>
37namespace NDEVR
38{
39 class ProgressInfo;
40 class Time;
41 class UUID;
42
43 /**----------------------------------------------------------------------------
44 \brief Logic for reading or writing to a file as well as navigating filesystems
45 or other common file operations.
46 ----------------------------------------------------------------------------*/
47 class File : public String
48 {
49 public:
72 public:
74 NDEVR_BASE_API File(const File& file);
75 NDEVR_BASE_API File(const String& resource_name, const String& path_id);
76 NDEVR_BASE_API File(File&& file) noexcept;
77 NDEVR_BASE_API File(const String& full_path);
79 NDEVR_BASE_API File(const char* full_path);
81
82 NDEVR_BASE_API bool copyTo(const File& cs, bool override_file, ProgressInfo* log = nullptr) const;
83 NDEVR_BASE_API bool moveTo(File& file, bool override_file, ProgressInfo* log = nullptr, bool is_source_temp = false);
85 [[nodiscard]] NDEVR_BASE_API String getPath(uint01 file_parts) const;
86 NDEVR_BASE_API void setPath(const String& path, uint01 part);
88 [[nodiscard]] NDEVR_BASE_API bool exists() const;
89 [[nodiscard]] NDEVR_BASE_API bool cachedExist() const;
90 [[nodiscard]] NDEVR_BASE_API bool parentDirectoryExists() const;
91 [[nodiscard]] NDEVR_BASE_API bool isDirectory() const;
92 [[nodiscard]] NDEVR_BASE_API bool isDrive() const;
93 [[nodiscard]] NDEVR_BASE_API bool isHidden() const;
94 [[nodiscard]] NDEVR_BASE_API bool isOpen() const;
95
97 [[nodiscard]] NDEVR_BASE_API String getFolderName() const;
99
100 [[nodiscard]] NDEVR_BASE_API Time getModifiedTime() const;
101 [[nodiscard]] NDEVR_BASE_API Time getCreationTime() const;
102 [[nodiscard]] NDEVR_BASE_API Time getAccessTime() const;
103 NDEVR_BASE_API void getFileTimes(Time& modified_time, Time& creation_time, Time& access_time) const;
105 NDEVR_BASE_API bool updateAccessedTime(Time access_time) const;
106
108 NDEVR_BASE_API File& append(const char& s);
113 [[nodiscard]] NDEVR_BASE_API Buffer<File, uint04, ObjectAllocator<false>> getChildrenMatching(const Buffer<String>& include_patterns, const Buffer<String>& exclude_patterns, bool recursive = false) const;
114 [[nodiscard]] NDEVR_BASE_API FILE* filePtr();
115 NDEVR_BASE_API FILE* open(OpenMode mode, bool append = false);
116 NDEVR_BASE_API String relativePathTo(const File& reference) const;
120
121
122 NDEVR_BASE_API void create(bool override_file) const;
124
126
127 [[nodiscard]] NDEVR_BASE_API uint08 fileSize() const;
128
129 [[nodiscard]] NDEVR_BASE_API UUID getUUID() const;
130
132
133 NDEVR_BASE_API bool operator<<(const String& value);
135 NDEVR_BASE_API bool operator<<(const fltp04& value);
136 NDEVR_BASE_API bool operator<<(const fltp08& value);
137
139 NDEVR_BASE_API File& operator=(File&& value) noexcept;
140
142 [[nodiscard]] NDEVR_BASE_API static File TempFileFolder();
143 [[nodiscard]] NDEVR_BASE_API File generateTempFile() const;
144
145 const String& pathID() const { return m_id; }
147 NDEVR_BASE_API bool isMTP() const;
155 NDEVR_BASE_API void setFromDisplayString(const String& display_string);
156 public:
159 NDEVR_BASE_API static bool doesFileExist(const String& name);
160 NDEVR_BASE_API static bool typeSort(const File& i, const File& j);
161 NDEVR_BASE_API static bool nameSort(const File& i, const File& j);
162 NDEVR_BASE_API static bool accessSort(const File& i, const File& j);
163 NDEVR_BASE_API static bool createSort(const File& i, const File& j);
164 NDEVR_BASE_API static bool isPathSep(const char& path);
165 NDEVR_BASE_API static bool isIDSep(const char& path);
166 size_t operator()() const
167 {
168 return static_cast<size_t>(hash());
169 }
170 public:
171#ifdef _WIN32
172 static constexpr char PathSep = '\\';
173#else
174 static constexpr char PathSep = '/';
175#endif
176 static constexpr char ExtSep = '.';
177 static constexpr char DriveSep = ':';
178 static constexpr char IDSep = '|';
179
181 private:
182 void checkError(uint04 error) const;
183 protected:
185 mutable String m_id;
191 mutable bool m_id_valid;
192 };
193 /**----------------------------------------------------------------------------
194 \brief Logic for searching for files based on some criteria.
195 File searches help locate files or directories within other directories.
196 ----------------------------------------------------------------------------*/
198 {
199 public:
203 uint04 max_recursion_level = Constant<uint04>::Max;
205 protected:
206 void performSearch(const File& current_file, Buffer<File>& files, uint04 recursion_level) const;
207 };
208}
209
210namespace std//Define things to allow use within std libs
211{
212 template <>
213 struct hash<NDEVR::File>
214 {
215 std::size_t operator()(const NDEVR::File& s) const noexcept
216 {
217 return static_cast<size_t>(s.hash());
218 }
219 };
220 NDEVR_BASE_API istream& operator>>(istream& in, NDEVR::String& string);
221};
222
#define NDEVR_BASE_API
Definition DLLInfo.h:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
bool isOpen() const
bool isMTP() const
const String & pathID() const
Definition File.h:145
File(String &&full_path)
static bool accessSort(const File &i, const File &j)
bool hasNullBytes(uint08 max_length=Constant< uint08 >::Max)
OpenMode m_open_mode
Definition File.h:187
Time getCreationTime() const
void setPath(const String &path, uint01 part)
FILE * filePtr()
bool copyTo(const File &cs, bool override_file, ProgressInfo *log=nullptr) const
FILE * open(OpenMode mode, bool append=false)
static String PathSepS
Definition File.h:180
Time getAccessTime() const
String pathNameID() const
uint01 m_path_start
Definition File.h:188
bool resolveNameFromMTPPath()
String m_id
Definition File.h:185
void deleteFile(ProgressInfo *log=nullptr)
bool isHidden() const
FileCachedData m_cached_data
Definition File.h:184
File(const String &resource_name, const String &path_id)
void updateCache(const FileCachedData &cache)
static Buffer< File, uint04, ObjectAllocator< false > > SystemDrives()
File & operator=(File &&value) noexcept
static bool isPathSep(const char &path)
size_t operator()() const
Definition File.h:166
bool operator<<(const Buffer< uint01 > &values)
void close()
File(const File &file)
bool operator<<(const fltp08 &value)
String getFolderName() const
bool parentDirectoryExists() const
FILE * m_file_ptr
Definition File.h:186
File(const char *full_path)
void create(bool override_file) const
static bool nameSort(const File &i, const File &j)
bool updateAccessedTime(Time access_time) const
uint01 m_file_ext_start
Definition File.h:190
String getPath(uint01 file_parts) const
Buffer< uint01 > getData()
static constexpr char PathSep
Definition File.h:172
bool resolveMTPPath() const
static File TempFileFolder()
uint08 fileSize() const
void setInternalVars()
static constexpr char IDSep
Definition File.h:178
void updateCache() const
File findNonExistingSuitableName() const
UUID getUUID() const
static bool typeSort(const File &i, const File &j)
FilePart
Definition File.h:64
@ e_drive
Definition File.h:65
@ e_file_name
Definition File.h:67
@ e_full_path
Definition File.h:69
@ e_file_extension
Definition File.h:68
@ e_dir_path
Definition File.h:66
@ e_folder_name
Definition File.h:70
bool operator<<(const String &value)
String getDriveDescription() const
bool isDirectory() const
File & operator=(const File &value)
File getParentDirectory() const
Buffer< File, uint04, ObjectAllocator< false > > getChildren() const
bool exists() const
static Buffer< File, uint04, ObjectAllocator< false > > MTPDevices()
bool updateAccessedTime() const
static constexpr char ExtSep
Definition File.h:176
void getFileTimes(Time &modified_time, Time &creation_time, Time &access_time) const
String relativePathTo(const File &reference) const
static bool doesFileExist(const String &name)
File & operator=(String &value)
File(const String &full_path)
File & append(const String &s)
static bool createSort(const File &i, const File &j)
File generateTempFile() const
static bool isIDSep(const char &path)
OpenMode
Definition File.h:51
@ e_ascii_read
Definition File.h:54
@ e_ascii_write_safe
Definition File.h:58
@ e_binary_read_safe
Definition File.h:57
@ e_ascii_write
Definition File.h:55
@ e_binary_read
Definition File.h:52
@ e_ascii_read_shared
Definition File.h:60
@ e_ascii_read_safe
Definition File.h:56
@ e_binary_write
Definition File.h:53
@ e_undefined
Definition File.h:61
@ e_binary_write_safe
Definition File.h:59
const FileCachedData & currentCache() const
bool moveTo(File &file, bool override_file, ProgressInfo *log=nullptr, bool is_source_temp=false)
File & append(const char &s)
void setFromDisplayString(const String &display_string)
Buffer< File, uint04, ObjectAllocator< false > > getChildrenMatching(const Buffer< String > &include_patterns, const Buffer< String > &exclude_patterns, bool recursive=false) const
uint01 m_file_name_start
Definition File.h:189
File & appendPath(const String &cs)
void throwIfNotExist() const
static constexpr char DriveSep
Definition File.h:177
void flush()
String toDisplayString()
bool m_id_valid
Definition File.h:191
bool isDrive() const
Time getModifiedTime() const
void invalidateCache()
bool operator<<(const fltp04 &value)
void removeInvalidChars()
void expandEnvironmentalVars()
File(File &&file) noexcept
bool cachedExist() const
Logic for searching for files based on some criteria.
Definition File.h:198
Buffer< String > search_extensions
Definition File.h:201
Buffer< File > performSearch() const
Buffer< File > excluded_list
Definition File.h:202
Buffer< File > files_recursively_to_search
Definition File.h:200
void performSearch(const File &current_file, Buffer< File > &files, uint04 recursion_level) const
A light-weight base class for Log that allows processes to update, without the need for additional in...
Definition ProgressInfo.hpp:48
The core String class for the NDEVR API.
Definition String.h:69
uint08 hash() const
Creates a simple, quick hash of the object. See hash(const char* value) for details of the implementa...
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Definition File.h:211
istream & operator>>(istream &in, NDEVR::String &string)
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Data that is cached from a file into program memory to limit expensive.
Definition FileCache.h:22