summaryrefslogtreecommitdiffhomepage
path: root/Public/Developer/System.Core/Headers/File.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'Public/Developer/System.Core/Headers/File.hxx')
-rw-r--r--Public/Developer/System.Core/Headers/File.hxx105
1 files changed, 105 insertions, 0 deletions
diff --git a/Public/Developer/System.Core/Headers/File.hxx b/Public/Developer/System.Core/Headers/File.hxx
new file mode 100644
index 00000000..06c2a22e
--- /dev/null
+++ b/Public/Developer/System.Core/Headers/File.hxx
@@ -0,0 +1,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__