39 #include "NptStreams.h" 45 const int NPT_ERROR_NO_SUCH_FILE = NPT_ERROR_BASE_FILE - 0;
46 const int NPT_ERROR_FILE_NOT_OPEN = NPT_ERROR_BASE_FILE - 1;
47 const int NPT_ERROR_FILE_BUSY = NPT_ERROR_BASE_FILE - 2;
48 const int NPT_ERROR_FILE_ALREADY_OPEN = NPT_ERROR_BASE_FILE - 3;
49 const int NPT_ERROR_FILE_NOT_READABLE = NPT_ERROR_BASE_FILE - 4;
50 const int NPT_ERROR_FILE_NOT_WRITABLE = NPT_ERROR_BASE_FILE - 5;
51 const int NPT_ERROR_FILE_NOT_DIRECTORY = NPT_ERROR_BASE_FILE - 6;
52 const int NPT_ERROR_FILE_ALREADY_EXISTS = NPT_ERROR_BASE_FILE - 7;
53 const int NPT_ERROR_FILE_NOT_ENOUGH_SPACE = NPT_ERROR_BASE_FILE - 8;
54 const int NPT_ERROR_DIRECTORY_NOT_EMPTY = NPT_ERROR_BASE_FILE - 9;
67 const unsigned int NPT_FILE_OPEN_MODE_READ = 0x01;
68 const unsigned int NPT_FILE_OPEN_MODE_WRITE = 0x02;
69 const unsigned int NPT_FILE_OPEN_MODE_CREATE = 0x04;
70 const unsigned int NPT_FILE_OPEN_MODE_TRUNCATE = 0x08;
71 const unsigned int NPT_FILE_OPEN_MODE_UNBUFFERED = 0x10;
72 const unsigned int NPT_FILE_OPEN_MODE_APPEND = 0x20;
74 const unsigned int NPT_FILE_ATTRIBUTE_READ_ONLY = 0x01;
75 const unsigned int NPT_FILE_ATTRIBUTE_LINK = 0x02;
77 #define NPT_FILE_STANDARD_INPUT "@STDIN" 78 #define NPT_FILE_STANDARD_OUTPUT "@STDOUT" 79 #define NPT_FILE_STANDARD_ERROR "@STDERR" 101 NPT_FileInfo() : m_Type(FILE_TYPE_NONE), m_Size(0), m_AttributesMask(0), m_Attributes(0) {}
106 NPT_Flags m_AttributesMask;
107 NPT_Flags m_Attributes;
119 static const char*
const Separator;
122 static NPT_String BaseName(
const char* path,
bool with_extension =
true);
124 static NPT_String FileExtension(
const char* path);
125 static NPT_String Create(
const char* directory,
const char* base);
138 typedef unsigned int OpenMode;
144 virtual NPT_Result Open(OpenMode mode) = 0;
145 virtual NPT_Result Close() = 0;
158 static NPT_Result GetSize(
const char* path, NPT_LargeSize &size);
159 static NPT_Result GetInfo(
const char* path,
NPT_FileInfo* info = NULL);
160 static bool Exists(
const char* path) {
return NPT_SUCCEEDED(GetInfo(path)); }
161 static NPT_Result Remove(
const char* path,
bool recurse =
false);
162 static NPT_Result RemoveFile(
const char* path);
163 static NPT_Result RemoveDir(
const char* path);
164 static NPT_Result RemoveDir(
const char* path,
bool force_if_not_empty);
165 static NPT_Result Rename(
const char* from_path,
const char* to_path);
166 static NPT_Result ListDir(
const char* path,
NPT_List<NPT_String>& entries, NPT_Ordinal start = 0, NPT_Cardinal count = 0);
167 static NPT_Result CreateDir(
const char* path);
168 static NPT_Result CreateDir(
const char* path,
bool create_intermediate_dirs);
169 static NPT_Result GetWorkingDir(
NPT_String& path);
170 static NPT_Result Load(
const char* path,
NPT_DataBuffer& buffer, NPT_FileInterface::OpenMode mode = NPT_FILE_OPEN_MODE_READ);
171 static NPT_Result Load(
const char* path,
NPT_String& data, NPT_FileInterface::OpenMode mode = NPT_FILE_OPEN_MODE_READ);
172 static NPT_Result Save(
const char* path,
NPT_String& data);
173 static NPT_Result Save(
const char* path,
const NPT_DataBuffer& buffer);
177 ~
NPT_File()
override {
delete m_Delegate; }
182 const NPT_String& GetPath() {
return m_Path; }
183 NPT_Result GetSize(NPT_LargeSize &size);
186 NPT_Result Rename(
const char* path);
189 NPT_Result Open(OpenMode mode)
override {
190 return m_Delegate->Open(mode);
192 NPT_Result Close()
override {
193 return m_Delegate->Close();
196 return m_Delegate->GetInputStream(stream);
199 return m_Delegate->GetOutputStream(stream);
220 if (NPT_FAILED(NPT_File::GetInfo(NPT_FilePath::Create(m_Directory, file1), &info1)))
return -1;
221 if (NPT_FAILED(NPT_File::GetInfo(NPT_FilePath::Create(m_Directory, file2), &info2)))
return -1;
222 return (info1.m_ModificationTime == info2.m_ModificationTime) ? 0 : (info1.m_ModificationTime < info2.m_ModificationTime ? -1 : 1);
229 #endif // _NPT_FILE_H_
Definition: NptFile.h:115
Definition: NptFile.h:215
Definition: NptDataBuffer.h:44
Definition: NptFile.h:153
Definition: NptStrings.h:57
Definition: NptFile.h:134