/// <summary> /// Loads the commanders from storage /// </summary> /// <param name="write">True if any migrated commanders should be written to storage</param> /// <param name="conn">SQLite connection</param> public static void Load(bool write = true, SQLiteConnectionUser conn = null) { if (_commandersDict == null) { _commandersDict = new Dictionary <int, EDCommander>(); } lock (_commandersDict) { _commandersDict.Clear(); var cmdrs = SQLiteConnectionUser.GetCommanders(conn); int maxnr = cmdrs.Count == 0 ? 0 : cmdrs.Max(c => c.Nr); foreach (EDCommander cmdr in cmdrs) { if (!cmdr.Deleted) { _commandersDict[cmdr.Nr] = cmdr; } } if (_commandersDict.Count == 0) { if (write) { Create("Jameson (Default)"); } else { _commandersDict[maxnr + 1] = new EDCommander(maxnr + 1, "Jameson (Default)", "", false, false, false); } } } // For some people sharing their user DB between different computers and having different paths to their journals on those computers. if (File.Exists(Path.Combine(EDDConfig.Options.AppDataDirectory, "CommanderPaths.json"))) { JObject jo; using (Stream stream = File.OpenRead(Path.Combine(EDDConfig.Options.AppDataDirectory, "CommanderPaths.json"))) { using (StreamReader reader = new StreamReader(stream)) { using (JsonTextReader jreader = new JsonTextReader(reader)) { jo = JObject.Load(jreader); } } } foreach (var kvp in jo) { string name = kvp.Key; JObject props = kvp.Value as JObject; EDCommander cmdr = GetCommander(name); if (props != null && cmdr != null) { cmdr.JournalDir = JSONHelper.GetStringDef(props["JournalDir"], cmdr.JournalDir); } } } }
public static void Load(bool write = true, SQLiteConnectionUser conn = null) { if (commandersDict == null) { commandersDict = new Dictionary <int, EDCommander>(); } lock (commandersDict) { commandersDict.Clear(); var cmdrs = SQLiteConnectionUser.GetCommanders(conn); int maxnr = cmdrs.Count == 0 ? 0 : cmdrs.Max(c => c.Nr); foreach (EDCommander cmdr in cmdrs) { if (!cmdr.Deleted) { commandersDict[cmdr.Nr] = cmdr; } } if (commandersDict.Count == 0) { if (write) { Create("Jameson (Default)"); } else { commandersDict[maxnr + 1] = new EDCommander(maxnr + 1, "Jameson (Default)"); } } EDCommander hidden = new EDCommander(-1, "Hidden Log"); // -1 is the hidden commander, add to list to make it commandersDict[-1] = hidden; // so we give back a valid entry when its selected } // For some people sharing their user DB between different computers and having different paths to their journals on those computers. if (File.Exists(Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json"))) { JObject jo; using (Stream stream = File.OpenRead(Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json"))) { using (StreamReader reader = new StreamReader(stream)) { using (JsonTextReader jreader = new JsonTextReader(reader)) { jo = JObject.Load(jreader); } } } foreach (var kvp in jo) { string name = kvp.Key; JObject props = kvp.Value as JObject; EDCommander cmdr = GetCommander(name); if (props != null && cmdr != null) { cmdr.JournalDir = props["JournalDir"].Str(cmdr.JournalDir); } } } }