private static void load_contexts(settings_file sett) { logger.Debug("loading contexts"); int history_count = int.Parse( sett.get("history_count", "0")); for (int idx = 0; idx < history_count; ++idx) { history hist = new history(); string guid = sett.get("history." + idx + ".guid"); if (guid != "") { // 1.5.6+ - guid points to the whole settings string settings = sett.get("guid." + guid); if (settings == "") { logger.Debug("history guid removed " + guid); continue; // entry removed } Debug.Assert(settings.Contains(guid)); hist.from_settings(new settings_as_string(settings)); } else { // old code (pre 1.5.6) string type_str = sett.get("history." + idx + "type", "file"); if (type_str == "0") type_str = "file"; string name = sett.get("history." + idx + "name"); string friendly_name = sett.get("history." + idx + "friendly_name"); settings_as_string history_sett = new settings_as_string(""); history_sett.set("type", type_str); history_sett.set("name", name); history_sett.set("friendly_name", friendly_name); // create a guid now history_sett.set("guid", Guid.NewGuid().ToString()); hist.from_settings(history_sett); } history_.Add( hist ); } history_ = history_.Where(h => { if (h.type == history.entry_type.file) { // 1.5.11 - don't include this into the list next time the user opens the app // (so that he'll see the "Drop me like it's hot" huge message) if (h.name.EndsWith("LogWizardSetupSample.log")) return false; if (File.Exists(h.name)) // 1.1.5+ - compute md5s for this md5_log_keeper.inst.compute_default_md5s_for_file(h.name); else return false; } return true; }).ToList(); int count = int.Parse( sett.get("context_count", "1")); for ( int i = 0; i < count ; ++i) { ui_context ctx = new ui_context(); ctx.load("context." + i); contexts_.Add(ctx); } // 1.1.25 - at application start - remove empty contexts (like, the user may have dragged a file, not what he wanted, dragged another) contexts_ = contexts_.Where(x => x.has_not_empty_views || x.name == "Default").ToList(); }
// saves the settings - you can specify another file name (in case you're making a backup) public void save_to(string file_name) { if (file_name == "") file_name = file_name_; // needs to be loaded first if (file_name == "") return; bool force_save = file_name != file_name_; if (!dirty_ && !force_save) return; if (file_name == file_name_ && notes_sorted_by_line_index_.Count < 1) return; // optimization - nothing to save_to settings_file sett = new settings_file(file_name) { log_each_set = false }; // first, save_to lines - don't save_to the cur_line sett.set("line_count", "" + (lines_.Count - 1)); int line_idx = 0; foreach ( var l in lines_) if (l.Key != cur_line_id_) { string prefix = "line." + line_idx + "."; sett.set(prefix + "id", "" + l.Key); sett.set(prefix + "index", "" + l.Value.idx); sett.set(prefix + "view_name", l.Value.view_name); sett.set(prefix + "msg", l.Value.msg); ++line_idx; } // save_to notes sett.set("note_count", "" + notes_sorted_by_line_index_.Count); for (int idx = 0; idx < notes_sorted_by_line_index_.Count; ++idx) { string prefix = "note." + idx + "."; note_item n = notes_sorted_by_line_index_[idx]; if (n.the_note != null) { sett.set(prefix + "author_name", n.the_note.author_name); sett.set(prefix + "author_initials", n.the_note.author_initials); sett.set(prefix + "author_color", util.color_to_str(n.the_note.author_color)); sett.set(prefix + "note_text", n.the_note.note_text); } else // clear the author name, so we know it's not a note (it's a line) sett.set(prefix + "author_name", ""); sett.set(prefix + "deleted", n.deleted ? "1" : "0"); sett.set(prefix + "note_id", "" + n.note_id); sett.set(prefix + "reply_id", "" + n.reply_id); sett.set(prefix + "line_id", "" + n.line_id); sett.set(prefix + "added_at", "" + n.utc_last_edited.Ticks); } sett.save(); if ( file_name == file_name_) dirty_ = false; }
private static void load_contexts(settings_file sett) { logger.Debug("loading contexts"); history_list_.load(); int count = int.Parse( sett.get("context_count", "1")); for ( int i = 0; i < count ; ++i) { ui_context ctx = new ui_context(); ctx.load("context." + i); contexts_.Add(ctx); } // 1.1.25 - at application start - remove empty contexts (like, the user may have dragged a file, not what he wanted, dragged another) contexts_ = contexts_.Where(x => x.has_not_empty_views || x.name == "Default").ToList(); }
private static Tuple<Dictionary<string, line>, List<note_item>> load_settings_file(note_ctrl self, string file_name) { Dictionary<string, line> lines = new Dictionary<string, line>(); List<note_item> notes = new List<note_item>(); settings_file sett = new settings_file(file_name); // first, load lines int line_count = int.Parse(sett.get("line_count", "0")); for (int idx = 0; idx < line_count; ++idx) { string prefix = "line." + idx + "."; line l = new line(); l.idx = int.Parse(sett.get(prefix + "index", "0")); l.view_name = sett.get(prefix + "view_name"); l.msg = sett.get(prefix + "msg"); var id = sett.get(prefix + "id", ""); lines.Add(id, l); } // load notes // if author name = ourselves -> made_by_current_user = true int note_count = int.Parse(sett.get("note_count", "0")); for (int idx = 0; idx < note_count; ++idx) { string prefix = "note." + idx + "."; note n = null; string author_name = sett.get(prefix + "author_name"); if (author_name != "") { n = new note() {author_name = author_name}; n.author_initials = sett.get(prefix + "author_initials"); n.author_color = util.str_to_color(sett.get(prefix + "author_color")); n.note_text = sett.get(prefix + "note_text"); } bool deleted = sett.get(prefix + "deleted", "0") != "0"; var note_id = sett.get(prefix + "note_id", ""); var reply_id = sett.get(prefix + "reply_id", ""); var line_id = sett.get(prefix + "line_id", ""); long ticks = long.Parse(sett.get(prefix + "added_at", "0")); note_item note; if (n != null) note = new note_item(self, n, note_id, reply_id, line_id, deleted, new DateTime(ticks)); else note = new note_item(self, note_id, line_id, deleted, new DateTime(ticks)); notes.Add(note); } return new Tuple<Dictionary<string, line>, List<note_item>>(lines, notes); }