Added FileNotFound checks to database loader

This commit is contained in:
gb.luke 2010-07-10 07:59:10 +00:00
parent 6ac6a30516
commit 778a44e31b
2 changed files with 22 additions and 11 deletions

View File

@ -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();

View File

@ -1652,6 +1652,8 @@ namespace NUS_Downloader
private void RetrieveNewDatabase_Completed(object sender, RunWorkerCompletedEventArgs e)
{
string database = e.Result.ToString();
try
{
Database db = new Database();
db.LoadDatabaseToStream(Path.Combine(CURRENT_DIR, "database.xml"));
string currentversion = db.GetDatabaseVersion();
@ -1665,6 +1667,12 @@ namespace NUS_Downloader
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;
if (File.Exists("database.xml"))