diff --git a/NUS Downloader/Database.cs b/NUS Downloader/Database.cs index 44a7f25..2f6ce37 100644 --- a/NUS Downloader/Database.cs +++ b/NUS Downloader/Database.cs @@ -34,6 +34,9 @@ namespace NUS_Downloader public void LoadDatabaseToStream(string databaseFile) { + // Does it exist? + if (!File.Exists(databaseFile)) + throw new FileNotFoundException("I couldn't find the database file!", "database.xml"); // Load database.xml into MemoryStream databaseString = File.ReadAllText(databaseFile); /*System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); diff --git a/NUS Downloader/Form1.cs b/NUS Downloader/Form1.cs index 21b1417..61ef883 100644 --- a/NUS Downloader/Form1.cs +++ b/NUS Downloader/Form1.cs @@ -1652,18 +1652,26 @@ namespace NUS_Downloader private void RetrieveNewDatabase_Completed(object sender, RunWorkerCompletedEventArgs e) { string database = e.Result.ToString(); - Database db = new Database(); - db.LoadDatabaseToStream(Path.Combine(CURRENT_DIR, "database.xml")); - string currentversion = db.GetDatabaseVersion(); - string onlineversion = Database.GetDatabaseVersion(database); - WriteStatus(" - Database successfully parsed!"); - WriteStatus(" - Current Database Version: " + currentversion); - WriteStatus(" - Online Database Version: " + onlineversion); - - if (currentversion == onlineversion) + try { - WriteStatus(" - You have the latest database version!"); - return; + Database db = new Database(); + db.LoadDatabaseToStream(Path.Combine(CURRENT_DIR, "database.xml")); + string currentversion = db.GetDatabaseVersion(); + string onlineversion = Database.GetDatabaseVersion(database); + WriteStatus(" - Database successfully parsed!"); + WriteStatus(" - Current Database Version: " + currentversion); + WriteStatus(" - Online Database Version: " + onlineversion); + + if (currentversion == onlineversion) + { + WriteStatus(" - You have the latest database version!"); + return; + } + } + catch (FileNotFoundException) + { + WriteStatus(" - Database does not yet exist."); + WriteStatus(" - Online Database Version: " + Database.GetDatabaseVersion(database)); } bool isCreation = false;