internal bool Setting() { string path = (string)Application.Current.Properties["DataPath"]; FileStream fs = null; try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!File.Exists(path + "Config.txt")) { if (!BasicDataUpdate(path, "Config.txt")) { throw new UnauthorizedAccessException("Config 파일 생성 실패"); } } fs = new FileStream(path + "Config.txt", FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mConfig = Json.Deserialize <ConfigData>(json); } if (mConfig.Options.SearchListCount > 80) { mConfig.Options.SearchListCount = 80; } if (!File.Exists(path + "Parser.txt")) { if (!BasicDataUpdate(path, "Parser.txt")) { throw new UnauthorizedAccessException("Parser 파일 생성 실패"); } } fs = new FileStream(path + "Parser.txt", FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mParser = Json.Deserialize <ParserData>(json); } if (!File.Exists(path + "Checked.txt")) { if (!BasicDataUpdate(path, "Checked.txt")) { throw new UnauthorizedAccessException("checked 파일 생성 실패"); } } fs = new FileStream(path + "Checked.txt", FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mChecked = Json.Deserialize <CheckedDict>(json); } if (mChecked.Entries == null) { mChecked.Entries = new List <CheckedDictItem>(); } } catch (Exception ex) { MessageBox.Show(Application.Current.MainWindow, ex.Message, "에러"); return(false); } finally { if (fs != null) { fs.Dispose(); } } return(true); }
/* * [DataContract] * public class MODS * { * [DataMember(Name = "FIELD1")] * public string FIELD1; * [DataMember(Name = "FIELD2")] * public string FIELD2; * [DataMember(Name = "FIELD3")] * public int FIELD3; * [DataMember(Name = "FIELD4")] * public string FIELD4; * [DataMember(Name = "FIELD5")] * public string FIELD5; * } * * private bool MergeModData() * { * string path = (string)Application.Current.Properties["DataPath"]; * FileStream fs = null; * string s = ""; * try * { * List<MODS>[] modsData = new List<MODS>[2]; * * s = "_POE_EXE/mods_ko.txt"; * fs = new FileStream(path + s, FileMode.Open); * using (StreamReader reader = new StreamReader(fs)) * { * fs = null; * string json = reader.ReadToEnd(); * modsData[0] = Json.Deserialize<List<MODS>>(json); * reader.Close(); * } * * s = "_POE_EXE/mods_en.txt"; * fs = new FileStream(path + s, FileMode.Open); * using (StreamReader reader = new StreamReader(fs)) * { * fs = null; * string json = reader.ReadToEnd(); * modsData[1] = Json.Deserialize<List<MODS>>(json); * reader.Close(); * } * * ModsDict modsDict = new ModsDict(); * modsDict.Entries = new List<ModsDictItem>(); * * int i = -1; * * foreach (var item in modsData[1]) * { * i++; * string[] split = item.FIELD4.Replace("\u000a", "\n").Split(new string[] { "\n" }, StringSplitOptions.None); * * string[] sa = new string[2] { "Eternal Iron Hook", "Totemic Wood Lure" }; * if (split[0].WithIn(sa)) continue; * * for (int k = 0; k < split.Length; k++) * { * FilterDictItem filter = null; * string[] matches = { null, null }; * * foreach (var re in mFilter[1].Result) * { * split[k] = split[k].RepEx(@" an additional (Arrow|Target|Curse)", " 1 additional $1s"); * * string tmp = split[k].RepEx(@"\([0-9\-\.]+\)", "#"); * filter = Array.Find(re.Entries, x => x.Text == tmp); * if (filter == null) * { * tmp = tmp.RepEx(@"[0-9]+ to #|# to [0-9]+|[0-9]+ to [0-9]+", "# to #"); * filter = Array.Find(re.Entries, x => x.Text == tmp); * } * if (filter == null) * { * tmp = tmp.RepEx(@"[+-]?[0-9]+\.[0-9]+|[+-]?[0-9]+", "#").Escape() * .RepEx(@"\\#", "[+-]?([0-9]+\\.[0-9]+|[0-9]+|\\#)") * .Replace("Attacks\\ have\\ ", "(Melee )?Attacks\\ have\\ "); * Regex rgx = new Regex("^" + tmp + "$", RegexOptions.IgnoreCase); * filter = Array.Find(re.Entries, x => rgx.IsMatch(x.Text)); * } * if (filter != null) * { * tmp = filter.Text.Replace("#", @"(\([0-9\.-]+\)|[0-9]+|[0-9]+\.[0-9]+)"); * matches = split[k].RepEx(tmp, "$1,$2").Split(',') * .Select(x => x[0] == '$' ? null : x.RepEx(@"\(|\)|\+", "")).ToArray(); * if(matches.Length == 1) matches = new string[] { null, null }; * break; * } * } * * if (filter != null) * { * ModsDictItem modsDictItem = new ModsDictItem(); * modsDictItem.Id = filter != null ? filter.Id.Split('.')[1] : split[k]; * modsDictItem.Level = item.FIELD3; * modsDictItem.Fix = item.FIELD1; * modsDictItem.Tags = item.FIELD5; * modsDictItem.Name = new string[2] { item.FIELD2, modsData[0][i].FIELD2 }; * modsDictItem.Min = matches[0]?.RepEx("([0-9])-", "$1~"); * modsDictItem.Max = matches[1]?.RepEx("([0-9])-", "$1~"); * modsDict.Entries.Add(modsDictItem); * } * } * } * * File.Delete(path + "Mods.txt"); * using (StreamWriter writer = new StreamWriter(path + "Mods.txt", false, Encoding.UTF8)) * { * writer.Write(Json.Serialize<ModsDict>(modsDict, true)); * writer.Close(); * } * } * catch (Exception ex) * { * MessageBox.Show(Application.Current.MainWindow, ex.Message, "에러"); * return false; * } * finally * { * if (fs != null) fs.Dispose(); * } * * return true; * } */ private bool LoadData(out string outString) { string path = (string)Application.Current.Properties["DataPath"]; FileStream fs = null; string s = ""; try { if (!File.Exists(path + "FiltersKO.txt") || !File.Exists(path + "FiltersEN.txt")) { mTrayIcon.BalloonTipText = "데이터를 업데이트 하는중..."; mTrayIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info; mTrayIcon.ShowBalloonTip(5000); string[] items = { "FiltersKO", "FiltersEN", "ItemsKO", "ItemsEN", "StaticKO", "StaticEN" }; foreach (string item in items) { File.Delete(path + item + ".txt"); } if (!FilterDataUpdate(path) || !ItemDataUpdate(path) || !StaticDataUpdate(path)) { s = "생성 실패"; throw new UnauthorizedAccessException("Database 파일 생성 실패"); } } s = "FiltersKO.txt"; fs = new FileStream(path + s, FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mFilter[0] = Json.Deserialize <FilterData>(json); reader.Close(); } s = "FiltersEN.txt"; fs = new FileStream(path + s, FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mFilter[1] = Json.Deserialize <FilterData>(json); reader.Close(); } s = "ItemsKO.txt"; fs = new FileStream(path + s, FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mItems[0] = Json.Deserialize <FilterData>(json); reader.Close(); } s = "ItemsEN.txt"; fs = new FileStream(path + s, FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mItems[1] = Json.Deserialize <FilterData>(json); reader.Close(); } s = "StaticKO.txt"; fs = new FileStream(path + s, FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mStatic[0] = Json.Deserialize <FilterData>(json); reader.Close(); } s = "StaticEN.txt"; fs = new FileStream(path + s, FileMode.Open); using (StreamReader reader = new StreamReader(fs)) { fs = null; string json = reader.ReadToEnd(); mStatic[1] = Json.Deserialize <FilterData>(json); reader.Close(); } /* * s = "Mods.txt"; * fs = new FileStream(path + s, FileMode.Open); * using (StreamReader reader = new StreamReader(fs)) * { * fs = null; * string json = reader.ReadToEnd(); * mMods = Json.Deserialize<ModsDict>(json); * reader.Close(); * } */ //MergeModData(); } catch (Exception ex) { outString = s; MessageBox.Show(Application.Current.MainWindow, ex.Message, "에러"); return(false); } finally { if (fs != null) { fs.Dispose(); } } outString = s; return(true); }