private void bWorldDel_Click( object sender, EventArgs e )
{
if ( dgvWorlds.SelectedRows.Count > 0 ) {
WorldListEntry world = Worlds[dgvWorlds.SelectedRows[0].Index];
// prompt to delete map file, if it exists
if ( File.Exists( world.FullFileName ) ) {
string promptMessage = String.Format( "Are you sure you want to delete world \"{0}\"?", world.Name );
if ( MessageBox.Show( promptMessage, "Deleting a world", MessageBoxButtons.YesNo ) == DialogResult.No ) {
return;
}
string fileDeleteWarning = "Do you want to delete the map file (" + world.FileName + ") as well?";
if ( MessageBox.Show( fileDeleteWarning, "Warning", MessageBoxButtons.YesNo ) == DialogResult.Yes ) {
try {
File.Delete( world.FullFileName );
} catch ( Exception ex ) {
MessageBox.Show( "You have to delete the file (" + world.FileName + ") manually. " +
"An error occured while trying to delete it automatically:" + Environment.NewLine + ex,
"Could not delete map file" );
}
}
}
Worlds.Remove( world );
if ( cMainWorld.SelectedItem == null ) {
// deleting non-main world
FillWorldList();
if ( cMainWorld.Items.Count > 0 ) {
cMainWorld.SelectedIndex = 0;
}
} else {
// deleting main world
string mainWorldName = cMainWorld.SelectedItem.ToString();
FillWorldList();
if ( mainWorldName == world.Name ) {
MessageBox.Show( "Main world has been reset." );
if ( cMainWorld.Items.Count > 0 ) {
cMainWorld.SelectedIndex = 0;
}
} else {
cMainWorld.SelectedItem = mainWorldName;
}
}
}
}