private static void EncodeDsl(string dir) { #if DEBUG List<string> destfiles = new List<string>(); foreach (string filter in dslfilters.Split(',')) { foreach (var eachfileinfo in new DirectoryInfo(dir).GetFiles(filter, SearchOption.AllDirectories)) { destfiles.Add(eachfileinfo.FullName); } } foreach (string destfile in destfiles) { string code = File.ReadAllText(destfile); DslFile file = new DslFile(); code = file.GenerateBinaryCode(code, GameFramework.GlobalVariables.Instance.EncodeTable, (string msg) => GameFramework.LogSystem.Warn("{0}", msg)); if (string.IsNullOrEmpty(code)) { Console.WriteLine("encode dsl:{0} failed.", destfile); } else { try { File.WriteAllText(destfile, code); } catch (Exception ex) { Console.WriteLine("EncodeDsl {0} exception:{1}\n{2}", destfile, ex.Message, ex.StackTrace); } } } #endif }
public static void Main(string[] args) { DslLogDelegation logCallback = (string msg) => { Console.WriteLine("{0}", msg); }; Dictionary<string, string> encodeTable = new Dictionary<string, string>(); Dictionary<string, string> decodeTable = new Dictionary<string, string>(); AddCrypto("skill", encodeTable, decodeTable); AddCrypto("section", encodeTable, decodeTable); AddCrypto("foreach", encodeTable, decodeTable); AddCrypto("looplist", encodeTable, decodeTable); AddCrypto("loop", encodeTable, decodeTable); AddCrypto("wait", encodeTable, decodeTable); AddCrypto("sleep", encodeTable, decodeTable); AddCrypto("while", encodeTable, decodeTable); AddCrypto("if", encodeTable, decodeTable); AddCrypto("log", encodeTable, decodeTable); AddCrypto("=", encodeTable, decodeTable); AddCrypto("+", encodeTable, decodeTable); AddCrypto("-", encodeTable, decodeTable); AddCrypto("*", encodeTable, decodeTable); AddCrypto("/", encodeTable, decodeTable); AddCrypto("%", encodeTable, decodeTable); AddCrypto(">", encodeTable, decodeTable); AddCrypto(">=", encodeTable, decodeTable); AddCrypto("==", encodeTable, decodeTable); AddCrypto("!=", encodeTable, decodeTable); AddCrypto("<", encodeTable, decodeTable); AddCrypto("<=", encodeTable, decodeTable); AddCrypto("&&", encodeTable, decodeTable); AddCrypto("||", encodeTable, decodeTable); AddCrypto("!", encodeTable, decodeTable); DslFile file = new DslFile(); file.Load("test.txt", logCallback); #if FULL_VERSION file.Save("copy.txt"); string code1 = file.GenerateBinaryCode(File.ReadAllText("test.txt"), encodeTable, logCallback); File.WriteAllText("binary.txt", code1); #endif file.DslInfos.Clear(); string code = File.ReadAllText("binary.txt"); file.LoadBinaryCode(code, decodeTable); #if FULL_VERSION file.Save("unbinary.txt"); #endif long t1 = GetLocalMilliseconds(); for (int i = 0; i < 1000; ++i) { file.LoadBinaryCode(code, decodeTable); } long t2 = GetLocalMilliseconds(); Console.WriteLine("time:{0}", t2 - t1); }