public void SaveData() { if (this.activeFile == null) { return; } List <string> strs = new List <string>(); SortedList <int, int> nums = new SortedList <int, int>(); List <KeyValuePair <string, ToDo.Item> > keyValuePairs = new List <KeyValuePair <string, ToDo.Item> >(); foreach (KeyValuePair <string, ToDo.Item> item in this.items) { ToDo.SubItem value = item.Value.active; if (value == null || (value.description == null || value.description.Length <= 0) && value.priority == 0 && value.state == 0) { continue; } keyValuePairs.Add(item); if (value.assignedPrecidence <= item.Value.locked.assignedPrecidence || nums.ContainsKey(value.assigned)) { continue; } strs.Add(this.assignList[value.assigned]); nums[value.assigned] = strs.Count - 1; } if (keyValuePairs.Count > 0) { StreamWriter streamWriter = new StreamWriter(this.activeFile); streamWriter.WriteLine(string.Concat("MODS: ", string.Join(",", strs))); foreach (KeyValuePair <string, ToDo.Item> keyValuePair in keyValuePairs) { ToDo.SubItem subItem = keyValuePair.Value.active; string str = string.Concat(new object[] { keyValuePair.Key, "|", subItem.state, "|", subItem.priority }); if (subItem.assignedPrecidence > keyValuePair.Value.locked.assignedPrecidence) { str = string.Concat(new object[] { str, "|", subItem.assignedPrecidence, ".", nums[subItem.assigned] }); } if (subItem.description != null) { str = string.Concat(str, "||", subItem.description.Replace("\n", "<br>").Replace("\r", "")); } streamWriter.WriteLine(str); } streamWriter.Close(); } }
public void AddItem(GameData.Item target, string description = "") { ToDo.Item item; if (this.items.ContainsKey(target.stringID)) { item = this.items[target.stringID]; if (item.active.description != null) { ToDo.SubItem subItem = item.active; subItem.description = string.Concat(subItem.description, description); } else { item.Description = ""; } if (!this.listView.Items.ContainsKey(target.stringID)) { this.addListItem(target.stringID, item); } } else { item = new ToDo.Item(); this.items[target.stringID] = item; item.Description = description; item.item = target; this.addListItem(target.stringID, item); this.nav.HasChanges = true; } base.Show(); this.listView.SelectedItems.Clear(); int num = this.listView.Items.IndexOfKey(target.stringID); this.listView.EnsureVisible(num); this.listView.Items[num].Selected = true; }
public void LoadData(string file, bool active) { ToDo.Item item; string str; if (active) { this.activeFile = file; } if (File.Exists(file)) { StreamReader streamReader = new StreamReader(file); string str1 = streamReader.ReadLine(); List <int> nums = null; if (str1 != null && str1.StartsWith("MODS: ")) { nums = new List <int>(); string[] strArrays = str1.Substring(6).Split(new char[] { ',' }); for (int i = 0; i < (int)strArrays.Length; i++) { string str2 = strArrays[i]; if (!this.assignList.Contains(str2)) { this.assignList.Add(str2); } nums.Add(this.assignList.IndexOf(str2)); } } while (true) { string str3 = streamReader.ReadLine(); str1 = str3; if (str3 == null) { break; } int num = str1.IndexOf("||"); if (num > 0) { str = str1.Substring(num + 2); } else { str = null; } string str4 = str; string[] strArrays1 = (num > 0 ? str1.Substring(0, num).Split(new char[] { '|' }) : str1.Split(new char[] { '|' })); if (!this.items.ContainsKey(strArrays1[0])) { Dictionary <string, ToDo.Item> strs = this.items; string str5 = strArrays1[0]; ToDo.Item item1 = new ToDo.Item(); ToDo.Item item2 = item1; strs[str5] = item1; item = item2; } else { item = this.items[strArrays1[0]]; } if (active && item.active == null) { item.active = new ToDo.SubItem(); } ToDo.SubItem subItem = (active ? item.active : item.locked); subItem.state += int.Parse(strArrays1[1]); subItem.priority += int.Parse(strArrays1[2]); if (str4 != null) { str4 = str4.Replace("<br>", "\n"); if (subItem.description != null) { ToDo.SubItem subItem1 = subItem; subItem1.description = string.Concat(subItem1.description, "\n", str4); } else { subItem.description = str4; } } if ((int)strArrays1.Length > 3 && nums != null) { string[] strArrays2 = strArrays1[3].Split(new char[] { '.' }); int num1 = int.Parse(strArrays2[0]); if (num1 > subItem.assignedPrecidence) { subItem.assigned = nums[int.Parse(strArrays2[1])]; subItem.assignedPrecidence = num1; } } } streamReader.Close(); this.resolveItems(); } }