private void LoadCommanders() { if (_ListOfCommanders == null) { _ListOfCommanders = new List <EDCommander>(); } lock (_ListOfCommanders) { _ListOfCommanders.Clear(); int maxnr = -1; using (SQLiteConnectionUser conn = new SQLiteConnectionUser(mode: EDDbAccessMode.Reader)) { using (DbCommand cmd = conn.CreateCommand("SELECT * FROM Commanders")) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { EDCommander edcmdr = new EDCommander(reader); string name = Convert.ToString(reader["Name"]); string edsmapikey = Convert.ToString(reader["EdsmApiKey"]); if (edcmdr.Nr > maxnr) { maxnr = edcmdr.Nr; } if (edcmdr.Deleted == false) { _ListOfCommanders.Add(edcmdr); } } } } } if (maxnr == -1) // migrate from really old code { using (SQLiteConnectionUser conn = new SQLiteConnectionUser()) { using (DbCommand cmd = conn.CreateCommand("INSERT OR REPLACE INTO Commanders (Id, Name, EdsmName, EdsmApiKey, NetLogDir, Deleted, SyncToEdsm, SyncFromEdsm, SyncToEddn) VALUES (@Id, @Name, @EdsmName, @EdsmApiKey, @NetLogDir, @Deleted, @SyncToEdsm, @SyncFromEdsm, @SyncToEddn)")) { cmd.AddParameter("@Id", DbType.Int32); cmd.AddParameter("@Name", DbType.String); cmd.AddParameter("@EdsmName", DbType.String); cmd.AddParameter("@EdsmApiKey", DbType.String); cmd.AddParameter("@NetLogDir", DbType.String); cmd.AddParameter("@Deleted", DbType.Boolean); cmd.AddParameter("@SyncToEdsm", DbType.Boolean); cmd.AddParameter("@SyncFromEdsm", DbType.Boolean); cmd.AddParameter("@SyncToEddn", DbType.Boolean); // Migrate old settigns. string apikey = conn.GetSettingStringCN("EDSMApiKey", ""); string commanderName = conn.GetSettingStringCN("CommanderName", ""); for (int i = 0; i < 100; i++) { EDCommander cmdr = new EDCommander(i, conn.GetSettingStringCN("EDCommanderName" + i.ToString(), commanderName), conn.GetSettingStringCN("EDCommanderApiKey" + i.ToString(), apikey), true, false, true); cmdr.NetLogDir = conn.GetSettingStringCN("EDCommanderNetLogPath" + i.ToString(), null); bool deleted = conn.GetSettingBoolCN("EDCommanderDeleted" + i.ToString(), false); if (cmdr.Name != "") { cmd.Parameters["@Id"].Value = cmdr.Nr; cmd.Parameters["@Name"].Value = cmdr.Name; cmd.Parameters["@EdsmName"].Value = cmdr.EdsmName; cmd.Parameters["@EdsmApiKey"].Value = cmdr.APIKey; cmd.Parameters["@NetLogDir"].Value = cmdr.NetLogDir; cmd.Parameters["@Deleted"].Value = deleted; cmd.Parameters["@SyncToEdsm"].Value = cmdr.SyncToEdsm; cmd.Parameters["@SyncFromEdsm"].Value = cmdr.SyncFromEdsm; cmd.Parameters["@SyncToEddn"].Value = cmdr.SyncToEddn; cmd.ExecuteNonQuery(); _ListOfCommanders.Add(cmdr); } commanderName = ""; apikey = ""; } } } } } }