private void buttonLoadDatabase_Click( object sender, EventArgs e )
{
if ( m_Database != null && m_Database.Entries.Length > 0 )
{ // Caution!
if ( MessageBox( "Loading a new database will lose existing database data, do you wish to continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ) != DialogResult.Yes )
return;
}
string OldFileName = GetRegKey( "DatabaseFileName", Path.Combine( m_ApplicationPath, "Database.rdb" ) );
openFileDialogDatabase.InitialDirectory = Path.GetFullPath( OldFileName );
openFileDialogDatabase.FileName = Path.GetFileName( OldFileName );
if ( openFileDialogDatabase.ShowDialog( this ) != DialogResult.OK )
return;
SetRegKey( "DatabaseFileName", openFileDialogDatabase.FileName );
try
{
Database D = new Database();
try
{
D.Load( new FileInfo( openFileDialogDatabase.FileName ) );
}
catch ( Database.InvalidDatabaseRootPathException _e )
{
MessageBox( "The database could not be opened completely as it did not manage to reconnect manifest files on disk based on its embedded location path.\nConsider changing the root folder location to a valid path.\n\nError: " + _e.Message, MessageBoxButtons.OK, MessageBoxIcon.Warning );
}
if ( m_Database != null )
m_Database.Dispose();
Database = D;
// Update UI
textBoxDatabaseFileName.Text = openFileDialogDatabase.FileName;
UpdateDatabaseEntries();
}
catch ( Exception _e )
{
MessageBox( "An error occurred while opening the database:\n\n", _e );
}
}