public static void LoadPBProfile(string path, XElement element = null) { PbProfile profile = null; if (!string.IsNullOrEmpty(path)) { if (File.Exists(path)) { PBLog.Log("Loading profile {0} from file", Path.GetFileName(path)); profile = PbProfile.LoadFromFile(path); Instance.MySettings.LastProfile = path; } else { PBLog.Warn("Profile: {0} does not exist", path); Instance.MySettings.LastProfile = path; return; } } else if (element != null) { PBLog.Log("Loading profile from Xml element"); profile = PbProfile.LoadFromXml(element); } if (profile == null) { return; } Instance.CurrentProfile = profile; Instance.MySettings.LastProfile = path; Instance.ProfileSettings.Load(); DynamicCodeCompiler.GenorateDynamicCode(); Instance.UpdateMaterials(); if (MainForm.IsValid) { MainForm.Instance.InitActionTree(); MainForm.Instance.RefreshTradeSkillTabs(); } if (MainForm.IsValid) { MainForm.Instance.UpdateControls(); } Instance.MySettings.Save(); }
private void ToolStripSaveClick(object sender, EventArgs e) { saveFileDialog.DefaultExt = "xml"; saveFileDialog.FilterIndex = 1; saveFileDialog.FileName = ProfessionbuddyBot.Instance.CurrentProfile != null && ProfessionbuddyBot.Instance.CurrentProfile.XmlPath != null ? ProfessionbuddyBot.Instance.CurrentProfile.XmlPath : ""; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string extension = Path.GetExtension(saveFileDialog.FileName); bool zip = extension != null && extension.Equals( ".package", StringComparison.InvariantCultureIgnoreCase); // if we are saving to a zip check if CurrentProfile.XmlPath is not blank/null and use it if not. // otherwise use the selected zipname with xml ext. if (ProfessionbuddyBot.Instance.CurrentProfile != null) { string xmlfile = zip ? (ProfessionbuddyBot.Instance.CurrentProfile != null && string.IsNullOrEmpty(ProfessionbuddyBot.Instance.CurrentProfile.XmlPath) ? Path.ChangeExtension(saveFileDialog.FileName, ".xml") : ProfessionbuddyBot.Instance.CurrentProfile.XmlPath) : saveFileDialog.FileName; PBLog.Log("Saving profile to {0}", saveFileDialog.FileName); if (ProfessionbuddyBot.Instance.CurrentProfile != null) { ProfessionbuddyBot.Instance.CurrentProfile.SaveXml(xmlfile); if (zip) { PbProfile.CreatePackage(saveFileDialog.FileName, xmlfile); } } } ProfessionbuddyBot.Instance.MySettings.LastProfile = saveFileDialog.FileName; ProfessionbuddyBot.Instance.MySettings.Save(); UpdateControls(); } }