public static void SavingSetting() { string ot = ""; foreach (var x in setting.data) { ot += x.Key + "," + x.Value + "\n"; } //var fileService = DependencyService.Get<ISaveAndLoad>(); SaveAndLoad.SaveText("setting.txt", ot); }
public void remove(string key) { using (var lk = rwl.WriterLock()) { data.remove(key); ok.remove(key); //data.Remove(key); //ok.Remove(key); if (file_name != null) { SaveAndLoad.AppendText(file_name, "$" + key + "\n"); } } }
public void add_ok(string key, string value = "") { using (var lk = rwl.WriterLock()) { ok.add(key, value); //ok[key] = value; if (file_name != null) { if (exists_ok_nolock(key)) { SaveAndLoad.AppendText(file_name, "*" + val_ok_nolock(key) + "," + val_nolock(key) + "\n"); } else { SaveAndLoad.AppendText(file_name, key + "," + val_nolock(key) + "\n"); } } } }
public static Maps GetDoc(string inp, bool user = true) { Maps data = new Maps(); data.clear(); //var fileService = DependencyService.Get<ISaveAndLoad>(); if (!SaveAndLoad.FileExists(inp + ".txt")) { return(data); } string st = SaveAndLoad.LoadText(inp + ".txt"); if (user && SaveAndLoad.FileExists(inp + "_user.txt")) { st += "\n" + SaveAndLoad.LoadText(inp + "_user.txt"); } byte[] byteArray = Encoding.UTF8.GetBytes(st); //byte[] byteArray = Encoding.ASCII.GetBytes(contents); MemoryStream stream = new MemoryStream(byteArray); StreamReader str = new StreamReader(stream); string s; while (true) { s = str.ReadLine(); if (s == null) { break; } List <string> a = new List <string> { "" }; string b = "", d = ""; int l = s.Length; bool tag = false, star = false, dis = false; for (int i = 0; i < l; i++) { if (tag) { b += s[i]; } else if (s[i] == '$') { dis = true; } else if (s[i] == '*') { star = true; } else if (star && s[i] == ' ') { d += ' '; } else if (s[i] == ',') { tag = true; } else if (s[i] == '/') { a.Add(""); } else { a[a.Count - 1] += s[i]; d += s[i]; } } foreach (var c in a) { if (c.Trim() == "") { continue; } if (dis) { data.remove(c); continue; } data.add(c, b); if (star) { data.add_ok(c, d); } } } if (user) { data.file_name = inp + "_user.txt"; } else { data.file_name = inp + ".txt"; } return(data); }
//public static SortedDictionary<string, SortedSet<string>> rtp=null; public static void DumpAppFile(string fil) { string s = SaveAndLoad.LoadText("..\\bin\\data\\" + fil); SaveAndLoad.SaveText(fil, s); }
//public static SortedDictionary<string, SortedSet<string>> rtp=null; public static void DumpAppFile(string fil) { string s = SaveAndLoad.LoadText(fil); SaveAndLoad.SaveText(fil, s); }
private void Init() { int data_version = 18; //await Voc.InitAsync(); if (!SaveAndLoad.FileExists("setting.txt")) { SaveAndLoad.SaveText("setting.txt", ""); } Voc.setting = Voc.GetDoc("setting", false); if (!Voc.setting.exists("website")) { Voc.setting.add("website", "http://joe59491.azurewebsites.net"); } if (!Voc.setting.exists("sound_url")) { Voc.setting.add("sound_url", "http://dictionary.reference.com/browse/"); } if (!Voc.setting.exists("sound_url2")) { Voc.setting.add("sound_url2", "http://static.sfdict.com/staticrep/dictaudio"); } if (!Voc.setting.exists("sound_type")) { Voc.setting.add("sound_type", ".mp3"); } if (!Voc.setting.exists("data_version")) { Voc.setting.add("data_version", "0"); } Voc.SavingSetting(); if (!SaveAndLoad.FileExists("favorite.txt")) { SaveAndLoad.SaveText("favorite.txt", ""); } Voc.favorite = Voc.GetDoc("favorite", false); if (!SaveAndLoad.FileExists("words.txt") || int.Parse(Voc.setting["data_version"]) < data_version) { Voc.DumpAppFile("words.txt"); } if (!SaveAndLoad.FileExists("root.txt") || int.Parse(Voc.setting["data_version"]) < data_version) { Voc.DumpAppFile("root.txt"); } if (!SaveAndLoad.FileExists("prefix.txt") || int.Parse(Voc.setting["data_version"]) < data_version) { Voc.DumpAppFile("prefix.txt"); } if (!SaveAndLoad.FileExists("suffix.txt") || int.Parse(Voc.setting["data_version"]) < data_version) { Voc.DumpAppFile("suffix.txt"); } if (!SaveAndLoad.FileExists("note.txt") || int.Parse(Voc.setting["data_version"]) < data_version) { Voc.DumpAppFile("note.txt"); } if (int.Parse(Voc.setting["data_version"]) < data_version) { Voc.setting["data_version"] = data_version.ToString(); } Voc.words = Voc.GetDoc("words", true); var tmp = Voc.words.val("apple"); foreach (var x in Voc.words.data) { var y = x; } Voc.root = Voc.GetDoc("root", true); Voc.prefix = Voc.GetDoc("prefix", true); Voc.suffix = Voc.GetDoc("suffix", true); Voc.note = Voc.GetDoc("note", true); }