summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/io
diff options
context:
space:
mode:
Diffstat (limited to 'source/libs/asura-lib-utils/io')
-rw-r--r--source/libs/asura-lib-utils/io/binding/_compressor.cpp0
-rw-r--r--source/libs/asura-lib-utils/io/binding/_data_buffer.cpp123
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file.cpp223
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file_data.cpp60
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file_system.cpp265
-rw-r--r--source/libs/asura-lib-utils/io/binding/_io_task.cpp46
-rw-r--r--source/libs/asura-lib-utils/io/compressor.cpp11
-rw-r--r--source/libs/asura-lib-utils/io/compressor.h30
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.cpp102
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.h62
-rw-r--r--source/libs/asura-lib-utils/io/decoded_data.cpp21
-rw-r--r--source/libs/asura-lib-utils/io/decoded_data.h42
-rw-r--r--source/libs/asura-lib-utils/io/file.cpp292
-rw-r--r--source/libs/asura-lib-utils/io/file.h146
-rw-r--r--source/libs/asura-lib-utils/io/file_data.cpp52
-rw-r--r--source/libs/asura-lib-utils/io/file_data.h69
-rw-r--r--source/libs/asura-lib-utils/io/file_system.cpp198
-rw-r--r--source/libs/asura-lib-utils/io/file_system.h112
-rw-r--r--source/libs/asura-lib-utils/io/io_batch_task.cpp0
-rw-r--r--source/libs/asura-lib-utils/io/io_batch_task.h31
-rw-r--r--source/libs/asura-lib-utils/io/io_task.cpp55
-rw-r--r--source/libs/asura-lib-utils/io/io_task.h57
-rw-r--r--source/libs/asura-lib-utils/io/reloadable.h29
23 files changed, 0 insertions, 2026 deletions
diff --git a/source/libs/asura-lib-utils/io/binding/_compressor.cpp b/source/libs/asura-lib-utils/io/binding/_compressor.cpp
deleted file mode 100644
index e69de29..0000000
--- a/source/libs/asura-lib-utils/io/binding/_compressor.cpp
+++ /dev/null
diff --git a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
deleted file mode 100644
index cd73b31..0000000
--- a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-#include "../data_buffer.h"
-
-using namespace Luax;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- LUAX_REGISTRY(DataBuffer)
- {
- LUAX_REGISTER_METHODS(state,
- { "New", _New },
- { "GetData", _GetData },
- { "GetSize", _GetSize },
- { "Refactor", _Refactor },
- { "Load", _Load },
- { "Clear", _Clear }
- );
- }
-
- LUAX_POSTPROCESS(DataBuffer)
- {
- }
-
- // databuffer = DataBuffer.New(lstring)
- // databuffer = DataBuffer.New(size)
- LUAX_IMPL_METHOD(DataBuffer, _New)
- {
- LUAX_STATE(L);
-
- if (state.IsType(1, LUA_TSTRING))
- {
- size_t size;
- const byte* bytes = lua_tolstring(L, 1, &size);
- DataBuffer* buffer = new DataBuffer(bytes, size);
- buffer->PushLuaxUserdata(state);
- return 1;
- }
- else if (state.IsType(1, LUA_TNUMBER))
- {
- size_t size = lua_tonumber(L, 1);
- DataBuffer* buffer = new DataBuffer(size);
- buffer->PushLuaxUserdata(state);
- return 1;
- }
- else
- {
- return state.ErrorType(1, "number or string");
- }
- }
-
- // lsting, len = databuffer:GetData()
- LUAX_IMPL_METHOD(DataBuffer, _GetData)
- {
- LUAX_SETUP(L, "U");
-
- DataBuffer* self = state.GetUserdata<DataBuffer>(1);
- lua_pushlstring(L, self->GetData(), self->GetSize());
- return 1;
- }
-
- // length = databuffer:GetSize()
- LUAX_IMPL_METHOD(DataBuffer, _GetSize)
- {
- LUAX_SETUP(L, "U");
-
- DataBuffer* self = state.GetUserdata<DataBuffer>(1);
- lua_pushinteger(L, self->GetSize());
- return 1;
- }
-
- // databuffer:Refactor(size)
- LUAX_IMPL_METHOD(DataBuffer, _Refactor)
- {
- LUAX_PREPARE(L, DataBuffer);
-
- size_t size = state.CheckValue<int>(2);
- self->Refactor(size);
- return 0;
- }
-
- // size = databuffer:Load(lstring)
- // size = databuffer:Load(src)
- LUAX_IMPL_METHOD(DataBuffer, _Load)
- {
- LUAX_STATE(L);
-
- DataBuffer* buffer = state.GetUserdata<DataBuffer>(1);
- const byte* data;
- size_t size;
- if (state.IsType(2, LUA_TSTRING))
- {
- data = lua_tolstring(L, 2, &size);
- size_t len = buffer->Load(data, size);
- state.Push(len);
- return 1;
- }
- else if(state.IsType(2, LUA_TUSERDATA))
- {
- DataBuffer* src = state.CheckUserdata<DataBuffer>(2);
- size_t len = buffer->Load(*src);
- state.Push(len);
- return 1;
- }
- else
- {
- return state.ErrorType(1, "lstring or DataBuffer");
- }
- }
-
- // databuffer:Clear()
- LUAX_IMPL_METHOD(DataBuffer, _Clear)
- {
- LUAX_SETUP(L, "U");
-
- DataBuffer* self = state.GetUserdata<DataBuffer>(1);
- self->Clear();
- return 0;
- }
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp
deleted file mode 100644
index c44bc90..0000000
--- a/source/libs/asura-lib-utils/io/binding/_file.cpp
+++ /dev/null
@@ -1,223 +0,0 @@
-#include "../file.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- LUAX_REGISTRY(File)
- {
- LUAX_REGISTER_METHODS(state,
- { "New", _New },
- { "Open", _Open },
- { "Close", _Close },
- { "IsOpen", _IsOpen },
- { "GetMode", _GetMode },
- { "GetSize", _GetSize },
- { "Read", _Read },
- { "IsEOF", _IsEOF },
- { "Write", _Write },
- { "Flush", _Flush },
- { "Tell", _Tell },
- { "Seek", _Seek },
- { "SetBuffer", _SetBuffer },
- { "GetBuffer", _GetBuffer },
- { "GetFileName", _GetFileName },
- { "GetExtension", _GetExtension },
- { "GetName", _GetName }
- );
- }
-
- LUAX_POSTPROCESS(File)
- {
- LUAX_REGISTER_ENUM(state, "EFileMode",
- { "CLOSED", FILE_MODE_CLOSED },
- { "READ", FILE_MODE_READ },
- { "WRITE", FILE_MODE_WRITE },
- { "APPEND", FILE_MODE_APPEND }
- );
-
- LUAX_REGISTER_ENUM(state, "EBufferMode",
- { "NONE", BUFFER_MODE_NONE},
- { "LINE", BUFFER_MODE_LINE},
- { "FULL", BUFFER_MODE_FULL}
- );
- }
-
- // file = File.New(name)
- LUAX_IMPL_METHOD(File, _New)
- {
- LUAX_STATE(L);
-
- cc8* name = state.CheckValue<cc8*>(1);
- File* file = new File(name);
- file->PushLuaxUserdata(state);
- return 1;
- }
-
- // successsed = file:Open(mode)
- LUAX_IMPL_METHOD(File, _Open)
- {
- LUAX_PREPARE(L, File);
-
- File::FileMode mode = (File::FileMode)state.CheckValue<int>(2);
- state.Push(self->Open(mode));
- return 1;
- }
-
- // successed = file:Close()
- LUAX_IMPL_METHOD(File, _Close)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->Close());
- return 1;
- }
-
- // opened = file:IsOpen()
- LUAX_IMPL_METHOD(File, _IsOpen)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->IsOpen());
- return 1;
- }
-
- // mode = file:GetMode()
- LUAX_IMPL_METHOD(File, _GetMode)
- {
- LUAX_PREPARE(L, File);
-
- File::FileMode mode = self->GetMode();
- state.Push((int)mode);
- return 1;
- }
-
- // size = file:GetSize()
- LUAX_IMPL_METHOD(File, _GetSize)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->GetSize());
- return 1;
- }
-
- // size = file:Read(dst, len)
- // returns:
- // size ʵʶĴС
- // params:
- // self ļ
- // dst Ŀ껺
- // len ĴС
- LUAX_IMPL_METHOD(File, _Read)
- {
- LUAX_PREPARE(L, File);
-
- DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
- if (!db) return state.ErrorType(2, "DataBuffer");
- int len = state.CheckValue<int>(3);
- int size = self->Read(db, len);
- state.Push(size);
- return 1;
- }
-
- // isEOF = file:IsEOF()
- LUAX_IMPL_METHOD(File, _IsEOF)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->IsEOF());
- return 1;
- }
-
- // isWrite = file:Write(data buffer[, size])
- LUAX_IMPL_METHOD(File, _Write)
- {
- LUAX_PREPARE(L, File);
-
- DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
- if (!db) return state.ErrorType(2, "DataBuffer");
- state.Push(self->Write(db));
- return 1;
- }
-
- // isFlushed = file:Flush()
- LUAX_IMPL_METHOD(File, _Flush)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->Flush());
- return 1;
- }
-
- // pos = file:Tell()
- LUAX_IMPL_METHOD(File, _Tell)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->Tell());
- return 1;
- }
-
- // isSeek = file:Seek(pos)
- LUAX_IMPL_METHOD(File, _Seek)
- {
- LUAX_PREPARE(L, File);
-
- int pos = state.CheckValue<int>(2);
- state.Push(self->Seek(pos));
- return 1;
- }
-
- // isSetted = file:SetBuffer(mode, size)
- LUAX_IMPL_METHOD(File, _SetBuffer)
- {
- LUAX_PREPARE(L, File);
-
- BufferMode mode = (BufferMode)state.CheckValue<int>(2);
- int size = state.CheckValue<int>(3);
- state.Push(self->SetBuffer(mode, size));
- return 1;
- }
-
- // size, mode = file:GetBuffer()
- LUAX_IMPL_METHOD(File, _GetBuffer)
- {
- LUAX_PREPARE(L, File);
-
- size_t size = 0;
- BufferMode mode = self->GetBuffer(ASURA_OUT size);
- state.Push((int)size);
- state.Push((int)mode);
- return 2;
- }
-
- // name = file:GetFileName()
- LUAX_IMPL_METHOD(File, _GetFileName)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->GetFileName());
- return 1;
- }
-
- // name = file:GetExtension()
- LUAX_IMPL_METHOD(File, _GetExtension)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->GetExtension());
- return 1;
- }
-
- // name = file:GetName()
- LUAX_IMPL_METHOD(File, _GetName)
- {
- LUAX_PREPARE(L, File);
-
- state.Push(self->GetName());
- return 1;
- }
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/binding/_file_data.cpp b/source/libs/asura-lib-utils/io/binding/_file_data.cpp
deleted file mode 100644
index 09a0643..0000000
--- a/source/libs/asura-lib-utils/io/binding/_file_data.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#include "../file_data.h"
-
-using namespace std;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- LUAX_REGISTRY(FileData)
- {
- LUAX_REGISTER_METHODS(state,
- { "GetFileName", _GetFileName },
- { "GetExtension", _GetExtension },
- { "GetName", _GetName },
- { "GetDataBuffer", _GetDataBuffer }
- );
- }
-
- LUAX_POSTPROCESS(FileData)
- {
- }
-
- // filename = filedata:GetFileName()
- LUAX_IMPL_METHOD(FileData, _GetFileName)
- {
- LUAX_PREPARE(L, FileData);
- string filename = self->GetFileName();
- state.Push(filename);
- return 1;
- }
-
- // extension = filedata:GetExtension()
- LUAX_IMPL_METHOD(FileData, _GetExtension)
- {
- LUAX_PREPARE(L, FileData);
- string extension = self->GetExtension();
- state.Push(extension);
- return 1;
- }
-
- // name = filedata:GetName()
- LUAX_IMPL_METHOD(FileData, _GetName)
- {
- LUAX_PREPARE(L, FileData);
- string extension = self->GetName();
- state.Push(extension);
- return 1;
- }
-
- // databuffer = filedata:GetDataBuffer()
- LUAX_IMPL_METHOD(FileData, _GetDataBuffer)
- {
- LUAX_PREPARE(L, FileData);
- self->PushLuaxMemberRef(state, self->mDataRef);
- return 1;
- }
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/binding/_file_system.cpp b/source/libs/asura-lib-utils/io/binding/_file_system.cpp
deleted file mode 100644
index 3843451..0000000
--- a/source/libs/asura-lib-utils/io/binding/_file_system.cpp
+++ /dev/null
@@ -1,265 +0,0 @@
-#include "../file_system.h"
-
-using namespace Luax;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
-#define PREPARE(l) \
- LUAX_STATE(l); \
- Filesystem* fs = Filesystem::Get();
-
- LUAX_REGISTRY(Filesystem)
- {
- LUAX_REGISTER_METHODS(state,
- { "Init", _Init },
- { "Mount", _Mount },
- { "Unmount", _Unmount },
- { "GetMountPoint", _GetMountPoint },
- { "SetWriteDirectory", _SetWriteDirectory },
- { "GetWriteDirectory", _GetWriteDirectory },
- { "CreateFile", _CreateFile },
- { "CreateDirectory", _CreateDirectory },
- { "Write", _Write },
- { "Append", _Append },
- { "Remove", _Remove },
- { "Read", _Read },
- { "GetFileInfo", _GetFileInfo },
- { "GetDirectoryItems", _GetDirectoryItems }
- );
- }
-
- LUAX_POSTPROCESS(Filesystem)
- {
- LUAX_REGISTER_ENUM(state, "EFileType",
- { "FILE", FILE_TYPE_FILE },
- { "DIRECTORY", FILE_TYPE_DIRECTORY },
- { "SYMLINK", FILE_TYPE_SYMLINK },
- { "OTHER", FILE_TYPE_OTHER }
- );
- }
-
- // Filesystem.Init(arg0)
- LUAX_IMPL_METHOD(Filesystem, _Init)
- {
- PREPARE(L);
-
- const char* arg0 = state.CheckValue<const char*>(1);
- fs->Init(arg0);
- return 0;
- }
-
- // successed = Filesystem.Mount(path, mountpoint[, prepend = false])
- // successed = Filesystem.Mount(data buffer, archievename, mountpoint[, prepend = false])
- LUAX_IMPL_METHOD(Filesystem, _Mount)
- {
- PREPARE(L);
- bool mounted = false;
-
- if (state.IsType(1, LUA_TSTRING))
- {
- cc8* path = state.GetValue<cc8*>(1, "");
- cc8* moutpoint = state.GetValue<cc8*>(2, "/");
- bool prepend = state.GetValue<bool>(3, false);
- mounted = fs->Mount(path, moutpoint, prepend);
- }
- else if (state.IsType(1, LUA_TUSERDATA))
- {
- DataBuffer* db = state.CheckUserdata<DataBuffer>(1);
- if (!db)
- return state.ErrorType(1, "Data Buffer");
- cc8* arcname = state.GetValue<cc8*>(2, "");
- cc8* mountpoint = state.GetValue<cc8*>(3, "/");
- bool prepend = state.GetValue<bool>(4, false);
- mounted = fs->Mount(db, arcname, mountpoint, prepend);
- // retain
- fs->LuaxRetain<DataBuffer>(state, db);
- }
- state.Push(mounted);
- return 1;
- }
-
- // successed = Filesystem.Unmount(path)
- // successed = Filesystem.Unmount(data buffer)
- LUAX_IMPL_METHOD(Filesystem, _Unmount)
- {
- PREPARE(L);
- bool unmounted = false;
-
- if (state.IsType(1, LUA_TSTRING))
- {
- cc8* path = state.GetValue<cc8*>(1, "");
- unmounted = fs->Unmount(path);
- }
- else if (state.IsType(1, LUA_TUSERDATA))
- {
- DataBuffer* db = state.CheckUserdata<DataBuffer>(1);
- if (!db)
- return state.ErrorType(1, "Data Buffer");
- unmounted = fs->Unmount(db);
- if (unmounted)
- fs->LuaxRelease<DataBuffer>(state, db);
- }
- state.Push(unmounted);
- return 1;
- }
-
- // moutpoint = Filesystem.GetMountPoint(path)
- LUAX_IMPL_METHOD(Filesystem, _GetMountPoint)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- std::string mp;
- if (fs->GetMountPoint(path, ASURA_OUT mp))
- state.Push(mp);
- else
- state.PushNil();
-
- return 1;
- }
-
- // Filesystem.SetWriteDirectory(dir)
- LUAX_IMPL_METHOD(Filesystem, _SetWriteDirectory)
- {
- PREPARE(L);
-
- cc8* dir = state.CheckValue<cc8*>(1);
- fs->SetWriteDirectory(dir);
- return 0;
- }
-
- // dir = Filesystem.GetWriteDirectory()
- LUAX_IMPL_METHOD(Filesystem, _GetWriteDirectory)
- {
- PREPARE(L);
-
- std::string dir = fs->GetWriteDirectory();
- state.Push(dir);
- return 1;
- }
-
- // file = Filesystem.CreateFile(name)
- LUAX_IMPL_METHOD(Filesystem, _CreateFile)
- {
- PREPARE(L);
-
- cc8* name = state.CheckValue<cc8*>(1);
- File* file = fs->NewFile(name);
- if (file)
- file->PushLuaxUserdata(state);
- else
- state.PushNil();
- return 1;
- }
-
- // successed = Filesystem.CreateDirectory(name)
- LUAX_IMPL_METHOD(Filesystem, _CreateDirectory)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- state.Push(fs->NewDirectory(path));
- return 1;
- }
-
- // successed = Filesystem.Write(path, data buffer)
- LUAX_IMPL_METHOD(Filesystem, _Write)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
- state.Push(fs->Write(path, db));
- return 1;
- }
-
- // successed = Filesystem.Append(path, data buffer)
- LUAX_IMPL_METHOD(Filesystem, _Append)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
- state.Push(fs->Append(path, db));
- return 1;
- }
-
- // successed = Filesystem.Remove(path)
- LUAX_IMPL_METHOD(Filesystem, _Remove)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- state.Push(fs->Remove(path));
- return 1;
- }
-
- // filedata = Filesystem.Read(path)
- LUAX_IMPL_METHOD(Filesystem, _Read)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- FileData* fd = fs->Read(path);
- if (fd)
- {
- fd->mData->PushLuaxUserdata(state);
- fd->SetLuaxMemberRef(state, fd->mDataRef, -1); // fd->mDataRef = data buffer
- state.Pop(1); // data buffer
- fd->PushLuaxUserdata(state);
- }
- else
- {
- state.PushNil();
- }
- return 1;
- }
-
- // fileinfo = Filesystem.GetFileInfo(path)
- LUAX_IMPL_METHOD(Filesystem, _GetFileInfo)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- FileInfo info;
- if (fs->GetFileInfo(path, &info))
- {
- lua_newtable(L); // info table
- state.SetField(-1, "size", info.size);
- state.SetField(-1, "modtime", info.modtime);
- state.SetField(-1, "type", info.type);
- }
- else
- {
- state.PushNil();
- }
- return 1;
- }
-
- // items = Filesystem.GetDirectoryItems(path)
- LUAX_IMPL_METHOD(Filesystem, _GetDirectoryItems)
- {
- PREPARE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- std::vector<std::string> items;
- if(fs->GetDirectoryItems(path, ASURA_OUT items))
- {
- lua_newtable(L); // item list
- for (int i = 0; i < items.size(); ++i)
- {
- state.SetFieldByIndex(-1, i + 1, items[i]);
- }
- }
- else
- {
- state.PushNil();
- }
- return 1;
- }
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/binding/_io_task.cpp b/source/libs/asura-lib-utils/io/binding/_io_task.cpp
deleted file mode 100644
index b3c5988..0000000
--- a/source/libs/asura-lib-utils/io/binding/_io_task.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "../io_task.h"
-
-using namespace std;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- LUAX_REGISTRY(IOTask)
- {
- LUAX_REGISTER_METHODS(state,
- { "New", _New }
- );
- }
-
- LUAX_POSTPROCESS(IOTask)
- {
- LUAX_REGISTER_ENUM(state, "EIOTaskType",
- { "READ", IOTASK_TYPE_READ },
- { "WRITE", IOTASK_TYPE_WRITE },
- { "APPEND", IOTASK_TYPE_APPEND }
- );
-
- }
-
- // task = IOTask.New(path, buffer, type, callback)
- LUAX_IMPL_METHOD(IOTask, _New)
- {
- LUAX_STATE(L);
-
- cc8* path = state.CheckValue<cc8*>(1);
- DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
- IOTaskType type = (IOTaskType)state.CheckValue<int>(3);
- bool cbk = state.GetTop() >= 4 && state.IsType(4, LUA_TFUNCTION);
-
- IOTask* task = new IOTask(path, db, type);
- task->SetLuaxMemberRef(state, task->mBufferRef, 2);
- if(cbk)
- task->SetLuaxMemberRef(state, task->mCallback, 4);
- task->PushLuaxUserdata(state);
- return 1;
- }
-
- }
-}
diff --git a/source/libs/asura-lib-utils/io/compressor.cpp b/source/libs/asura-lib-utils/io/compressor.cpp
deleted file mode 100644
index 095eff4..0000000
--- a/source/libs/asura-lib-utils/io/compressor.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "compressor.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
-
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/compressor.h b/source/libs/asura-lib-utils/io/compressor.h
deleted file mode 100644
index 30a074c..0000000
--- a/source/libs/asura-lib-utils/io/compressor.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef __ASURA_COMPRESSOR_H__
-#define __ASURA_COMPRESSOR_H__
-
-#include "../scripting/portable.hpp"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- class Compressor ASURA_FINAL
- : public AEScripting::Portable<Compressor>
- {
- public:
-
- LUAX_DECL_SINGLETON(Compressor);
-
- private:
-
- LUAX_DECL_METHOD(_Compress);
- LUAX_DECL_METHOD(_Decompress);
-
-
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp
deleted file mode 100644
index 5049b38..0000000
--- a/source/libs/asura-lib-utils/io/data_buffer.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-#include <cstdlib>
-#include <cstring>
-#include "data_buffer.h"
-
-using namespace AEThreading;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- DataBuffer::DataBuffer(DataBuffer& src)
- {
- Load(src);
- }
-
- DataBuffer::DataBuffer(std::size_t size)
- : mSize(size)
- , mBytes(nullptr)
- {
- lock(mMutex);
- mBytes = new byte[size];
- memset(mBytes, 0, size);
- }
-
- DataBuffer::DataBuffer(const void* data, std::size_t size)
- : mSize(size)
- , mBytes(nullptr)
- {
- Load(data, size);
- }
-
- DataBuffer::~DataBuffer()
- {
- delete[] mBytes;
- }
-
- void DataBuffer::Refactor(size_t size)
- {
- lock(mMutex);
- if (!mBytes || mSize != size)
- {
- delete[] mBytes;
- mBytes = new byte[size];
- mSize = size;
- }
- memset(mBytes, 0, size * sizeof(byte));
- }
-
- size_t DataBuffer::Load(DataBuffer& db)
- {
- return Load(db.GetData(), db.GetSize());
- }
-
- size_t DataBuffer::Load(const void* data, std::size_t size)
- {
- lock(mMutex);
- size_t len = mSize > size ? size : mSize;
- memcpy(mBytes, data, len);
- return len;
- }
-
- void DataBuffer::Move(void* bytes, std::size_t size)
- {
- lock(mMutex);
- if (!mBytes)
- {
- delete[] mBytes;
- }
- mBytes = (byte*)bytes;
- mSize = size;
- }
-
- byte* DataBuffer::GetData()
- {
- return mBytes;
- }
-
- void DataBuffer::Clear()
- {
- lock(mMutex);
- if (mBytes)
- memset(mBytes, 0, mSize);
- }
-
- std::size_t DataBuffer::GetSize()
- {
- return mSize;
- }
-
- void DataBuffer::Lock()
- {
- mMutex.Lock();
- }
-
- void DataBuffer::Unlock()
- {
- mMutex.Unlock();
- }
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/data_buffer.h b/source/libs/asura-lib-utils/io/data_buffer.h
deleted file mode 100644
index 445bdf4..0000000
--- a/source/libs/asura-lib-utils/io/data_buffer.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef __ASURA_ENGINE_DATABUFFER_H__
-#define __ASURA_ENGINE_DATABUFFER_H__
-
-#include <cstdlib>
-
-#include "../scripting/portable.hpp"
-#include "../threading/mutex.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- ///
- /// ڴݵķװеʹData bufferװֱʹconst void*ͨresource managerȡ
- ///
- class DataBuffer ASURA_FINAL
- : public AEScripting::Portable<DataBuffer>
- {
- public:
-
- LUAX_DECL_FACTORY(DataBuffer);
-
- DataBuffer(DataBuffer& src);
- DataBuffer(std::size_t size);
- DataBuffer(const void* bytes, std::size_t size);
- ~DataBuffer();
-
- byte* GetData();
- size_t GetSize();
-
- void Refactor(size_t size);
- size_t Load(DataBuffer& db);
- size_t Load(const void* bytes, std::size_t size);
- void Move(void* bytes, std::size_t size);
- void Clear();
-
- void Lock();
- void Unlock();
-
- private:
-
- byte* mBytes;
- size_t mSize;
-
- AEThreading::Mutex mMutex;
-
- LUAX_DECL_METHOD(_New);
- LUAX_DECL_METHOD(_GetData);
- LUAX_DECL_METHOD(_GetSize);
- LUAX_DECL_METHOD(_Refactor);
- LUAX_DECL_METHOD(_Load);
- LUAX_DECL_METHOD(_Clear);
-
- };
-
- }
-}
-
-namespace AEIO = AsuraEngine::IO;
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/decoded_data.cpp b/source/libs/asura-lib-utils/io/decoded_data.cpp
deleted file mode 100644
index 358a7a5..0000000
--- a/source/libs/asura-lib-utils/io/decoded_data.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "../exceptions/exception.h"
-
-#include "decoded_data.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- DecodedData::DecodedData(const DataBuffer& databuffer)
- {
- Decode(databuffer);
- }
-
- DecodedData::~DecodedData()
- {
-
- }
-
- }
-}
diff --git a/source/libs/asura-lib-utils/io/decoded_data.h b/source/libs/asura-lib-utils/io/decoded_data.h
deleted file mode 100644
index e201e91..0000000
--- a/source/libs/asura-lib-utils/io/decoded_data.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef __ASURA_ENGINE_DATA_H__
-#define __ASURA_ENGINE_DATA_H__
-
-#include <cstdlib>
-
-#include "../scripting/portable.hpp"
-
-#include "data_buffer.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- ///
- /// һ̹߳data̳дࡣͼƬݡƵݵȣһ߳нԭļڲݸʽ
- /// ȡ
- ///
- ASURA_ABSTRACT class DecodedData
- {
- public:
-
- ///
- /// ڴйdataԷһ߳棬Դϵͳء
- ///
- DecodedData(const DataBuffer& databuffer);
-
- virtual ~DecodedData();
-
- protected:
-
- ///
- /// ڴеݡ
- ///
- virtual void Decode(const DataBuffer& buffer) = 0;
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/file.cpp b/source/libs/asura-lib-utils/io/file.cpp
deleted file mode 100644
index 0ff8c90..0000000
--- a/source/libs/asura-lib-utils/io/file.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-#include <physfs/physfs.h>
-
-#include <asura-lib-utils/exceptions/exception.h>
-
-#include "file.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- File::File(const std::string& filename)
- : mFileName(filename)
- , mFileHandle(nullptr)
- , mMode(FILE_MODE_CLOSED)
- , mBufferMode(BUFFER_MODE_NONE)
- , mBufferSize(0)
- {
- size_t dot = filename.rfind('.');
- if (dot != std::string::npos)
- {
- mExtension = filename.substr(dot + 1);
- mName = filename.substr(0, dot);
- }
- else
- mName = filename;
- }
-
- File::~File()
- {
- if (mMode != FILE_MODE_CLOSED)
- Close();
- }
-
- bool File::Open(FileMode mode)
- {
- if (!PHYSFS_isInit())
- throw Exception("Physfs is NOT initialized.");
-
- if (mode == FILE_MODE_CLOSED)
- return false;
-
- if (mode == FILE_MODE_READ && !PHYSFS_exists(mFileName.c_str()))
- throw Exception("Could NOT open file %s. Does not exist.", mFileName.c_str());
-
- if (mode == FILE_MODE_APPEND || mode == FILE_MODE_WRITE)
- {
- if (!PHYSFS_getWriteDir())
- {
- throw Exception("Could NOT set write directory.");
- }
- }
-
- // Ѿ֮ǰ򿪹Ͳٴµhandle
- if (mFileHandle != nullptr)
- return true;
-
- PHYSFS_getLastErrorCode();
-
- PHYSFS_File* handle = nullptr;
-
- switch (mode)
- {
- case FILE_MODE_READ:
- handle = PHYSFS_openRead(mFileName.c_str());
- break;
- case FILE_MODE_APPEND:
- handle = PHYSFS_openAppend(mFileName.c_str());
- break;
- case FILE_MODE_WRITE:
- handle = PHYSFS_openWrite(mFileName.c_str());
- break;
- }
-
- if (handle == nullptr)
- {
- const char *err = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
- if (err == nullptr)
- err = "unknown error";
- throw Exception("Could not open file %s (%s)", mFileName.c_str(), err);
- }
-
- mFileHandle = handle;
- mMode = mode;
-
- if (mFileHandle && !SetBuffer(mBufferMode,mBufferSize))
- {
- mBufferMode = BUFFER_MODE_NONE;
- mBufferSize = 0;
- }
-
- return mFileHandle != nullptr;
- }
-
- bool File::Close()
- {
- if (mFileHandle == nullptr || !PHYSFS_close(mFileHandle))
- return false;
- mMode = FILE_MODE_CLOSED;
- mFileHandle = nullptr;
- return true;
- }
-
- bool File::IsOpen()
- {
- return mMode != FILE_MODE_CLOSED && mFileHandle != nullptr;
- }
-
- size_t File::GetSize()
- {
- if (mFileHandle == nullptr)
- {
- Open(FILE_MODE_READ);
- size_t size = PHYSFS_fileLength(mFileHandle);
- Close();
- return size;
- }
- return PHYSFS_fileLength(mFileHandle);
- }
-
- size_t File::Read(ASURA_OUT DataBuffer* dst, size_t length)
- {
- ASSERT(dst);
-
- if (dst->GetSize() < length)
- throw Exception("Data buffer is too small compares to read length.");
-
- if (!mFileHandle || mMode != FILE_MODE_READ)
- throw Exception("File \"%s\" is not opened for reading", mFileName);
-
- size_t max = PHYSFS_fileLength(mFileHandle);
- length = (length > max) ? max : length;
-
- if (length < 0)
- throw Exception("Invalid read size.");
-
- dst->Lock();
- size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
- dst->Unlock();
- return size;
- }
-
- size_t File::ReadAll(ASURA_OUT DataBuffer* dst)
- {
- ASSERT(dst);
-
- if (!mFileHandle || mMode != FILE_MODE_READ)
- throw Exception("File \"%s\" is not opened for reading", mFileName);
-
- size_t length = PHYSFS_fileLength(mFileHandle);
-
- if (dst->GetSize() < length)
- throw Exception("Data buffer is too small compares to file length.");
-
- dst->Lock();
- size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
- dst->Unlock();
- return size;
- }
-
-#ifdef ASURA_WINDOWS
- inline bool test_eof(File *that, PHYSFS_File *)
- {
- int64 pos = that->Tell();
- int64 size = that->GetSize();
- return pos == -1 || size == -1 || pos >= size;
- }
-#else
- inline bool test_eof(File *, PHYSFS_File *file)
- {
- return PHYSFS_eof(file);
- }
-#endif
-
- bool File::IsEOF()
- {
- return mFileHandle == nullptr || test_eof(this, mFileHandle);
- }
-
- size_t File::Tell()
- {
- if (!mFileHandle)
- return - 1;
-
- return PHYSFS_tell(mFileHandle);
- }
-
- bool File::Seek(size_t pos)
- {
- return mFileHandle != nullptr && PHYSFS_seek(mFileHandle, pos) != 0;
- }
-
- bool File::Write(ASURA_REF DataBuffer* src)
- {
- if (!mFileHandle || (mMode != FILE_MODE_APPEND && mMode != FILE_MODE_WRITE))
- throw Exception("File is not opened for writing.");
-
- byte* data = src->GetData();
- int size = src->GetSize();
-
- if (size < 0)
- throw Exception("Invalid write size.");
-
- size_t written = PHYSFS_writeBytes(mFileHandle, data, size);
-
- if (written != src->GetSize())
- return false;
-
- // л
- if (mBufferSize == BUFFER_MODE_LINE && mBufferSize > size)
- {
- if (memchr(data, '\n', size) != nullptr)
- Flush();
- }
-
- return true;
- }
-
- bool File::Flush()
- {
- if (!mFileHandle || (mMode != FILE_MODE_WRITE && mMode != FILE_MODE_APPEND))
- throw Exception("File is not opened for writing.");
-
- return PHYSFS_flush(mFileHandle) != 0;
- }
-
- bool File::SetBuffer(BufferMode mode, size_t size)
- {
- if (size < 0)
- return false;
-
- // If the file isn't open, we'll make sure the buffer values are set in
- // File::open.
- if (!IsOpen())
- {
- mBufferMode = mode;
- mBufferSize = size;
- return true;
- }
-
- int ret = 1;
-
- switch (mode)
- {
- case BUFFER_MODE_NONE:
- default:
- ret = PHYSFS_setBuffer(mFileHandle, 0);
- size = 0;
- break;
- case BUFFER_MODE_LINE:
- case BUFFER_MODE_FULL:
- ret = PHYSFS_setBuffer(mFileHandle, size);
- break;
- }
-
- if (ret == 0)
- return false;
-
- mBufferMode = mode;
- mBufferSize = size;
-
- return true;
- }
-
- File::BufferMode File::GetBuffer(ASURA_OUT size_t& size)
- {
- size = mBufferSize;
- return mBufferMode;
- }
-
- const std::string& File::GetFileName()
- {
- return mFileName;
- }
-
- const std::string& File::GetName()
- {
- return mName;
- }
-
- const std::string& File::GetExtension()
- {
- return mExtension;
- }
-
- File::FileMode File::GetMode()
- {
- return mMode;
- }
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/file.h b/source/libs/asura-lib-utils/io/file.h
deleted file mode 100644
index 56077e0..0000000
--- a/source/libs/asura-lib-utils/io/file.h
+++ /dev/null
@@ -1,146 +0,0 @@
-#ifndef __ASURA_ENGINE_FILE_H__
-#define __ASURA_ENGINE_FILE_H__
-
-#include "physfs/physfs.h"
-
-#include "../scripting/portable.hpp"
-#include "../threading/thread.h"
-
-#include "file_data.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- ///
- /// ʽļָд㡢Сʹȡʱʹñ࣬ʹFilesystem.read()ֱӶȡļȫ
- /// ݣһFileData
- ///
- class File ASURA_FINAL
- : public AEScripting::Portable<File>
- {
- public:
-
- LUAX_DECL_FACTORY(File);
-
- ///
- /// ļдģʽ
- ///
- enum FileMode
- {
- FILE_MODE_CLOSED,
- FILE_MODE_READ,
- FILE_MODE_WRITE,
- FILE_MODE_APPEND,
- };
-
- ///
- /// ļдʱΪ
- ///
- enum BufferMode
- {
- BUFFER_MODE_NONE, ///< ʹû壬дļ
- BUFFER_MODE_LINE, ///< л壬зߴﵽСʱдļ
- BUFFER_MODE_FULL, ///< ȫ壬ʱдļ
- };
-
- File(const std::string& filename);
- ~File();
-
- bool Open(FileMode mode);
- bool Close();
- bool IsOpen();
- FileMode GetMode();
- size_t GetSize();
-
- ///
- /// ȡdata bufferض
- ///
- size_t Read(ASURA_OUT DataBuffer* dst, size_t length);
- size_t ReadAll(ASURA_OUT DataBuffer* dst);
- size_t ReadAsync(ASURA_OUT DataBuffer* dst);
-
- ///
- /// Ƿļβ
- ///
- bool IsEOF();
-
- ///
- /// data bufferед룬Ƿɹ
- ///
- bool Write(ASURA_REF DataBuffer* src);
-
- ///
- /// 첽дļдļtaskthreadĶС
- ///
- bool WriteAsync(ASURA_REF DataBuffer* src, AEThreading::Thread* thread);
-
- ///
- /// ˻壬ǿջдļ
- ///
- bool Flush();
-
- ///
- /// صǰдλ
- ///
- size_t Tell();
-
- ///
- /// Ӧλ
- ///
- bool Seek(size_t pos);
-
- ///
- /// ûСģʽ
- ///
- bool SetBuffer(BufferMode mode, size_t size);
-
- ///
- /// ȡСģʽ
- ///
- BufferMode GetBuffer(ASURA_OUT size_t& size);
-
- const std::string& GetFileName();
- const std::string& GetName();
- const std::string& GetExtension();
-
- private:
-
- PHYSFS_File* mFileHandle; ///< physfs ļ
- std::string mFileName; ///< ļ
- std::string mExtension; ///< չ
- std::string mName; ///< չļ
- FileMode mMode; ///< ļģʽ
- BufferMode mBufferMode; ///< д뻺ģʽ
- size_t mBufferSize; ///< д뻺С
-
- LUAX_DECL_ENUM(FileMode);
- LUAX_DECL_ENUM(BufferMode);
-
- LUAX_DECL_METHOD(_New);
- LUAX_DECL_METHOD(_Open);
- LUAX_DECL_METHOD(_Close);
- LUAX_DECL_METHOD(_IsOpen);
- LUAX_DECL_METHOD(_GetMode);
- LUAX_DECL_METHOD(_GetSize);
- LUAX_DECL_METHOD(_Read);
- LUAX_DECL_METHOD(_Write);
- LUAX_DECL_METHOD(_ReadAsync);
- LUAX_DECL_METHOD(_WriteAsync);
- LUAX_DECL_METHOD(_IsEOF);
- LUAX_DECL_METHOD(_Flush);
- LUAX_DECL_METHOD(_Tell);
- LUAX_DECL_METHOD(_Seek);
- LUAX_DECL_METHOD(_SetBuffer);
- LUAX_DECL_METHOD(_GetBuffer);
- LUAX_DECL_METHOD(_GetFileName);
- LUAX_DECL_METHOD(_GetExtension);
- LUAX_DECL_METHOD(_GetName);
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/file_data.cpp b/source/libs/asura-lib-utils/io/file_data.cpp
deleted file mode 100644
index 92333cf..0000000
--- a/source/libs/asura-lib-utils/io/file_data.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "file_data.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- FileData::FileData(const std::string& filename)
- : mData(nullptr)
- , mFileName(filename)
- {
- size_t dot = filename.rfind('.');
- if (dot != std::string::npos)
- {
- mExtension = filename.substr(dot + 1);
- mName = filename.substr(0, dot);
- }
- else
- mName = filename;
- }
-
- FileData::~FileData()
- {
- }
-
- const std::string& FileData::GetFileName()
- {
- return mFileName;
- }
-
- const std::string& FileData::GetExtension()
- {
- return mExtension;
- }
-
- const std::string& FileData::GetName()
- {
- return mName;
- }
-
- void FileData::BindData(ASURA_MOVE DataBuffer* buffer)
- {
- mData = buffer;
- }
-
- DataBuffer* FileData::GetDataBuffer()
- {
- return mData;
- }
-
- }
-}
diff --git a/source/libs/asura-lib-utils/io/file_data.h b/source/libs/asura-lib-utils/io/file_data.h
deleted file mode 100644
index 9aa0e3b..0000000
--- a/source/libs/asura-lib-utils/io/file_data.h
+++ /dev/null
@@ -1,69 +0,0 @@
-#ifndef __ASURA_ENGINE_FILE_DATA_H__
-#define __ASURA_ENGINE_FILE_DATA_H__
-
-#include <string>
-
-#include <asura-lib-utils/scripting/portable.hpp>
-
-#include "data_buffer.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- class Filesystem;
-
- ///
- /// filesystemֱӶȡļʱFileDataļݺϢFilesystem
- ///
- class FileData ASURA_FINAL
- : public AEScripting::Portable<FileData>
- {
- public:
-
- LUAX_DECL_FACTORY(FileData);
-
- ~FileData();
-
- ///
- /// ļݣͨDatabufferݺʹСڲӿڶData bufferΪҲdata buffer
- ///
- DataBuffer* GetDataBuffer();
-
- const std::string& GetFileName();
- const std::string& GetExtension();
- const std::string& GetName();
-
- private:
-
- friend class Filesystem;
-
- FileData(const std::string& name);
-
- ///
- /// data buffer
- ///
- void BindData(ASURA_MOVE DataBuffer* buffer);
-
- ///
- /// Data bufferfiledataʱ٣luaüΪ0ʱluaGC١mDataʱһԱá
- ///
- ASURA_REF DataBuffer* mData;
- Luax::LuaxMemberRef mDataRef;
-
- std::string mFileName; ///< չļ
- std::string mExtension; ///< չ
- std::string mName; ///< ͺ׺ļ
-
- LUAX_DECL_METHOD(_GetDataBuffer);
- LUAX_DECL_METHOD(_GetFileName);
- LUAX_DECL_METHOD(_GetExtension);
- LUAX_DECL_METHOD(_GetName);
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/file_system.cpp b/source/libs/asura-lib-utils/io/file_system.cpp
deleted file mode 100644
index 20f3cb2..0000000
--- a/source/libs/asura-lib-utils/io/file_system.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-#include <physfs/physfs.h>
-
-#include "../exceptions/exception.h"
-
-#include "file.h"
-#include "file_data.h"
-#include "file_system.h"
-
-using namespace std;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
-#ifdef ASURA_WINDOWS
- #include <windows.h>
- #include <direct.h>
-#else
- #include <sys/param.h>
- #include <unistd.h>
-#endif
-
- Filesystem::~Filesystem()
- {
- if (mInited) //PHYSFS_isInit
- PHYSFS_deinit();
- }
-
- void Filesystem::Init(const char* arg0)
- {
- if (!PHYSFS_init(arg0))
- throw Exception("Failed to initialize filesystem: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
-
- mInited = true;
- }
-
- bool Filesystem::Mount(const std::string& locpath, const std::string& montpoint/* = "/"*/, bool prepend /*= false*/)
- {
- if (!mInited)
- return false;
-
- return PHYSFS_mount(locpath.c_str(), montpoint.c_str(), !prepend);
- }
-
- bool Filesystem::Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint /*= "/"*/, bool prepend /*= false*/)
- {
- if (!mInited)
- return false;
- if (PHYSFS_mountMemory(db->GetData(), db->GetSize(), nullptr, archivename.c_str(), mountpoint.c_str(), !prepend))
- {
- mMountData[archivename] = db;
- return true;
- }
- return false;
- }
-
- bool Filesystem::Unmount(const std::string& locpath)
- {
- if (!mInited)
- return false;
-
- // ǹ鵵ӳɾ
- auto datait = mMountData.find(locpath);
- if (datait != mMountData.end() && PHYSFS_unmount(locpath.c_str()) != 0)
- {
- mMountData.erase(datait);
- return true;
- }
-
- return PHYSFS_unmount(locpath.c_str());
- }
-
- bool Filesystem::Unmount(DataBuffer* db)
- {
- for (const auto& dp : mMountData)
- {
- if (dp.second == db)
- {
- std::string archive = dp.first;
- return Unmount(archive);
- }
- }
- }
-
- bool Filesystem::GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint)
- {
- if (!mInited)
- return false;
- const char* point = PHYSFS_getMountPoint(locpath.c_str());
- if (point != nullptr)
- {
- mountpoint = point;
- return true;
- }
- return false;
- }
-
- void Filesystem::SetWriteDirectory(const std::string locpath)
- {
- if (!mInited)
- return;
- if (!PHYSFS_setWriteDir(locpath.c_str()))
- throw Exception("Failed to set write directory %s", locpath.c_str());
- }
-
- std::string Filesystem::GetWriteDirectory()
- {
- return PHYSFS_getWriteDir();
- }
-
- File* Filesystem::NewFile(const std::string& name)
- {
- return new File(name);
- }
-
- bool Filesystem::NewDirectory(const std::string& path)
- {
- if (!mInited)
- return false;
- if (!PHYSFS_getWriteDir())
- return false;
- if (!PHYSFS_mkdir(path.c_str()))
- return false;
- return true;
- }
-
- bool Filesystem::Write(const std::string& name, ASURA_REF DataBuffer* buffer)
- {
- File file(name);
- file.Open(File::FILE_MODE_WRITE);
- if (!file.Write(buffer))
- throw Exception("Data could not be written.");
- }
-
- bool Filesystem::Append(const std::string& name, ASURA_REF DataBuffer* buffer)
- {
- File file(name);
- file.Open(File::FILE_MODE_APPEND);
- if (!file.Write(buffer))
- throw Exception("Data could not be append.");
- }
-
- FileData* Filesystem::Read(const std::string& name)
- {
- File file = File(name);
- file.Open(File::FILE_MODE_READ);
- int size = file.GetSize();
- DataBuffer* db = new DataBuffer(size);
- if (db)
- {
- file.ReadAll(db);
- FileData* fd = new FileData(name);
- fd->BindData(db);
- return fd;
- }
- return nullptr;
- }
-
- bool Filesystem::Remove(const std::string& path)
- {
- if (!mInited)
- return false;
- if (PHYSFS_getWriteDir() == 0)
- return false;
-
- if (!PHYSFS_delete(path.c_str()))
- return false;
-
- return true;
- }
-
- bool Filesystem::GetFileInfo(const std::string& filepath, ASURA_OUT FileInfo* info)
- {
- if (!mInited)
- return false;
-
- PHYSFS_Stat stat = {};
- if (!PHYSFS_stat(filepath.c_str(), &stat))
- return false;
-
- info->size = (int64)stat.filesize;
- info->modtime = (int64)stat.modtime;
-
- if (stat.filetype == PHYSFS_FILETYPE_REGULAR)
- info->type = FILE_TYPE_FILE;
- else if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY)
- info->type = FILE_TYPE_DIRECTORY;
- else if (stat.filetype == PHYSFS_FILETYPE_SYMLINK)
- info->type = FILE_TYPE_SYMLINK;
- else
- info->type = FILE_TYPE_OTHER;
-
- return true;
- }
-
- }
-} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/file_system.h b/source/libs/asura-lib-utils/io/file_system.h
deleted file mode 100644
index 849cbb6..0000000
--- a/source/libs/asura-lib-utils/io/file_system.h
+++ /dev/null
@@ -1,112 +0,0 @@
-#ifndef __ASURA_ENGINE_FILESYSTEM_H__
-#define __ASURA_ENGINE_FILESYSTEM_H__
-
-#include <map>
-#include <string>
-
-#include "../scripting/portable.hpp"
-#include "../singleton.hpp"
-#include "../type.h"
-
-#include "file_data.h"
-#include "file.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- enum FileType
- {
- FILE_TYPE_FILE, ///< ļ
- FILE_TYPE_DIRECTORY, ///< ļ
- FILE_TYPE_SYMLINK, ///<
- FILE_TYPE_OTHER, ///<
- };
-
- struct FileInfo
- {
- int64 size;
- int64 modtime;
- FileType type;
- };
-
- ///
- /// Դء洢ԴָĿ¼ȡ۱༭ʱҪƷʵĻƣûIJϷĿ¼
- /// £file systemµġFilesystemʱͱ༭õ࣬AssetDatabaseԴ࣬framework
- /// ʵ֣߼дFilesystemʵ֣AssetDatabaseṩļݴӦԴķ
- ///
- class Filesystem ASURA_FINAL
- : public Singleton<Filesystem>
- , public AEScripting::Portable<Filesystem>
- {
- public:
-
- LUAX_DECL_SINGLETON(Filesystem);
-
- ~Filesystem();
-
- void Init(const char* arg0);
-
- ///
- /// ǰִļļ
- ///
- std::string GetWorkingDirectory();
-
- bool Mount(const std::string& locpath, const std::string& montpoint = "/", bool prepend = false);
- bool Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint = "/", bool prepend = false);
-
- bool Unmount(const std::string& locpath);
- bool Unmount(DataBuffer* db);
-
- bool GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint);
-
- void SetWriteDirectory(const std::string locpath);
- std::string GetWriteDirectory();
- File* NewFile(const std::string& name);
- bool NewDirectory(const std::string& path);
- bool Write(const std::string& path, ASURA_REF DataBuffer* buffer);
- bool Append(const std::string& path, ASURA_REF DataBuffer* buffer);
- bool Remove(const std::string& path);
-
- FileData* Read(const std::string& path);
- bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info);
-
- bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector<std::string>& items) { return false; };
-
- private:
-
- typedef std::map<std::string, DataBuffer*> MountDataMap;
-
- bool mInited; ///< Ƿʼɹ
- std::string mCwd; ///< ǰִļĹĿ¼
- MountDataMap mMountData; ///< ·ѹĵӳ
-
- LUAX_DECL_METHOD(_Init);
- LUAX_DECL_METHOD(_Mount);
- LUAX_DECL_METHOD(_Unmount);
- LUAX_DECL_METHOD(_GetMountPoint);
-
- LUAX_DECL_METHOD(_SetWriteDirectory);
- LUAX_DECL_METHOD(_GetWriteDirectory);
- LUAX_DECL_METHOD(_CreateFile);
- LUAX_DECL_METHOD(_CreateDirectory);
-
- LUAX_DECL_METHOD(_Write);
- LUAX_DECL_METHOD(_Append);
- LUAX_DECL_METHOD(_Remove);
-
- LUAX_DECL_METHOD(_Read);
-
- LUAX_DECL_METHOD(_GetFileInfo);
-
- LUAX_DECL_METHOD(_GetDirectoryItems);
-
- };
-
- }
-}
-
-namespace AEIO = AsuraEngine::IO;
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/io_batch_task.cpp b/source/libs/asura-lib-utils/io/io_batch_task.cpp
deleted file mode 100644
index e69de29..0000000
--- a/source/libs/asura-lib-utils/io/io_batch_task.cpp
+++ /dev/null
diff --git a/source/libs/asura-lib-utils/io/io_batch_task.h b/source/libs/asura-lib-utils/io/io_batch_task.h
deleted file mode 100644
index c0be921..0000000
--- a/source/libs/asura-lib-utils/io/io_batch_task.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef __ASURA_IO_BATCH_TASK_H__
-#define __ASURA_IO_BATCH_TASK_H__
-
-#include "io_task.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- ///
- /// дһύһtableδ󷵻ؽ
- ///
- class IOBatchTask ASURA_FINAL : public AEThreading::Task
- {
- public:
-
- private:
-
- ///
- /// ÿһĽṹ£
- /// { path = "", }
- ///
- Luax::LuaxMemberRef mTasks;
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/io_task.cpp b/source/libs/asura-lib-utils/io/io_task.cpp
deleted file mode 100644
index 361b9c5..0000000
--- a/source/libs/asura-lib-utils/io/io_task.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#include "file_system.h"
-#include "io_task.h"
-
-#include <iostream>
-
-using namespace AEScripting;
-using namespace Luax;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- IOTask::IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type)
- : mPath(path)
- , mBuffer(buffer)
- {
- }
-
- IOTask::~IOTask()
- {
- }
-
- bool IOTask::Execute()
- {
- File file(mPath);
- if (mType == IOTASK_TYPE_WRITE)
- {
-
- }
- // pathȡݱmBuffer
- else if (mType == IOTASK_TYPE_READ)
- {
- file.Open(File::FILE_MODE_READ);
- file.ReadAll(mBuffer);
- file.Close();
- }
- return true;
- }
-
- void IOTask::Invoke(lua_State* invokeThreaad)
- {
- if (mCallback)
- {
- LuaxScopedState state(invokeThreaad);
- if (PushLuaxMemberRef(state, mCallback))
- {
- PushLuaxMemberRef(state, mBufferRef);
- state.Call(1, 0);
- }
- }
- }
-
- }
-}
diff --git a/source/libs/asura-lib-utils/io/io_task.h b/source/libs/asura-lib-utils/io/io_task.h
deleted file mode 100644
index 8f04142..0000000
--- a/source/libs/asura-lib-utils/io/io_task.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef __ASURA_IO_TASK_H__
-#define __ASURA_IO_TASK_H__
-
-#include <string>
-
-#include "../scripting/portable.hpp"
-#include "../threading/task.h"
-
-#include "data_buffer.h"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- enum IOTaskType
- {
- IOTASK_TYPE_READ,
- IOTASK_TYPE_WRITE,
- IOTASK_TYPE_APPEND,
- };
-
- ///
- /// ȡļ
- ///
- class IOTask ASURA_FINAL
- : public AEThreading::Task
- , public AEScripting::Portable<IOTask>
- {
- public:
-
- LUAX_DECL_FACTORY(IOTask);
-
- IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type);
- ~IOTask();
-
- bool Execute() override ;
- void Invoke(lua_State* invokeThreaad) override;
-
- private:
-
- LUAX_DECL_ENUM(IOTaskType);
-
- LUAX_DECL_METHOD(_New);
-
- std::string mPath;
- IOTaskType mType;
-
- ASURA_REF DataBuffer* mBuffer;
- Luax::LuaxMemberRef mBufferRef;
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/reloadable.h b/source/libs/asura-lib-utils/io/reloadable.h
deleted file mode 100644
index 22a721c..0000000
--- a/source/libs/asura-lib-utils/io/reloadable.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef __ASURA_ENGINE_RELOADABLE_H__
-#define __ASURA_ENGINE_RELOADABLE_H__
-
-#include "../scripting/portable.hpp"
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- ///
- /// ¹ݽṹͼƬƵ֣ⲿݿֱӹڱ༭¹ڲıhandleԴ
- ///
- ASURA_ABSTRACT class Reloadable
- {
- public:
- Reloadable();
- virtual ~Reloadable();
-
- // ̳ReloadableҪṩһload
-
- };
-
- }
-}
-
-namespace AEIO = AsuraEngine::IO;
-
-#endif \ No newline at end of file