void Init() { //文件路径 conflang = DEXConfig.GetLanguageFile(datapath); //游戏数据,MSE数据 olddatacfg = datacfg = new DataConfig(DEXConfig.GetCardInfoFile(datapath)); string confstring = MyPath.Combine(datapath, DEXConfig.FILE_STRINGS); if (File.Exists(confstring)) { Dictionary <long, string> d = datacfg.dicSetnames; if (!d.ContainsKey(0)) { d.Add(0L, "Archetype"); } foreach (string l in File.ReadAllLines(confstring)) { if (l.StartsWith("!setname")) { string[] sn = l.Split(new char[] { ' ' }, 3); _ = long.TryParse(sn[1], System.Globalization.NumberStyles.HexNumber, null, out long sc); if (!d.ContainsKey(sc)) { d.Add(sc, sn[2]); } } } } //初始化YGOUtil的数据 YGOUtil.SetConfig(datacfg); //代码提示 string funtxt = MyPath.Combine(datapath, DEXConfig.FILE_FUNCTION); string conlua = MyPath.Combine(datapath, DEXConfig.FILE_CONSTANT); codecfg = new CodeConfig(); //添加函数 codecfg.AddFunction(funtxt); //添加指示物 codecfg.AddStrings(confstring); //添加常量 codecfg.AddConstant(conlua); codecfg.SetNames(datacfg.dicSetnames); //生成菜单 codecfg.InitAutoMenus(); history = new History(this); //读取历史记录 history.ReadHistory(MyPath.Combine(datapath, DEXConfig.FILE_HISTORY)); //加载多语言 LanguageHelper.LoadFormLabels(conflang); }
private static void Main(string[] args) { string arg = (args.Length > 0) ? args[0] : ""; if (arg == DEXConfig.TAG_SAVE_LAGN || arg == DEXConfig.TAG_SAVE_LAGN2) { //保存语言 SaveLanguage(); _ = MessageBox.Show("Save Language OK."); Environment.Exit(1); } if (DEXConfig.OpenOnExistForm(arg))//在已经存在的窗口打开文件 { Environment.Exit(1); } else//新建窗口 { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainForm = new(); //设置将要打开的文件 mainForm.SetOpenFile(arg); //数据目录 mainForm.SetDataPath(MyPath.Combine(Application.StartupPath, DEXConfig.TAG_DATA)); Application.Run(mainForm); Dictionary <long, string> dic = mainForm.GetDataConfig().dicSetnames; Dictionary <long, string> old = mainForm.GetDataConfig(true).dicSetnames; foreach (long setcode in dic.Keys) { if (old.ContainsKey(setcode)) { continue; } string cardinfo = DEXConfig.GetCardInfoFile(MyPath.Combine(Application.StartupPath, DEXConfig.TAG_DATA)); if (File.Exists(cardinfo)) { using (FileStream cStream = new(cardinfo, FileMode.Open, FileAccess.ReadWrite)) { try { byte[] content = Encoding.UTF8.GetBytes($"\n0x{setcode:x}\t{dic[setcode]}\n#end"); _ = cStream.Seek(-5, SeekOrigin.End); cStream.Write(content, 0, content.Length); } catch { } finally { cStream.Close(); } } } string file = MyPath.Combine(Application.StartupPath, DEXConfig.TAG_DATA, DEXConfig.FILE_STRINGS); if (!string.IsNullOrEmpty(file) && File.Exists(file)) { using FileStream sStream = new(file, FileMode.Open, FileAccess.Write); try { byte[] content = Encoding.UTF8.GetBytes($"!setname 0x{setcode:x} {dic[setcode]}\n"); _ = sStream.Seek(0, SeekOrigin.End); sStream.Write(content, 0, content.Length); } catch { } finally { sStream.Close(); } } } } }