private User ReadUserFile(string userName, string path) { var user = new User(userName, path); try { try { user.Load(/*forceReadIncompatibleVersion*/false); } catch (IncompatibleVersionException) { IncompatibleVersion(); user.Load(/*forceReadIncompatibleVersion*/true); } catch (FileNotFoundException) { MessageBox.Show(this, "User file \"" + path + "\" is missing in user data location. Exiting application.", "User file not found", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); return null; } } catch (Exception e) { MessageBox.Show(this, "Unable to load user file: " + e.Message + " Exiting application.", "Unable to load user file", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } return user; }
private bool SelectUser() { var formSelectUser = new FormSelectUser(user != null ? user.Name : null); if (formSelectUser.ShowDialog(this) != DialogResult.OK) { return false; } else { var userName = formSelectUser.SelectedUser; var userFilePath = formSelectUser.UserFilePath; user = ReadUserFile(userName, userFilePath); if (user == null) { return false; } PopulateControls(); return true; } }
private void buttonReload_Click(object sender, EventArgs e) { user = ReadUserFile(user.Name, user.UserFilePath); PopulateControls(); MarkChanged(false); }