require("preload.tools.socket") require("preload.tools.url") url = require("socket.url") require("preload.tools.headers") require("preload.tools.http") http = require("socket.http") require("luaScript.all") require("luaScript.Tools.LuaXml") require("luaScript.Tools.GlobalFunction") require("luaScript.Protocol.Protocol"); require("luaScript.Protocol.ProtoDef"); require("luaScript.Protocol.ModuleName"); require("Editor.GenerateDict"); require("Editor.GenerateTextureSize"); require("Editor.GenerateAnimationClips"); require("Editor.GenerateMaterials"); require("Editor.ApplyDict"); require("Editor.CompileFile") require("Editor.LinkFile") require("Editor.CompareVersion") local bit32 = (bit32 or require("bit")) local lfs = lfs or require("lfs") -- avoid memory leak collectgarbage("setpause", 100) collectgarbage("setstepmul", 5000) -- 调试信息 function __G__TRACKBACK__(msg) print("----------------------------------------") print("LUA ERROR: " .. tostring(msg) .. "\n") print(debug.traceback()) print("----------------------------------------") end FilePackage = {}; function FilePackage.encrypt(data) return cc.FilePackage:getInstance():encrypt(data); end function FilePackage.compress(data) return lzma.compress(data); end function FilePackage.uncompress(data) return lzma.uncompress(data); end -- 是否有命令行参数被指定 function hasCmdArg(name) for i , v in pairs(CommandArguments) do if v == name then return true; end end return false; end -- 深度创建目录 function createDir(targetPath) local path = string.gsub(targetPath , "\\" , "/") local paths = string.split(path , "/"); local currentPath = ""; for i , v in ipairs(paths) do if i == 1 then currentPath = v; else currentPath = currentPath .. "/" .. v; end if lfs.attributes(currentPath , "mode") ~= "directory" then lfs.mkdir(currentPath); end end end -- 加密文件 function encryptFile(fileData , targetFile) targetFile:write(FilePackage.encrypt(fileData)); end function saveFile(str , targetFile) local file = io.open(targetFile , "wb"); file:write(str); file:close(); end function loadFile(filename) -- 读取整个文件数据 local file = io.open(filename , "rb"); if not file then return; end fileData = file:read("*a"); file:close(); return fileData; end -- 遍历一个目录,对目录中的每个文件执行 func 回调 function visitPath(sourcePath , func , ...) print("开始生成目录" .. sourcePath) -- 递归遍历sourcePath的所有目录 --local sourcePath = "d:\\WorkSpace\\DingDing\\Core\\debug\\src\\logs" for file in lfs.dir(sourcePath) do if file ~= "." and file ~= ".." and file ~= ".svn" then local f = sourcePath..'/'..file local attr = lfs.attributes (f , "mode") if attr == "directory" then if visitPath(f , func , ...) then return true; end else if func(f , ...) then return true; end end end end print("生成目录完毕" .. sourcePath) end -- 执行一个系统命令 local function runCmd(cmd) local out = io.popen(cmd , "r"); print(out:read("*a")); local exit_code = out:close(); return exit_code end local index = 0; local stackMap = {} local function decodeLog(fileName) index = index + 1 -- 返回pathName , baseName , ext local basePath , baseName , ext = string.splitFilename(fileName); print(index, basePath, baseName, ext); if ext ~= "7z" then return false; end -- 3_1033_7004668_97d3fd7fcf8a2c046905f4c0c85d1655_20180106003900_7A97365E.7z --[[ names = { [1] = "平台", [2] = "资源版本", [3] = "玩家ID", [4] = "堆栈MD5", [5] = "日期", [6] = "随机数", } fileName = "logs/堆栈/日期_版本_平台_玩家ID_随机数.log" ]]-- local names = string.split(baseName , "_"); local platform = names[1] local version = names[2] local user_id = names[3] local stack = names[4] local log_date = names[5] local randnum = names[6] local logFilePath = "logs" .. "/" .. stack .. "/"; local logFileName = log_date .. "_" .. version .. "_" .. platform .. "_" .. user_id .. "_" .. randnum .. ".log"; if not stackMap[stack] then stackMap[stack] = {} end table.insert(stackMap[stack], logFileName) pathName = basePath .. "/" .. logFilePath; if #names == 6 then createDir(pathName); local newFileName = pathName .. logFileName; local logFile = io.open(fileName , "rb"); local allData = logFile:read("*a"); logFile:close(); local uncompressData = lzma.uncompress(allData); if uncompressData ~= nil then local newLogFile = io.open(newFileName , "wb"); newLogFile:write(lzma.decodeLog(uncompressData)); newLogFile:close(); end -- 删除原始文件 os.remove(fileName) end end local function decodeLogs() visitPath("logs" , decodeLog); end local function decodeCrash(fileName) -- 返回pathName , baseName , ext local pathName , baseName , ext = string.splitFilename(fileName); print("pathName, baseName, ext:", pathName , baseName , ext); if ext ~= "7z" then return false; end local names = string.split(baseName , "_"); local newFileName, baseFileName, logFlag -- 如果是android则需要分平台创建 if tonumber(names[2]) == 3 or tonumber(names[2]) == 4 or tonumber(names[2]) == 5 then pathName = pathName .. "/" .. names[2] .. "/" .. names[3] .. "/" .. names[4] .. "/"; baseFileName = names[5] logFlag = names[6] else -- 其他平台 pathName = pathName .. "/" .. names[2] .. "/" .. names[3] .. "/"; baseFileName = names[4] logFlag = names[5] end local dumpPathName = pathName .. "dump/" local logPathName = pathName .. "log/" -- 创建dump目录 createDir(dumpPathName) -- 创建对应的log目录 createDir(logPathName) -- 再拆分一次 local secNames = string.split(baseFileName, "."); if logFlag then -- 解析log newFileName = logPathName .. secNames[1] .. ".log"; local logFile = io.open(fileName , "rb"); local allData = logFile:read("*a"); logFile:close(); local uncompressData = lzma.uncompress(allData); if uncompressData ~= nil then local newLogFile = io.open(newFileName , "wb"); newLogFile:write(lzma.decodeLog(uncompressData)); newLogFile:close(); end else -- 解析dump newFileName = dumpPathName .. secNames[1] .. ".dmp"; local logFile = io.open(fileName , "rb"); local allData = logFile:read("*a"); logFile:close(); local uncompressData = lzma.uncompress(allData); if uncompressData ~= nil then local newLogFile = io.open(newFileName , "wb"); newLogFile:write(uncompressData); newLogFile:close(); end end end local function decodeCrashs() visitPath("crash" , decodeCrash); end function main() print("CommandArguments" , CommandArguments); if hasCmdArg("-BuildLogs") then print("请把log文件拷贝到logs目录") decodeLogs(); elseif hasCmdArg("-BuildCrash") then print("请把crash文件拷贝到crash目录") decodeCrashs(); end end local result = nil local function main_exe() result = main() end xpcall(main_exe, __G__TRACKBACK__) return result