You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 rivejä
6.9 KiB

  1. require("preload.tools.socket")
  2. require("preload.tools.url")
  3. url = require("socket.url")
  4. require("preload.tools.headers")
  5. require("preload.tools.http")
  6. http = require("socket.http")
  7. require("luaScript.all")
  8. require("luaScript.Tools.LuaXml")
  9. require("luaScript.Tools.GlobalFunction")
  10. require("luaScript.Protocol.Protocol");
  11. require("luaScript.Protocol.ProtoDef");
  12. require("luaScript.Protocol.ModuleName");
  13. require("Editor.GenerateDict");
  14. require("Editor.GenerateTextureSize");
  15. require("Editor.GenerateAnimationClips");
  16. require("Editor.GenerateMaterials");
  17. require("Editor.ApplyDict");
  18. require("Editor.CompileFile")
  19. require("Editor.LinkFile")
  20. require("Editor.CompareVersion")
  21. local bit32 = (bit32 or require("bit"))
  22. local lfs = lfs or require("lfs")
  23. -- avoid memory leak
  24. collectgarbage("setpause", 100)
  25. collectgarbage("setstepmul", 5000)
  26. -- 调试信息
  27. function __G__TRACKBACK__(msg)
  28. print("----------------------------------------")
  29. print("LUA ERROR: " .. tostring(msg) .. "\n")
  30. print(debug.traceback())
  31. print("----------------------------------------")
  32. end
  33. FilePackage = {};
  34. function FilePackage.encrypt(data)
  35. return cc.FilePackage:getInstance():encrypt(data);
  36. end
  37. function FilePackage.compress(data)
  38. return lzma.compress(data);
  39. end
  40. function FilePackage.uncompress(data)
  41. return lzma.uncompress(data);
  42. end
  43. -- 是否有命令行参数被指定
  44. function hasCmdArg(name)
  45. for i , v in pairs(CommandArguments) do
  46. if v == name then
  47. return true;
  48. end
  49. end
  50. return false;
  51. end
  52. -- 深度创建目录
  53. function createDir(targetPath)
  54. local path = string.gsub(targetPath , "\\" , "/")
  55. local paths = string.split(path , "/");
  56. local currentPath = "";
  57. for i , v in ipairs(paths) do
  58. if i == 1 then
  59. currentPath = v;
  60. else
  61. currentPath = currentPath .. "/" .. v;
  62. end
  63. if lfs.attributes(currentPath , "mode") ~= "directory" then
  64. lfs.mkdir(currentPath);
  65. end
  66. end
  67. end
  68. -- 加密文件
  69. function encryptFile(fileData , targetFile)
  70. targetFile:write(FilePackage.encrypt(fileData));
  71. end
  72. function saveFile(str , targetFile)
  73. local file = io.open(targetFile , "wb");
  74. file:write(str);
  75. file:close();
  76. end
  77. function loadFile(filename)
  78. -- 读取整个文件数据
  79. local file = io.open(filename , "rb");
  80. if not file then
  81. return;
  82. end
  83. fileData = file:read("*a");
  84. file:close();
  85. return fileData;
  86. end
  87. -- 遍历一个目录,对目录中的每个文件执行 func 回调
  88. function visitPath(sourcePath , func , ...)
  89. print("开始生成目录" .. sourcePath)
  90. -- 递归遍历sourcePath的所有目录
  91. --local sourcePath = "d:\\WorkSpace\\DingDing\\Core\\debug\\src\\logs"
  92. for file in lfs.dir(sourcePath) do
  93. if file ~= "." and file ~= ".." and file ~= ".svn" then
  94. local f = sourcePath..'/'..file
  95. local attr = lfs.attributes (f , "mode")
  96. if attr == "directory" then
  97. if visitPath(f , func , ...) then
  98. return true;
  99. end
  100. else
  101. if func(f , ...) then
  102. return true;
  103. end
  104. end
  105. end
  106. end
  107. print("生成目录完毕" .. sourcePath)
  108. end
  109. -- 执行一个系统命令
  110. local function runCmd(cmd)
  111. local out = io.popen(cmd , "r");
  112. print(out:read("*a"));
  113. local exit_code = out:close();
  114. return exit_code
  115. end
  116. local index = 0;
  117. local stackMap = {}
  118. local function decodeLog(fileName)
  119. index = index + 1
  120. -- 返回pathName , baseName , ext
  121. local basePath , baseName , ext = string.splitFilename(fileName);
  122. print(index, basePath, baseName, ext);
  123. if ext ~= "7z" then
  124. return false;
  125. end
  126. -- 3_1033_7004668_97d3fd7fcf8a2c046905f4c0c85d1655_20180106003900_7A97365E.7z
  127. --[[
  128. names =
  129. {
  130. [1] = "平台",
  131. [2] = "资源版本",
  132. [3] = "玩家ID",
  133. [4] = "堆栈MD5",
  134. [5] = "日期",
  135. [6] = "随机数",
  136. }
  137. fileName = "logs/堆栈/日期_版本_平台_玩家ID_随机数.log"
  138. ]]--
  139. local names = string.split(baseName , "_");
  140. local platform = names[1]
  141. local version = names[2]
  142. local user_id = names[3]
  143. local stack = names[4]
  144. local log_date = names[5]
  145. local randnum = names[6]
  146. local logFilePath = "logs" .. "/" .. stack .. "/";
  147. local logFileName = log_date .. "_" .. version .. "_" .. platform .. "_" .. user_id .. "_" .. randnum .. ".log";
  148. if not stackMap[stack] then
  149. stackMap[stack] = {}
  150. end
  151. table.insert(stackMap[stack], logFileName)
  152. pathName = basePath .. "/" .. logFilePath;
  153. if #names == 6 then
  154. createDir(pathName);
  155. local newFileName = pathName .. logFileName;
  156. local logFile = io.open(fileName , "rb");
  157. local allData = logFile:read("*a");
  158. logFile:close();
  159. local uncompressData = lzma.uncompress(allData);
  160. if uncompressData ~= nil then
  161. local newLogFile = io.open(newFileName , "wb");
  162. newLogFile:write(lzma.decodeLog(uncompressData));
  163. newLogFile:close();
  164. end
  165. -- 删除原始文件
  166. os.remove(fileName)
  167. end
  168. end
  169. local function decodeLogs()
  170. visitPath("logs" , decodeLog);
  171. end
  172. local function decodeCrash(fileName)
  173. -- 返回pathName , baseName , ext
  174. local pathName , baseName , ext = string.splitFilename(fileName);
  175. print("pathName, baseName, ext:", pathName , baseName , ext);
  176. if ext ~= "7z" then
  177. return false;
  178. end
  179. local names = string.split(baseName , "_");
  180. local newFileName, baseFileName, logFlag
  181. -- 如果是android则需要分平台创建
  182. if tonumber(names[2]) == 3 or tonumber(names[2]) == 4 or tonumber(names[2]) == 5 then
  183. pathName = pathName .. "/" .. names[2] .. "/" .. names[3] .. "/" .. names[4] .. "/";
  184. baseFileName = names[5]
  185. logFlag = names[6]
  186. else
  187. -- 其他平台
  188. pathName = pathName .. "/" .. names[2] .. "/" .. names[3] .. "/";
  189. baseFileName = names[4]
  190. logFlag = names[5]
  191. end
  192. local dumpPathName = pathName .. "dump/"
  193. local logPathName = pathName .. "log/"
  194. -- 创建dump目录
  195. createDir(dumpPathName)
  196. -- 创建对应的log目录
  197. createDir(logPathName)
  198. -- 再拆分一次
  199. local secNames = string.split(baseFileName, ".");
  200. if logFlag then
  201. -- 解析log
  202. newFileName = logPathName .. secNames[1] .. ".log";
  203. local logFile = io.open(fileName , "rb");
  204. local allData = logFile:read("*a");
  205. logFile:close();
  206. local uncompressData = lzma.uncompress(allData);
  207. if uncompressData ~= nil then
  208. local newLogFile = io.open(newFileName , "wb");
  209. newLogFile:write(lzma.decodeLog(uncompressData));
  210. newLogFile:close();
  211. end
  212. else
  213. -- 解析dump
  214. newFileName = dumpPathName .. secNames[1] .. ".dmp";
  215. local logFile = io.open(fileName , "rb");
  216. local allData = logFile:read("*a");
  217. logFile:close();
  218. local uncompressData = lzma.uncompress(allData);
  219. if uncompressData ~= nil then
  220. local newLogFile = io.open(newFileName , "wb");
  221. newLogFile:write(uncompressData);
  222. newLogFile:close();
  223. end
  224. end
  225. end
  226. local function decodeCrashs()
  227. visitPath("crash" , decodeCrash);
  228. end
  229. function main()
  230. print("CommandArguments" , CommandArguments);
  231. if hasCmdArg("-BuildLogs") then
  232. print("请把log文件拷贝到logs目录")
  233. decodeLogs();
  234. elseif hasCmdArg("-BuildCrash") then
  235. print("请把crash文件拷贝到crash目录")
  236. decodeCrashs();
  237. end
  238. end
  239. local result = nil
  240. local function main_exe()
  241. result = main()
  242. end
  243. xpcall(main_exe, __G__TRACKBACK__)
  244. return result