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); }
public void Init(string path) { Iscn2tw = false; //读取配置 string tmp = MyPath.Combine(path, MyPath.GetFileName(TAG, DEXConfig.ReadString(DEXConfig.TAG_MSE))); if (!File.Exists(tmp)) { tmp = MyPath.Combine(path, MyPath.GetFileName(TAG, FILE_CONFIG_NAME)); if (!File.Exists(tmp)) { return;//如果默认的也不存在 } } SetConfig(tmp, path); }
public static void CheckVersion(bool showNew) { string newver = CheckUpdate.GetNewVersion(DEXConfig.ReadString(DEXConfig.TAG_UPDATE_URL)); if (newver == CheckUpdate.DEFAULT) { //检查失败 if (!showNew) { return; } MyMsg.Error(LMSG.CheckUpdateFail); return; } if (CheckUpdate.CheckVersion(newver, Application.ProductVersion)) {//有最新版本 if (!MyMsg.Question(LMSG.HaveNewVersion)) { return; } } else {//现在就是最新版本 if (!showNew) { return; } if (!MyMsg.Question(LMSG.NowIsNewVersion)) { return; } } //下载文件 if (CheckUpdate.DownLoad( MyPath.Combine(Application.StartupPath, newver + ".zip"))) { MyMsg.Show(LMSG.DownloadSucceed); } else { MyMsg.Show(LMSG.DownloadFail); } }
public void SetDataPath(string datapath) { //判断是否合法 if (string.IsNullOrEmpty(datapath)) { return; } tCards = null; //数据目录 this.datapath = datapath; if (DEXConfig.ReadBoolean(DEXConfig.TAG_ASYNC)) { //后台加载数据 bgWorker1.RunWorkerAsync(); } else { Init(); InitForm(); } }
static void SaveLanguage() { string datapath = MyPath.Combine(Application.StartupPath, DEXConfig.TAG_DATA); string conflang = DEXConfig.GetLanguageFile(datapath); LanguageHelper.LoadFormLabels(conflang); LanguageHelper langhelper = new(); MainForm form1 = new(); LanguageHelper.SetFormLabel(form1); langhelper.GetFormLabel(form1); DataEditForm form2 = new(); LanguageHelper.SetFormLabel(form2); langhelper.GetFormLabel(form2); CodeEditForm form3 = new(); LanguageHelper.SetFormLabel(form3); langhelper.GetFormLabel(form3); // LANG.GetFormLabel(this); //获取窗体文字 _ = langhelper.SaveLanguage(conflang + ".bak"); }
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(); } } } } }
//打开脚本 public bool OpenScript(bool openinthis, string addrequire) { if (!dataform.CheckOpen()) { return(false); } Card c = dataform.GetCard(); long id = c.id; string lua; if (c.id > 0) { lua = dataform.GetPath().GetScript(id); if (c.omega[0] > 0 && !File.Exists(lua)) { string tmp = MyPath.Combine(dataform.GetPath().gamepath, "../Scripts", "c" + id + ".lua"); if (File.Exists(tmp)) { lua = tmp; } if (c.omega[0] > 0 && !string.IsNullOrEmpty(c.script) && !byte.TryParse(c.script, out _) && !File.Exists(lua) && openinthis) { DEXConfig.OpenFileInThis(c.script); return(true); } } } else if (addrequire.Length > 0) { lua = dataform.GetPath().GetModuleScript(addrequire); } else { return(false); } if (!File.Exists(lua)) { if (c.omega[0] > 0 && !string.IsNullOrEmpty(c.script) && !byte.TryParse(c.script, out _) && !openinthis) { MyPath.CreateDirByFile(lua); using FileStream fs = new(lua, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new(fs, new UTF8Encoding(false)); sw.Write(c.script); sw.Close(); fs.Close(); } if (MyMsg.Question(LMSG.IfCreateScript))//是否创建脚本 { MyPath.CreateDirByFile(lua); using FileStream fs = new(lua, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new(fs, new UTF8Encoding(false)); sw.WriteLine("--" + c.name); sw.WriteLine("local s,id=GetID()"); if (!string.IsNullOrEmpty(addrequire)) { sw.WriteLine("Duel.LoadScript(\"" + addrequire + ".lua\")"); // DIY script } sw.WriteLine("function s.initial_effect(c)"); sw.WriteLine("\t"); sw.WriteLine("end"); sw.Close(); fs.Close(); } } if (File.Exists(lua)) //如果存在,则打开文件 { if (openinthis) //是否用本程序打开 { DEXConfig.OpenFileInThis(lua); } else { _ = System.Diagnostics.Process.Start(lua); } return(true); } return(false); }