12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- namespace ResBuilder
- {
- class LuaBinPacker
- {
- public readonly string inputPath;
- public readonly string outputPath;
- public LuaBinPacker(string input, string output)
- {
- this.inputPath = input;
- this.outputPath = output;
- }
- internal void Pack()
- {
- PackDir(inputPath);
- }
- void PackDir(string dir, SearchOption sopt = SearchOption.AllDirectories)
- {
- var fileNames = Directory.GetFiles(dir, "*.lua", sopt);
- var fileBytes = new byte[fileNames.Length][];
- // -- 1 write lb.bytes
- using (var ms = new MemoryStream())
- {
- var bw = new BinaryWriter(ms);
- for (int i = 0; i < fileNames.Length; i++)
- {
- fileBytes[i] = File.ReadAllBytes(fileNames[i]);
- bw.Write(fileBytes[i]);
- }
- var outFilePath = Path.Combine(outputPath, "lb.bin");
- File.WriteAllBytes(outFilePath, ms.ToArray());
- }
- // -- 2 write lh.bytes
- using (var ms = new MemoryStream())
- {
- var bw = new BinaryWriter(ms);
- // -- write flag
- byte flag = Program.IsZipLuaBytes ? (byte)1 : (byte)0;
- bw.Write(flag);
- // -- write files count
- bw.Write(fileNames.Length);
- // --
- for (int i = 0; i < fileNames.Length; i++)
- {
- bw.Write(Path.GetFileNameWithoutExtension(fileNames[i]));
- bw.Write(fileBytes[i].Length);
- }
- var outFilePath = Path.Combine(outputPath, "lh.bin");
- File.WriteAllBytes(outFilePath, ms.ToArray());
- }
- }
- }
- }
|