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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/* -------------------------------------------
Copyright Mahrouss Logic
------------------------------------------- */
#ifndef __FILE_API__
#define __FILE_API__
#include <System.Core/Headers/Defines.hxx>
namespace System {
class FileInterface;
class DirectoryInterface;
typedef IntPtrType SymlinkType;
typedef IntPtrType FileType;
typedef IntPtrType DirectoryType;
typedef IntPtrType FSRef;
enum {
kErrorNoSuchPath = -44,
kErrorNotAFile = -45,
kErrorNotADirectory = -46,
kErrorDirectory = -47,
kErrorBrokenSymlink = -48,
};
/// @brief System file interface
class FileInterface final {
public:
explicit FileInterface(const char *path) {
mHandle = kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle,
0, path);
}
~FileInterface() {
kApplicationObject->Invoke(kApplicationObject, kProcessCallCloseHandle, 0,
mHandle);
}
public:
CA_COPY_DEFAULT(FileInterface);
public:
PtrVoidType Read(UIntPtrType off, SizeType sz) {
return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 2,
off, sz);
}
PtrVoidType Read(SizeType sz) {
return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 3,
sz);
}
void Write(PtrVoidType buf, UIntPtrType off, SizeType sz) {
kApplicationObject->Invoke(kApplicationObject, mHandle, 4, buf, off, sz);
}
void Write(PtrVoidType buf, SizeType sz) {
kApplicationObject->Invoke(kApplicationObject, mHandle, 5, buf, sz);
}
void Seek(UIntPtrType off) {
kApplicationObject->Invoke(kApplicationObject, mHandle, 5);
}
void Rewind() { kApplicationObject->Invoke(kApplicationObject, mHandle, 6); }
public:
const char *MIME();
void MIME(const char *mime);
private:
FileType mHandle;
};
typedef FileInterface *FilePtr;
/// @brief file exception
/// Throws when the file isn't found or invalid.
class FileException : public SystemException {
public:
explicit FileException() = default;
virtual ~FileException() = default;
public:
CA_COPY_DEFAULT(FileException);
public:
const char *Name() override { return "FileException"; }
const char *Reason() override { return mReason; }
private:
const char *mReason{"System.Core: FileException: Catastrophic failure!"};
};
inline IntPtrType MakeSymlink(const char *from, const char *outputWhere) {
CA_MUST_PASS(from);
CA_MUST_PASS(outputWhere);
return kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, 1,
from);
}
} // namespace System
#endif // ifndef __FILE_API__
|