diff --git a/DATabaseTwo/DATabaseTwo.cs b/DATabaseTwo/DATabaseTwo.cs index b28386cc..641e70df 100644 --- a/DATabaseTwo/DATabaseTwo.cs +++ b/DATabaseTwo/DATabaseTwo.cs @@ -53,19 +53,8 @@ namespace SabreTools _logger = new Logger(true, "database2.log"); _logger.Start(); - Remapping.CreateRemappings(); - Build.Start("DATabaseTwo"); - - // Perform initial database and folder setup - if (!Directory.Exists(_datroot)) - { - Directory.CreateDirectory(_datroot); - } - if (!Directory.Exists(_outroot)) - { - Directory.CreateDirectory(_outroot); - } - DBTools.EnsureDatabase(_dbName, _connectionString); + // Perform initial setup + Setup(); // If there's no arguments, show the menu if (args.Length == 0) @@ -574,6 +563,50 @@ ORDER BY system.manufacturer, system.name"; #region Helper Methods + /// + /// Perform initial setup for the program + /// + private static void Setup() + { + Remapping.CreateRemappings(); + Build.Start("DATabaseTwo"); + + // Perform initial database and folder setup + if (!Directory.Exists(_datroot)) + { + Directory.CreateDirectory(_datroot); + } + if (!Directory.Exists(_outroot)) + { + Directory.CreateDirectory(_outroot); + } + DBTools.EnsureDatabase(_dbName, _connectionString); + + using (SqliteConnection dbc = new SqliteConnection(_connectionString)) + { + dbc.Open(); + + string query = "SELECT * FROM system"; + using (SqliteCommand slc = new SqliteCommand(query, dbc)) + { + using (SqliteDataReader sldr = slc.ExecuteReader()) + { + while (sldr.Read()) + { + int systemid = sldr.GetInt32(0); + string system = _datroot + Path.DirectorySeparatorChar + sldr.GetString(1) + " - " + sldr.GetString(2); + system = system.Trim(); + + if (!Directory.Exists(system)) + { + Directory.CreateDirectory(system); + } + } + } + } + } + } + /// /// Perform initial or incremental import of DATs in the root folder /// @@ -612,11 +645,6 @@ ORDER BY system.manufacturer, system.name"; _logger.Log("System: " + system.Remove(0, 5)); - if (!Directory.Exists(system)) - { - Directory.CreateDirectory(system); - } - // Audit all DATs in the folder foreach (string file in Directory.GetFiles(system, "*", SearchOption.AllDirectories)) {