public static EncodeLuaFile ( string srcFile, string outFile ) : void | ||
srcFile | string | |
outFile | string | |
return | void |
public static void EncodeLuaFile(string srcFile, string outFile) {
if (!srcFile.ToLower().EndsWith(".lua")) {
File.Copy(srcFile, outFile, true);
return;
}
bool isWin = true;
string luaexe = string.Empty;
string args = string.Empty;
string exedir = string.Empty;
string currDir = Directory.GetCurrentDirectory();
if (Application.platform == RuntimePlatform.WindowsEditor) {
isWin = true;
luaexe = "luajit.exe";
args = "-b " + srcFile + " " + outFile;
exedir = AppDataPath.Replace("assets", "") + "LuaEncoder/luajit/";
} else if (Application.platform == RuntimePlatform.OSXEditor) {
isWin = false;
luaexe = "./luac";
args = "-o " + outFile + " " + srcFile;
exedir = AppDataPath.Replace("assets", "") + "LuaEncoder/luavm/";
}
Directory.SetCurrentDirectory(exedir);
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = luaexe;
info.Arguments = args;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.ErrorDialog = true;
info.UseShellExecute = isWin;
QUtil.Log(info.FileName + " " + info.Arguments);
Process pro = Process.Start(info);
pro.WaitForExit();
Directory.SetCurrentDirectory(currDir);
}
static void CopyLuaBytesFiles(string sourceDir, string destDir, bool appendext = true) { if (!Directory.Exists(sourceDir)) { return; } string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } for (int i = 0; i < files.Length; i++) { string str = files[i].Remove(0, len); string dest = destDir + str; if (appendext) dest += ".bytes"; string dir = Path.GetDirectoryName(dest); Directory.CreateDirectory(dir); if (AppConst.LuaByteMode) { Packager.EncodeLuaFile(files[i], dest); } else { File.Copy(files[i], dest, true); } } }