public static Profile Load(string appDir, out bool createdNew)
{
Logger.V(">> Profile.Load");
Profile profile = null;
string profilePath = Path.Combine(appDir, PROFILE_FILE_NAME);
if (File.Exists(profilePath)) {
XmlSerializer xs = new XmlSerializer(typeof(Profile));
StreamReader reader = new StreamReader(profilePath);
createdNew = false;
try {
profile = (Profile)xs.Deserialize(reader.BaseStream);
profile.m_szProfilePath = profilePath;
reader.Close();
} catch (Exception) {
reader.Close();
DialogResult dr = MessageBox.Show(
"Error occurs in loading the profile."
+ Environment.NewLine + Environment.NewLine
+ "- Press 'Yes' to load the default profile settings, "
+ "but user settings will be lost."
+ Environment.NewLine
+ "- Press 'No' to exit for manually fixing the error in the editor.",
AppManager.ASSEMBLY_PRODUCT,
MessageBoxButtons.YesNo,
MessageBoxIcon.Error);
if (dr == DialogResult.Yes) {
// create an initial profile
profile = new Profile();
profile.m_szProfilePath = profilePath;
Save(profile);
createdNew = true;
} else {
// exit application
s_bLoadFailed = true;
Application.Exit();
}
}
} else {
profile = new Profile();
profile.m_szProfilePath = profilePath;
Save(profile);
createdNew = true;
}
Logger.V("<< Profile.Load");
return profile;
}