public static void AddFileOperationToQueue(string filePath, byte[] content, string method, bool insert = false, string guid = null) { AsyncFileOperationData operationData = new AsyncFileOperationData(); operationData.filePath = filePath; operationData.content = content; operationData.method = method; operationData.guid = guid; lock (s_queue) { if (insert) { s_queue.Insert(0, operationData); } else { s_queue.Add(operationData); } } if (s_thread == null) { StartFileOperationThread(); } }
public static AsyncFileOperationData GetFinishedAsyncFileOperationData() { lock (s_finished_queue) { if (s_finished_queue.Count > 0) { AsyncFileOperationData operationData = s_finished_queue.Dequeue(); return(operationData); } return(null); } }
static int QPYX_GetFinishedAsyncFileOperationData_YXQP(IntPtr L_YXQP) { try { ToLua.CheckArgsCount(L_YXQP, 0); AsyncFileOperationData QPYX_o_YXQP = AsyncFileUtil.GetFinishedAsyncFileOperationData(); ToLua.PushObject(L_YXQP, QPYX_o_YXQP); return(1); } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static int GetFinishedAsyncFileOperationData(IntPtr L) { try { ToLua.CheckArgsCount(L, 0); AsyncFileOperationData o = AsyncFileUtil.GetFinishedAsyncFileOperationData(); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private static void OperationLoop() { while (!s_end) { Thread.Sleep(10); lock (s_queue) { if (s_queue.Count > 0) { AsyncFileOperationData operationData = s_queue[0]; s_queue.RemoveAt(0); if (!operationData.drop) { if (operationData.method == "delete") { if (FileUtility.Exists(operationData.filePath)) { FileUtility.Delete(operationData.filePath); } for (int i = 0; i < s_queue.Count; i++) { if (s_queue[i].filePath == operationData.filePath) { s_queue[i].drop = true; } } } else if (operationData.method == "append") { FileUtility.SaveFile(operationData.filePath, operationData.content, true); } else if (operationData.method == "write") { FileUtility.SaveFile(operationData.filePath, operationData.content, false); } else if (operationData.method == "readAllBytes") { byte[] bytes = FileUtility.ReadAllBytes(operationData.filePath); operationData.content = bytes; lock (s_finished_queue) { s_finished_queue.Enqueue(operationData); } } } } } } }
static int set_content(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AsyncFileOperationData obj = (AsyncFileOperationData)o; byte[] arg0 = ToLua.CheckByteBuffer(L, 2); obj.content = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index content on a nil value")); } }
static int get_drop(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AsyncFileOperationData obj = (AsyncFileOperationData)o; bool ret = obj.drop; LuaDLL.lua_pushboolean(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index drop on a nil value")); } }
static int get_method(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AsyncFileOperationData obj = (AsyncFileOperationData)o; string ret = obj.method; LuaDLL.lua_pushstring(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index method on a nil value")); } }
static int get_content(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AsyncFileOperationData obj = (AsyncFileOperationData)o; byte[] ret = obj.content; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index content on a nil value")); } }
static int set_guid(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AsyncFileOperationData obj = (AsyncFileOperationData)o; string arg0 = ToLua.CheckString(L, 2); obj.guid = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index guid on a nil value")); } }
static int set_drop(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AsyncFileOperationData obj = (AsyncFileOperationData)o; bool arg0 = LuaDLL.luaL_checkboolean(L, 2); obj.drop = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index drop on a nil value")); } }
static int QPYX__CreateAsyncFileOperationData_YXQP(IntPtr L_YXQP) { try { int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP); if (QPYX_count_YXQP == 0) { AsyncFileOperationData QPYX_obj_YXQP = new AsyncFileOperationData(); ToLua.PushObject(L_YXQP, QPYX_obj_YXQP); return(1); } else { return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to ctor method: AsyncFileOperationData.New")); } } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static int _CreateAsyncFileOperationData(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { AsyncFileOperationData obj = new AsyncFileOperationData(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: AsyncFileOperationData.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int QPYX_get_drop_YXQP(IntPtr L_YXQP) { object QPYX_o_YXQP = null; try { QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1); AsyncFileOperationData QPYX_obj_YXQP = (AsyncFileOperationData)QPYX_o_YXQP; bool QPYX_ret_YXQP = QPYX_obj_YXQP.drop; LuaDLL.lua_pushboolean(L_YXQP, QPYX_ret_YXQP); return(1); } catch (Exception QPYX_e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index drop on a nil value")); } }
static int QPYX_get_method_YXQP(IntPtr L_YXQP) { object QPYX_o_YXQP = null; try { QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1); AsyncFileOperationData QPYX_obj_YXQP = (AsyncFileOperationData)QPYX_o_YXQP; string QPYX_ret_YXQP = QPYX_obj_YXQP.method; LuaDLL.lua_pushstring(L_YXQP, QPYX_ret_YXQP); return(1); } catch (Exception QPYX_e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index method on a nil value")); } }
static int QPYX_get_content_YXQP(IntPtr L_YXQP) { object QPYX_o_YXQP = null; try { QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1); AsyncFileOperationData QPYX_obj_YXQP = (AsyncFileOperationData)QPYX_o_YXQP; byte[] QPYX_ret_YXQP = QPYX_obj_YXQP.content; ToLua.Push(L_YXQP, QPYX_ret_YXQP); return(1); } catch (Exception QPYX_e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index content on a nil value")); } }
static int QPYX_set_json_YXQP(IntPtr L_YXQP) { object QPYX_o_YXQP = null; try { QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1); AsyncFileOperationData QPYX_obj_YXQP = (AsyncFileOperationData)QPYX_o_YXQP; string QPYX_arg0_YXQP = ToLua.CheckString(L_YXQP, 2); QPYX_obj_YXQP.json = QPYX_arg0_YXQP; return(0); } catch (Exception QPYX_e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index json on a nil value")); } }
private static void OperationLoop() { while (!s_end) { Thread.Sleep(2); AsyncFileOperationData operationData = null; lock (s_queue) { if (s_queue.Count > 0) { operationData = s_queue[0]; s_queue.RemoveAt(0); } } try { if (operationData != null) { if (!operationData.drop) { if (operationData.method == "delete") { if (FileUtility.Exists(operationData.filePath)) { FileUtility.Delete(operationData.filePath); } for (int i = 0; i < s_queue.Count; i++) { if (s_queue[i].filePath == operationData.filePath) { s_queue[i].drop = true; } } } else if (operationData.method == "append") { FileUtility.SaveFile(operationData.filePath, operationData.content, true); } else if (operationData.method == "write") { FileUtility.SaveFile(operationData.filePath, operationData.content, false); } else if (operationData.method == "directoryMove") { string[] paths = operationData.filePath.Split(','); FileUtility.DirectoryMove(paths[0], paths[1]); lock (s_finished_queue) { s_finished_queue.Enqueue(operationData); } } else if (operationData.method == "compressDir") { string[] parameters = operationData.filePath.Split(','); lzip.compressDir(parameters[0], int.Parse(parameters[1]), parameters[2], bool.Parse(parameters[3])); lock (s_finished_queue) { s_finished_queue.Enqueue(operationData); } } else if (operationData.method == "readAllBytes") { byte[] bytes = FileUtility.ReadAllBytes(operationData.filePath); operationData.content = bytes; lock (s_finished_queue) { s_finished_queue.Enqueue(operationData); } } } } } catch (Exception e) { Debug.LogException(e); } } }
static int QPYX_set_content_YXQP(IntPtr L_YXQP) { object QPYX_o_YXQP = null; try { QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1); AsyncFileOperationData QPYX_obj_YXQP = (AsyncFileOperationData)QPYX_o_YXQP; byte[] QPYX_arg0_YXQP = ToLua.CheckByteBuffer(L_YXQP, 2); QPYX_obj_YXQP.content = QPYX_arg0_YXQP; return(0); } catch (Exception QPYX_e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index content on a nil value")); } }