require "main.global" local fileOpt = {} local function createDir() local file = io.open(APP_DIR, "rb") if file then file:close() else log_print.info("create dir") os.execute("mkdir -p " .. APP_DIR) end end function fileOpt.init() createDir() end function fileOpt.read(fileName, useBkp) local data local file = io.open(fileName, "r") if file == nil then if not useBkp then --log_print.info("fuck_nm:") return nil else --log_print.info("fuck_what:") local file_bkp = io.open(fileName .. FILE_BKP_EXT, "r") if file_bkp ~= nil then file = io.open(fileName, "w") file_bkp:seek("set", 0) local bkp_data = file_bkp:read("*a") file:write(bkp_data) file:flush() file_bkp:close() file:close() return bkp_data else return nil end end else --log_print.info("fuck_md:") file:seek("set", 0) data = file:read("*a") file:close() return data end end function fileOpt.write(fileName, data, useBkp) --log_print.info(fileName, useBkp) if useBkp then local fileNameBkp = fileName .. FILE_BKP_EXT os.execute("rm " .. fileNameBkp) os.execute("cp " .. fileName .. " " .. fileNameBkp) end local file = io.open(fileName, "w") file:write(data) file:flush() file:close() end return fileOpt