-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfileio.h
64 lines (56 loc) · 1.74 KB
/
fileio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "defines.h"
#include <string_view>
#include <vector>
#include <string>
#include <ctime>
namespace lxd {
enum OpenMode {
NotOpen = 0x0000,
ReadOnly = 0x0001,
WriteOnly = 0x0002,
ReadWrite = ReadOnly | WriteOnly,
Append = 0x0004,
Truncate = 0x0008,
Text = 0x0010,
Unbuffered = 0x0020,
NewOnly = 0x0040,
ExistingOnly = 0x0080
};
enum SeekMode {
FileBegin = 0,
FileCurrent,
FileEnd
};
union Handle {
void* handle;
int fd;
};
DLL_PUBLIC bool FileExists(const Char* path);
DLL_PUBLIC Handle OpenFile(const Char* path, int mode);
DLL_PUBLIC bool CloseFile(Handle handle);
DLL_PUBLIC bool WriteFile(const Char* path, char const* buffer, size_t bufferSize);
DLL_PUBLIC std::string ReadFile(const Char* path);
DLL_PUBLIC bool RemoveFile(const Char* path);
DLL_PUBLIC bool CreateDir(const Char* path);
DLL_PUBLIC bool CreateDirRecursive(const String& path);
DLL_PUBLIC int DeleteDir(StringView path, bool bDeleteSubdirectories = true);
DLL_PUBLIC bool DirExists(StringView path);
DLL_PUBLIC bool ListDir(StringView path, std::vector<String>& result, bool recursive = false, const Char* suffix = nullptr);
DLL_PUBLIC String GetExePath();
class DLL_PUBLIC File {
public:
File(const StringView& path, int mode);
~File();
long long size() { return _size; }
bool seek(long long distance, SeekMode mode, long long* newPtr = nullptr);
bool read(void* buffer, unsigned long nNumberOfBytesToRead, unsigned long* lpNumberOfBytesRead = nullptr);
bool write(const void* buffer, size_t size);
bool write(std::string_view buffer);
struct tm getLastWriteTime();
bool isOlderThan(struct tm);
private:
Handle _handle{};
long long _size{};
};
}