/// <summary> /// Load a Character and open the correct window. /// </summary> /// <param name="strFileName">File to load.</param> /// <param name="blnIncludeInMRU">Whether or not the file should appear in the MRU list.</param> /// <param name="strNewName">New name for the character.</param> /// <param name="blnClearFileName">Whether or not the name of the save file should be cleared.</param> public void LoadCharacter(string strFileName, bool blnIncludeInMRU = true, string strNewName = "", bool blnClearFileName = false) { if (File.Exists(strFileName) && strFileName.EndsWith("chum5")) { Timekeeper.Start("loading"); bool blnLoaded = false; Character objCharacter = new Character(); objCharacter.FileName = strFileName; Timekeeper.Start("load_file"); blnLoaded = objCharacter.Load(); Timekeeper.Finish("load_file"); Timekeeper.Start("load_free"); if (!blnLoaded) { return; } // If a new name is given, set the character's name to match (used in cloning). if (strNewName != "") { objCharacter.Name = strNewName; } // Clear the File Name field so that this does not accidentally overwrite the original save file (used in cloning). if (blnClearFileName) { objCharacter.FileName = ""; } // Show the character form. if (!objCharacter.Created) { frmCreate frmCharacter = new frmCreate(objCharacter); frmCharacter.MdiParent = this; frmCharacter.WindowState = FormWindowState.Maximized; frmCharacter.Loading = true; frmCharacter.Show(); } else { frmCareer frmCharacter = new frmCareer(objCharacter); frmCharacter.MdiParent = this; frmCharacter.WindowState = FormWindowState.Maximized; frmCharacter.Loading = true; frmCharacter.DiceRollerOpened += objCareer_DiceRollerOpened; frmCharacter.DiceRollerOpenedInt += objCareer_DiceRollerOpenedInt; frmCharacter.Show(); } if (blnIncludeInMRU) { GlobalOptions.Instance.AddToMRUList(strFileName); } objCharacter.CharacterNameChanged += objCharacter_CharacterNameChanged; objCharacter_CharacterNameChanged(objCharacter); } else { MessageBox.Show(LanguageManager.Instance.GetString("Message_FileNotFound").Replace("{0}", strFileName), LanguageManager.Instance.GetString("MessageTitle_FileNotFound"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public frmMain() { InitializeComponent(); Version version = Assembly.GetExecutingAssembly().GetName().Version; string strCurrentVersion = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build); this.Text = string.Format("Chummer 5a - Version " + strCurrentVersion); #if DEBUG Text += " DEBUG BUILD"; #endif LanguageManager.Instance.Load(GlobalOptions.Instance.Language, this); /** Dashboard **/ //this.toolsMenu.DropDownItems.Add("GM Dashboard").Click += this.dashboardToolStripMenuItem_Click; /** End Dashboard **/ // If Automatic Updates are enabled, check for updates immediately. #if RELEASE if (Utils.GitUpdateAvailable() > 0) { if (GlobalOptions.Instance.AutomaticUpdate) { frmUpdate frmAutoUpdate = new frmUpdate(); frmAutoUpdate.SilentMode = true; frmAutoUpdate.Visible = false; frmAutoUpdate.ShowDialog(this); } else { this.Text += String.Format(" - Update {0} now available!", Utils.GitVersion()); } } #endif GlobalOptions.Instance.MRUChanged += PopulateMRU; // Delete the old executable if it exists (created by the update process). if (File.Exists("Chummer.exe.old")) { try { File.Delete("Chummer.exe.old"); } catch { } } // Populate the MRU list. PopulateMRU(); GlobalOptions.Instance.MainForm = this; // Set the Tag for each ToolStrip item so it can be translated. foreach (ToolStripMenuItem objItem in menuStrip.Items.OfType <ToolStripMenuItem>()) { if (objItem.Tag != null) { objItem.Text = LanguageManager.Instance.GetString(objItem.Tag.ToString()); } } // ToolStrip Items. foreach (ToolStrip objToolStrip in this.Controls.OfType <ToolStrip>()) { foreach (ToolStripButton objButton in objToolStrip.Items.OfType <ToolStripButton>()) { if (objButton.Tag != null) { objButton.Text = LanguageManager.Instance.GetString(objButton.Tag.ToString()); } } } // Attempt to cache the XML files that are used the most. try { Timekeeper.Start("cache_load"); XmlManager.Instance.Load("armor.xml"); XmlManager.Instance.Load("bioware.xml"); XmlManager.Instance.Load("books.xml"); XmlManager.Instance.Load("cyberware.xml"); XmlManager.Instance.Load("gear.xml"); XmlManager.Instance.Load("lifestyles.xml"); XmlManager.Instance.Load("metatypes.xml"); XmlManager.Instance.Load("qualities.xml"); XmlManager.Instance.Load("ranges.xml"); XmlManager.Instance.Load("skills.xml"); XmlManager.Instance.Load("vehicles.xml"); XmlManager.Instance.Load("weapons.xml"); Timekeeper.Finish("cache_load"); } catch { } frmCharacterRoster frmCharacter = new frmCharacterRoster(); frmCharacter.MdiParent = this; // Retrieve the arguments passed to the application. If more than 1 is passed, we're being given the name of a file to open. string[] strArgs = Environment.GetCommandLineArgs(); if (strArgs.GetUpperBound(0) > 0) { if (strArgs[1] != "/debug") { LoadCharacter(strArgs[1]); } if (strArgs.Length > 2) { if (strArgs[2] == "/test") { frmTest frmTestData = new frmTest(); frmTestData.Show(); } } } frmCharacter.WindowState = FormWindowState.Maximized; frmCharacter.Show(); }
/// <summary> /// Load a Character and open the correct window. /// </summary> /// <param name="strFileName">File to load.</param> /// <param name="blnIncludeInMRU">Whether or not the file should appear in the MRU list.</param> /// <param name="strNewName">New name for the character.</param> /// <param name="blnClearFileName">Whether or not the name of the save file should be cleared.</param> public void LoadCharacter(string strFileName, bool blnIncludeInMRU = true, string strNewName = "", bool blnClearFileName = false) { if (File.Exists(strFileName) && strFileName.EndsWith("chum5")) { Timekeeper.Start("loading"); Cursor.Current = Cursors.WaitCursor; bool blnLoaded = false; Character objCharacter = new Character(); objCharacter.FileName = strFileName; XmlDocument objXmlDocument = new XmlDocument(); //StreamReader is used to prevent encoding errors using (StreamReader sr = new StreamReader(strFileName, true)) { try { objXmlDocument.Load(sr); } catch (XmlException ex) { MessageBox.Show(LanguageManager.GetString("Message_FailedLoad").Replace("{0}", ex.Message), LanguageManager.GetString("MessageTitle_FailedLoad"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } XmlNode objXmlCharacter = objXmlDocument.SelectSingleNode("/character"); if (!string.IsNullOrEmpty(objXmlCharacter?["appversion"]?.InnerText)) { Version verSavedVersion; Version verCorrectedVersion; string strVersion = objXmlCharacter["appversion"].InnerText; if (strVersion.StartsWith("0.")) { strVersion = strVersion.Substring(2); } Version.TryParse(strVersion, out verSavedVersion); Version.TryParse("5.188.34", out verCorrectedVersion); if (verCorrectedVersion != null && verSavedVersion != null) { int intResult = verSavedVersion.CompareTo(verCorrectedVersion); //Check for typo in Corrupter quality and correct it if (intResult == -1) { File.WriteAllText(strFileName, Regex.Replace(File.ReadAllText(strFileName), "Corruptor", "Corrupter")); } } } Timekeeper.Start("load_file"); blnLoaded = objCharacter.Load(); Timekeeper.Finish("load_file"); Timekeeper.Start("load_free"); if (!blnLoaded) { Cursor.Current = Cursors.Default; return; } // If a new name is given, set the character's name to match (used in cloning). if (!string.IsNullOrEmpty(strNewName)) { objCharacter.Name = strNewName; } // Clear the File Name field so that this does not accidentally overwrite the original save file (used in cloning). if (blnClearFileName) { objCharacter.FileName = string.Empty; } // Show the character form. if (!objCharacter.Created) { frmCreate frmCharacter = new frmCreate(objCharacter) { MdiParent = this, WindowState = FormWindowState.Maximized, Loading = true }; frmCharacter.Show(); } else { frmCareer frmCharacter = new frmCareer(objCharacter) { MdiParent = this, WindowState = FormWindowState.Maximized, Loading = true }; frmCharacter.DiceRollerOpened += objCareer_DiceRollerOpened; frmCharacter.DiceRollerOpenedInt += objCareer_DiceRollerOpenedInt; frmCharacter.Show(); } if (blnIncludeInMRU) { GlobalOptions.AddToMRUList(strFileName); } objCharacter.CharacterNameChanged += objCharacter_CharacterNameChanged; objCharacter_CharacterNameChanged(objCharacter); Cursor.Current = Cursors.Default; } else { MessageBox.Show(LanguageManager.GetString("Message_FileNotFound").Replace("{0}", strFileName), LanguageManager.GetString("MessageTitle_FileNotFound"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public frmMain() { InitializeComponent(); Version version = Assembly.GetExecutingAssembly().GetName().Version; string strCurrentVersion = $"{version.Major}.{version.Minor}.{version.Build}"; Text = string.Format("Chummer 5a - Version " + strCurrentVersion); #if DEBUG Text += " DEBUG BUILD"; #endif LanguageManager.Load(GlobalOptions.Language, this); /** Dashboard **/ //this.toolsMenu.DropDownItems.Add("GM Dashboard").Click += this.dashboardToolStripMenuItem_Click; /** End Dashboard **/ // If Automatic Updates are enabled, check for updates immediately. #if RELEASE if (Utils.GitUpdateAvailable() > 0) { if (GlobalOptions.AutomaticUpdate) { frmUpdate frmAutoUpdate = new frmUpdate(); frmAutoUpdate.SilentMode = true; frmAutoUpdate.Visible = false; frmAutoUpdate.ShowDialog(this); } else { this.Text += String.Format(" - Update {0} now available!", Utils.GitVersion()); } } #endif GlobalOptions.MRUChanged += PopulateMRU; // Delete the old executable if it exists (created by the update process). foreach (string strLoopOldFilePath in Directory.GetFiles(Application.StartupPath, "*.old")) { if (File.Exists(strLoopOldFilePath)) { File.Delete(strLoopOldFilePath); } } // Populate the MRU list. PopulateMRU(); GlobalOptions.MainForm = this; // Set the Tag for each ToolStrip item so it can be translated. foreach (ToolStripMenuItem objItem in menuStrip.Items.OfType <ToolStripMenuItem>()) { if (objItem.Tag != null) { objItem.Text = LanguageManager.GetString(objItem.Tag.ToString()); } } // ToolStrip Items. foreach (ToolStrip objToolStrip in Controls.OfType <ToolStrip>()) { foreach (ToolStripButton objButton in objToolStrip.Items.OfType <ToolStripButton>()) { if (objButton.Tag != null) { objButton.Text = LanguageManager.GetString(objButton.Tag.ToString()); } } } // Attempt to cache all XML files that are used the most. Timekeeper.Start("cache_load"); XmlManager.Load("armor.xml"); XmlManager.Load("bioware.xml"); XmlManager.Load("books.xml"); XmlManager.Load("complexforms.xml"); XmlManager.Load("contacts.xml"); XmlManager.Load("critters.xml"); XmlManager.Load("critterpowers.xml"); XmlManager.Load("cyberware.xml"); // XmlManager.Load("drugcomponents.xml"); TODO: Re-enable when Custom Drugs branch is merged XmlManager.Load("echoes.xml"); XmlManager.Load("gameplayoptions.xml"); XmlManager.Load("gear.xml"); XmlManager.Load("improvements.xml"); XmlManager.Load("licenses.xml"); XmlManager.Load("lifemodules.xml"); XmlManager.Load("lifestyles.xml"); XmlManager.Load("martialarts.xml"); XmlManager.Load("mentors.xml"); XmlManager.Load("metamagic.xml"); XmlManager.Load("metatypes.xml"); XmlManager.Load("options.xml"); XmlManager.Load("packs.xml"); XmlManager.Load("powers.xml"); XmlManager.Load("priorities.xml"); XmlManager.Load("programs.xml"); XmlManager.Load("qualities.xml"); XmlManager.Load("ranges.xml"); XmlManager.Load("skills.xml"); XmlManager.Load("spells.xml"); XmlManager.Load("spiritpowers.xml"); XmlManager.Load("traditions.xml"); XmlManager.Load("vehicles.xml"); XmlManager.Load("weapons.xml"); Timekeeper.Finish("cache_load"); frmCharacterRoster frmCharacter = new frmCharacterRoster(); frmCharacter.MdiParent = this; // Retrieve the arguments passed to the application. If more than 1 is passed, we're being given the name of a file to open. string[] strArgs = Environment.GetCommandLineArgs(); if (strArgs.GetUpperBound(0) > 0) { if (strArgs[1] != "/debug") { LoadCharacter(strArgs[1]); } if (strArgs.Length > 2) { if (strArgs[2] == "/test") { frmTest frmTestData = new frmTest(); frmTestData.Show(); } } } frmCharacter.WindowState = FormWindowState.Maximized; frmCharacter.Show(); }
public frmChummerMain() { InitializeComponent(); _strCurrentVersion = $"{_objCurrentVersion.Major}.{_objCurrentVersion.Minor}.{_objCurrentVersion.Build}"; this.Text = "Chummer 5a - Version " + _strCurrentVersion; #if DEBUG Text += " DEBUG BUILD"; #endif LanguageManager.TranslateWinForm(GlobalOptions.Language, this); /** Dashboard **/ //this.toolsMenu.DropDownItems.Add("GM Dashboard").Click += this.dashboardToolStripMenuItem_Click; /** End Dashboard **/ // If Automatic Updates are enabled, check for updates immediately. #if !DEBUG _workerVersionUpdateChecker.WorkerReportsProgress = false; _workerVersionUpdateChecker.WorkerSupportsCancellation = false; _workerVersionUpdateChecker.DoWork += DoCacheGitVersion; _workerVersionUpdateChecker.RunWorkerCompleted += CheckForUpdate; Application.Idle += IdleUpdateCheck; _workerVersionUpdateChecker.RunWorkerAsync(); #endif GlobalOptions.MRUChanged += PopulateMRUToolstripMenu; // Delete the old executable if it exists (created by the update process). foreach (string strLoopOldFilePath in Directory.GetFiles(Application.StartupPath, "*.old", SearchOption.AllDirectories)) { if (File.Exists(strLoopOldFilePath)) { File.Delete(strLoopOldFilePath); } } // Populate the MRU list. PopulateMRUToolstripMenu(); Program.MainForm = this; // Set the Tag for each ToolStrip item so it can be translated. foreach (ToolStripMenuItem objItem in menuStrip.Items.OfType <ToolStripMenuItem>()) { LanguageManager.TranslateToolStripItemsRecursively(objItem, GlobalOptions.Language); } // Attempt to cache all XML files that are used the most. Timekeeper.Start("cache_load"); Parallel.Invoke( () => XmlManager.Load("armor.xml"), () => XmlManager.Load("bioware.xml"), () => XmlManager.Load("books.xml"), () => XmlManager.Load("complexforms.xml"), () => XmlManager.Load("contacts.xml"), () => XmlManager.Load("critters.xml"), () => XmlManager.Load("critterpowers.xml"), () => XmlManager.Load("cyberware.xml"), //() => XmlManager.Load("drugcomponents.xml"), TODO: Re-enable when Custom Drugs branch is merged () => XmlManager.Load("echoes.xml"), () => XmlManager.Load("gameplayoptions.xml"), () => XmlManager.Load("gear.xml"), () => XmlManager.Load("improvements.xml"), () => XmlManager.Load("licenses.xml"), () => XmlManager.Load("lifemodules.xml"), () => XmlManager.Load("lifestyles.xml"), () => XmlManager.Load("martialarts.xml"), () => XmlManager.Load("mentors.xml"), () => XmlManager.Load("metamagic.xml"), () => XmlManager.Load("metatypes.xml"), () => XmlManager.Load("options.xml"), () => XmlManager.Load("packs.xml"), () => XmlManager.Load("powers.xml"), () => XmlManager.Load("priorities.xml"), () => XmlManager.Load("programs.xml"), () => XmlManager.Load("qualities.xml"), () => XmlManager.Load("ranges.xml"), () => XmlManager.Load("sheets.xml"), () => XmlManager.Load("skills.xml"), () => XmlManager.Load("spells.xml"), () => XmlManager.Load("spiritpowers.xml"), () => XmlManager.Load("traditions.xml"), () => XmlManager.Load("vehicles.xml"), () => XmlManager.Load("weapons.xml") ); Timekeeper.Finish("cache_load"); _frmCharacterRoster = new frmCharacterRoster { MdiParent = this }; // Retrieve the arguments passed to the application. If more than 1 is passed, we're being given the name of a file to open. string[] strArgs = Environment.GetCommandLineArgs(); string strLoop = string.Empty; List <Character> lstCharactersToLoad = new List <Character>(); object lstCharactersToLoadLock = new object(); bool blnShowTest = false; object blnShowTestLock = new object(); Parallel.For(1, strArgs.Length, i => { strLoop = strArgs[i]; if (strLoop == "/test") { lock (blnShowTestLock) blnShowTest = true; } else if (!strLoop.StartsWith('/')) { Character objLoopCharacter = LoadCharacter(strLoop); lock (lstCharactersToLoadLock) lstCharactersToLoad.Add(objLoopCharacter); } }); if (blnShowTest) { frmTest frmTestData = new frmTest(); frmTestData.Show(); } OpenCharacterList(lstCharactersToLoad); _frmCharacterRoster.WindowState = FormWindowState.Maximized; _frmCharacterRoster.Show(); }
/// <summary> /// Load a Character from a file and return it (thread-safe). /// </summary> /// <param name="strFileName">File to load.</param> /// <param name="blnIncludeInMRU">Whether or not the file should appear in the MRU list.</param> /// <param name="strNewName">New name for the character.</param> /// <param name="blnClearFileName">Whether or not the name of the save file should be cleared.</param> public Character LoadCharacter(string strFileName, string strNewName = "", bool blnClearFileName = false, bool blnShowErrors = true) { Character objCharacter = null; if (File.Exists(strFileName) && strFileName.EndsWith("chum5")) { Timekeeper.Start("loading"); bool blnLoaded = false; objCharacter = new Character { FileName = strFileName }; XmlDocument objXmlDocument = new XmlDocument(); //StreamReader is used to prevent encoding errors using (StreamReader sr = new StreamReader(strFileName, true)) { try { objXmlDocument.Load(sr); } catch (XmlException ex) { if (blnShowErrors) { MessageBox.Show(LanguageManager.GetString("Message_FailedLoad", GlobalOptions.Language).Replace("{0}", ex.Message), LanguageManager.GetString("MessageTitle_FailedLoad", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } return(null); } } XmlNode objXmlCharacter = objXmlDocument.SelectSingleNode("/character"); if (!string.IsNullOrEmpty(objXmlCharacter?["appversion"]?.InnerText)) { string strVersion = objXmlCharacter["appversion"].InnerText; if (strVersion.StartsWith("0.")) { strVersion = strVersion.Substring(2); } Version.TryParse(strVersion, out Version verSavedVersion); Version.TryParse("5.188.34", out Version verCorrectedVersion); if (verCorrectedVersion != null && verSavedVersion != null) { int intResult = verSavedVersion.CompareTo(verCorrectedVersion); //Check for typo in Corrupter quality and correct it if (intResult == -1) { File.WriteAllText(strFileName, Regex.Replace(File.ReadAllText(strFileName), "Corruptor", "Corrupter")); } } } OpenCharacters.Add(objCharacter); Timekeeper.Start("load_file"); blnLoaded = objCharacter.Load(); Timekeeper.Finish("load_file"); if (!blnLoaded) { objCharacter.Dispose(); OpenCharacters.Remove(objCharacter); return(null); } // If a new name is given, set the character's name to match (used in cloning). if (!string.IsNullOrEmpty(strNewName)) { objCharacter.Name = strNewName; } // Clear the File Name field so that this does not accidentally overwrite the original save file (used in cloning). if (blnClearFileName) { objCharacter.FileName = string.Empty; } } else if (blnShowErrors) { MessageBox.Show(LanguageManager.GetString("Message_FileNotFound", GlobalOptions.Language).Replace("{0}", strFileName), LanguageManager.GetString("MessageTitle_FileNotFound", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } return(objCharacter); }