public frmSelectSpellCategory(Character objCharacter) { InitializeComponent(); this.UpdateLightDarkMode(); this.TranslateWinForm(); _objXmlDocument = XmlManager.LoadXPath("spells.xml", objCharacter?.Options.EnabledCustomDataDirectoryPaths); }
public SelectSkillGroup(Character objCharacter) { InitializeComponent(); this.UpdateLightDarkMode(); this.TranslateWinForm(); _objXmlDocument = XmlManager.LoadXPath("skills.xml", objCharacter?.Settings.EnabledCustomDataDirectoryPaths); }
public Chummy(Character objCharacter) { InitializeComponent(); using (Graphics g = CreateGraphics()) { _eyeballCenter = new Point((int)(95 * g.DpiX / 96.0f), (int)(15 * g.DpiY / 96.0f)); _mouthCenter = new Point((int)(100 * g.DpiX / 96.0f), (int)(50 * g.DpiY / 96.0f)); _thickPen = new Pen(Color.Black, (int)(3 * g.DpiY / 96.0f)); } Paint += panel1_Paint; using (var tmrDraw = new Timer { Interval = 100 }) { tmrDraw.Tick += tmr_DrawTick; tmrDraw.Start(); } using (var tmrTip = new Timer { Interval = 300000 }) { tmrTip.Tick += tmr_TipTick; tmrTip.Start(); } _myToolTip.Show(LanguageManager.GetString("Chummy_Intro").WordWrap(), this, _mouthCenter); _objXmlDocument = (objCharacter?.LoadDataXPath("tips.xml") ?? XmlManager.LoadXPath("tips.xml")).SelectSingleNode("/chummer/tips"); }
private static void LoadCharacterOptions() { s_dicLoadedCharacterOptions.Clear(); foreach (XPathNavigator xmlBuiltInSetting in XmlManager.LoadXPath("settings.xml").CreateNavigator().Select("/chummer/settings/setting")) { CharacterOptions objNewCharacterOptions = new CharacterOptions(); if (objNewCharacterOptions.Load(xmlBuiltInSetting) && (!objNewCharacterOptions.BuildMethodIsLifeModule || GlobalOptions.LifeModuleEnabled)) { s_dicLoadedCharacterOptions.TryAdd(objNewCharacterOptions.SourceId, objNewCharacterOptions); } } string strSettingsPath = Path.Combine(Utils.GetStartupPath, "settings"); if (Directory.Exists(strSettingsPath)) { foreach (string strSettingsFilePath in Directory.EnumerateFiles(strSettingsPath, "*.xml")) { string strSettingName = Path.GetFileName(strSettingsFilePath); CharacterOptions objNewCharacterOptions = new CharacterOptions(); if (objNewCharacterOptions.Load(strSettingName, false) && (!objNewCharacterOptions.BuildMethodIsLifeModule || GlobalOptions.LifeModuleEnabled)) { s_dicLoadedCharacterOptions.TryAdd(strSettingName, objNewCharacterOptions); } } } }
public SelectWeaponCategory(Character objCharacter) { _objXmlDocument = XmlManager.LoadXPath("weapons.xml", objCharacter?.Settings.EnabledCustomDataDirectoryPaths); InitializeComponent(); this.UpdateLightDarkMode(); this.TranslateWinForm(); }
public frmSelectSpec(Skill skill) { _objSkill = skill ?? throw new ArgumentNullException(nameof(skill)); _objCharacter = skill.CharacterObject; InitializeComponent(); this.UpdateLightDarkMode(); this.TranslateWinForm(); _objXmlDocument = XmlManager.LoadXPath("skills.xml", _objCharacter?.Options.EnabledCustomDataDirectoryPaths); }
private static void LoadCharacterSettings() { _intDicLoadedCharacterSettingsLoadedStatus = 0; try { s_DicLoadedCharacterSettings.Clear(); if (Utils.IsDesignerMode || Utils.IsRunningInVisualStudio) { CharacterSettings objNewCharacterSettings = new CharacterSettings(); if (!s_DicLoadedCharacterSettings.TryAdd(GlobalSettings.DefaultCharacterSetting, objNewCharacterSettings)) { objNewCharacterSettings.Dispose(); } return; } IEnumerable <XPathNavigator> xmlSettingsIterator = XmlManager.LoadXPath("settings.xml") .SelectAndCacheExpression("/chummer/settings/setting").Cast <XPathNavigator>(); Parallel.ForEach(xmlSettingsIterator, xmlBuiltInSetting => { CharacterSettings objNewCharacterSettings = new CharacterSettings(); if (!objNewCharacterSettings.Load(xmlBuiltInSetting) || (objNewCharacterSettings.BuildMethodIsLifeModule && !GlobalSettings.LifeModuleEnabled) || !s_DicLoadedCharacterSettings.TryAdd(objNewCharacterSettings.DictionaryKey, objNewCharacterSettings)) { objNewCharacterSettings.Dispose(); } }); string strSettingsPath = Path.Combine(Utils.GetStartupPath, "settings"); if (Directory.Exists(strSettingsPath)) { Parallel.ForEach(Directory.EnumerateFiles(strSettingsPath, "*.xml"), strSettingsFilePath => { string strSettingName = Path.GetFileName(strSettingsFilePath); CharacterSettings objNewCharacterSettings = new CharacterSettings(); if (!objNewCharacterSettings.Load(strSettingName, false) || (objNewCharacterSettings.BuildMethodIsLifeModule && !GlobalSettings.LifeModuleEnabled) || !s_DicLoadedCharacterSettings.TryAdd(objNewCharacterSettings.DictionaryKey, objNewCharacterSettings)) { objNewCharacterSettings.Dispose(); } }); } } finally { _intDicLoadedCharacterSettingsLoadedStatus = 1; } }
private static void LoadCharacterOptions() { s_intDicLoadedCharacterOptionsLoadedStatus = 0; try { s_dicLoadedCharacterOptions.Clear(); if (Utils.IsDesignerMode || Utils.IsRunningInVisualStudio) { s_dicLoadedCharacterOptions.TryAdd(GlobalOptions.DefaultCharacterOption, new CharacterOptions()); return; } IEnumerable <XPathNavigator> xmlSettingsIterator = XmlManager.LoadXPath("settings.xml") .Select("/chummer/settings/setting").Cast <XPathNavigator>(); Parallel.ForEach(xmlSettingsIterator, xmlBuiltInSetting => { CharacterOptions objNewCharacterOptions = new CharacterOptions(); if (objNewCharacterOptions.Load(xmlBuiltInSetting) && (!objNewCharacterOptions.BuildMethodIsLifeModule || GlobalOptions.LifeModuleEnabled)) { s_dicLoadedCharacterOptions.TryAdd(objNewCharacterOptions.SourceId, objNewCharacterOptions); } }); string strSettingsPath = Path.Combine(Utils.GetStartupPath, "settings"); if (Directory.Exists(strSettingsPath)) { Parallel.ForEach(Directory.EnumerateFiles(strSettingsPath, "*.xml"), strSettingsFilePath => { string strSettingName = Path.GetFileName(strSettingsFilePath); CharacterOptions objNewCharacterOptions = new CharacterOptions(); if (objNewCharacterOptions.Load(strSettingName, false) && (!objNewCharacterOptions.BuildMethodIsLifeModule || GlobalOptions.LifeModuleEnabled)) { s_dicLoadedCharacterOptions.TryAdd(strSettingName, objNewCharacterOptions); } }); } } finally { s_intDicLoadedCharacterOptionsLoadedStatus = 1; } }
/// <summary> /// Generates a character cache, which prevents us from repeatedly loading XmlNodes or caching a full character. /// </summary> /// <param name="strFile"></param> private TreeNode CacheCharacters(string strFile) { if (!File.Exists(strFile)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_File_Cannot_Be_Accessed") + Environment.NewLine + Environment.NewLine + strFile); return(null); } List <XPathNavigator> lstCharacterXmlStatblocks = new List <XPathNavigator>(3); try { using (ZipArchive zipArchive = ZipFile.Open(strFile, ZipArchiveMode.Read, Encoding.GetEncoding(850))) { foreach (ZipArchiveEntry entry in zipArchive.Entries) { string strEntryFullName = entry.FullName; if (strEntryFullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) && strEntryFullName.StartsWith("statblocks_xml", StringComparison.Ordinal)) { // If we run into any problems loading the character cache, fail out early. try { XPathDocument xmlSourceDoc; using (StreamReader sr = new StreamReader(entry.Open(), true)) using (XmlReader objXmlReader = XmlReader.Create(sr, GlobalOptions.SafeXmlReaderSettings)) xmlSourceDoc = new XPathDocument(objXmlReader); lstCharacterXmlStatblocks.Add(xmlSourceDoc.CreateNavigator()); } // If we run into any problems loading the character cache, fail out early. catch (IOException) { Utils.BreakIfDebug(); } catch (XmlException) { Utils.BreakIfDebug(); } } else if (strEntryFullName.StartsWith("images", StringComparison.Ordinal) && strEntryFullName.Contains('.')) { string strKey = Path.GetFileName(strEntryFullName); using (Bitmap bmpMugshot = new Bitmap(entry.Open(), true)) { Bitmap bmpNewMugshot = bmpMugshot.PixelFormat == PixelFormat.Format32bppPArgb ? bmpMugshot.Clone() as Bitmap // Clone makes sure file handle is closed : bmpMugshot.ConvertPixelFormat(PixelFormat.Format32bppPArgb); if (_dicImages.ContainsKey(strKey)) { _dicImages[strKey].Dispose(); _dicImages[strKey] = bmpNewMugshot; } else { _dicImages.Add(strKey, bmpNewMugshot); } } } } } } catch (IOException) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_File_Cannot_Be_Accessed") + Environment.NewLine + Environment.NewLine + strFile); return(null); } catch (NotSupportedException) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_File_Cannot_Be_Accessed") + Environment.NewLine + Environment.NewLine + strFile); return(null); } catch (UnauthorizedAccessException) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_Insufficient_Permissions_Warning")); return(null); } string strFileText = strFile.CheapReplace(Application.StartupPath, () => "<" + Application.ProductName + ">"); TreeNode nodRootNode = new TreeNode { Text = strFileText, ToolTipText = strFileText }; XPathNavigator xmlMetatypesDocument = XmlManager.LoadXPath("metatypes.xml"); foreach (XPathNavigator xmlCharacterDocument in lstCharacterXmlStatblocks) { XPathNavigator xmlBaseCharacterNode = xmlCharacterDocument.SelectSingleNode("/document/public/character"); if (xmlBaseCharacterNode != null) { HeroLabCharacterCache objCache = new HeroLabCharacterCache { PlayerName = xmlBaseCharacterNode.SelectSingleNode("@playername")?.Value ?? string.Empty }; string strNameString = xmlBaseCharacterNode.SelectSingleNode("@name")?.Value ?? string.Empty; objCache.CharacterId = strNameString; if (!string.IsNullOrEmpty(strNameString)) { int intAsIndex = strNameString.IndexOf(" as ", StringComparison.Ordinal); if (intAsIndex != -1) { objCache.CharacterName = strNameString.Substring(0, intAsIndex); objCache.CharacterAlias = strNameString.Substring(intAsIndex).TrimStart(" as ").Trim('\''); } else { objCache.CharacterName = strNameString; } } string strRaceString = xmlBaseCharacterNode.SelectSingleNode("race/@name")?.Value; if (strRaceString == "Metasapient") { strRaceString = "A.I."; } if (!string.IsNullOrEmpty(strRaceString)) { foreach (XPathNavigator xmlMetatype in xmlMetatypesDocument.Select("/chummer/metatypes/metatype")) { string strMetatypeName = xmlMetatype.SelectSingleNode("name")?.Value ?? string.Empty; if (strMetatypeName == strRaceString) { objCache.Metatype = strMetatypeName; objCache.Metavariant = "None"; break; } foreach (XPathNavigator xmlMetavariant in xmlMetatype.Select("metavariants/metavariant")) { string strMetavariantName = xmlMetavariant.SelectSingleNode("name")?.Value ?? string.Empty; if (strMetavariantName == strRaceString) { objCache.Metatype = strMetatypeName; objCache.Metavariant = strMetavariantName; break; } } } } objCache.Description = xmlBaseCharacterNode.SelectSingleNode("personal/description")?.Value; objCache.Karma = xmlBaseCharacterNode.SelectSingleNode("karma/@total")?.Value ?? "0"; objCache.Essence = xmlBaseCharacterNode.SelectSingleNode("attributes/attribute[@name = \"Essence\"]/@text")?.Value; objCache.BuildMethod = xmlBaseCharacterNode.SelectSingleNode("creation/bp/@total")?.Value == "25" ? CharacterBuildMethod.Priority.ToString() : CharacterBuildMethod.Karma.ToString(); objCache.Created = objCache.Karma != "0"; if (!objCache.Created) { XPathNodeIterator xmlJournalEntries = xmlBaseCharacterNode.Select("journals/journal"); if (xmlJournalEntries?.Count > 1) { objCache.Created = true; } else if (xmlJournalEntries?.Count == 1 && xmlJournalEntries.Current?.SelectSingleNode("@name")?.Value != "Title") { objCache.Created = true; } } string strImageString = xmlBaseCharacterNode.SelectSingleNode("images/image/@filename")?.Value; if (!string.IsNullOrEmpty(strImageString) && _dicImages.TryGetValue(strImageString, out Bitmap objTemp)) { objCache.Mugshot = objTemp; } objCache.FilePath = strFile; TreeNode objNode = new TreeNode { Text = CalculatedName(objCache), ToolTipText = strFile.CheapReplace(Application.StartupPath, () => "<" + Application.ProductName + ">") }; nodRootNode.Nodes.Add(objNode); lock (_lstCharacterCacheLock) { _lstCharacterCache.Add(objCache); objNode.Tag = _lstCharacterCache.IndexOf(objCache); } } } nodRootNode.Expand(); return(nodRootNode); }
/// <summary> /// Update the labels and images based on the selected treenode. /// </summary> /// <param name="objCache"></param> private void UpdateCharacter(HeroLabCharacterCache objCache) { if (objCache != null) { txtCharacterBio.Text = objCache.Description; string strUnknown = LanguageManager.GetString("String_Unknown"); string strNone = LanguageManager.GetString("String_None"); lblCharacterName.Text = objCache.CharacterName; if (string.IsNullOrEmpty(lblCharacterName.Text)) { lblCharacterName.Text = strUnknown; } lblCharacterNameLabel.Visible = !string.IsNullOrEmpty(lblCharacterName.Text); lblCharacterName.Visible = !string.IsNullOrEmpty(lblCharacterName.Text); lblCharacterAlias.Text = objCache.CharacterAlias; if (string.IsNullOrEmpty(lblCharacterAlias.Text)) { lblCharacterAlias.Text = strUnknown; } lblCharacterAliasLabel.Visible = !string.IsNullOrEmpty(lblCharacterAlias.Text); lblCharacterAlias.Visible = !string.IsNullOrEmpty(lblCharacterAlias.Text); lblPlayerName.Text = objCache.PlayerName; if (string.IsNullOrEmpty(lblPlayerName.Text)) { lblPlayerName.Text = strUnknown; } lblPlayerNameLabel.Visible = !string.IsNullOrEmpty(lblPlayerName.Text); lblPlayerName.Visible = !string.IsNullOrEmpty(lblPlayerName.Text); lblCareerKarma.Text = objCache.Karma; if (string.IsNullOrEmpty(lblCareerKarma.Text) || lblCareerKarma.Text == 0.ToString(GlobalOptions.CultureInfo)) { lblCareerKarma.Text = strNone; } lblCareerKarmaLabel.Visible = !string.IsNullOrEmpty(lblCareerKarma.Text); lblCareerKarma.Visible = !string.IsNullOrEmpty(lblCareerKarma.Text); lblEssence.Text = objCache.Essence; if (string.IsNullOrEmpty(lblEssence.Text)) { lblEssence.Text = strUnknown; } lblEssenceLabel.Visible = !string.IsNullOrEmpty(lblEssence.Text); lblEssence.Visible = !string.IsNullOrEmpty(lblEssence.Text); picMugshot.Image = objCache.Mugshot; // Populate character information fields. XPathNavigator objMetatypeDoc = XmlManager.LoadXPath("metatypes.xml"); XPathNavigator objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype.CleanXPath() + "]"); if (objMetatypeNode == null) { objMetatypeDoc = XmlManager.LoadXPath("critters.xml"); objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype.CleanXPath() + "]"); } string strMetatype = objMetatypeNode?.SelectSingleNode("translate")?.Value ?? objCache.Metatype; if (!string.IsNullOrEmpty(objCache.Metavariant) && objCache.Metavariant != "None") { objMetatypeNode = objMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = " + objCache.Metavariant.CleanXPath() + "]"); strMetatype += " (" + (objMetatypeNode?.SelectSingleNode("translate")?.Value ?? objCache.Metavariant) + ')'; } lblMetatype.Text = strMetatype; if (string.IsNullOrEmpty(lblMetatype.Text)) { lblMetatype.Text = strUnknown; } lblMetatypeLabel.Visible = !string.IsNullOrEmpty(lblMetatype.Text); lblMetatype.Visible = !string.IsNullOrEmpty(lblMetatype.Text); cmdImport.Enabled = true; } else { txtCharacterBio.Text = string.Empty; lblCharacterNameLabel.Visible = false; lblCharacterName.Visible = false; lblCharacterAliasLabel.Visible = false; lblCharacterAlias.Visible = false; lblPlayerNameLabel.Visible = false; lblPlayerName.Visible = false; lblMetatypeLabel.Visible = false; lblMetatype.Visible = false; lblCareerKarmaLabel.Visible = false; lblCareerKarma.Visible = false; lblEssenceLabel.Visible = false; lblEssence.Visible = false; picMugshot.Image = null; cmdImport.Enabled = false; } picMugshot_SizeChanged(null, EventArgs.Empty); }
/// <summary> /// Update the labels and images based on the selected treenode. /// </summary> /// <param name="objCache"></param> public void UpdateCharacter(CharacterCache objCache) { if (this.IsNullOrDisposed()) // Safety check for external calls { return; } tlpCharacterRoster.SuspendLayout(); if (objCache != null) { string strUnknown = LanguageManager.GetString("String_Unknown"); string strNone = LanguageManager.GetString("String_None"); txtCharacterBio.Text = objCache.Description.RtfToPlainText(); txtCharacterBackground.Text = objCache.Background.RtfToPlainText(); txtCharacterNotes.Text = objCache.CharacterNotes.RtfToPlainText(); txtGameNotes.Text = objCache.GameNotes.RtfToPlainText(); txtCharacterConcept.Text = objCache.Concept.RtfToPlainText(); lblCareerKarma.Text = objCache.Karma; if (string.IsNullOrEmpty(lblCareerKarma.Text) || lblCareerKarma.Text == 0.ToString(GlobalOptions.CultureInfo)) { lblCareerKarma.Text = strNone; } lblPlayerName.Text = objCache.PlayerName; if (string.IsNullOrEmpty(lblPlayerName.Text)) { lblPlayerName.Text = strUnknown; } lblCharacterName.Text = objCache.CharacterName; if (string.IsNullOrEmpty(lblCharacterName.Text)) { lblCharacterName.Text = strUnknown; } lblCharacterAlias.Text = objCache.CharacterAlias; if (string.IsNullOrEmpty(lblCharacterAlias.Text)) { lblCharacterAlias.Text = strUnknown; } lblEssence.Text = objCache.Essence; if (string.IsNullOrEmpty(lblEssence.Text)) { lblEssence.Text = strUnknown; } lblFilePath.Text = objCache.FileName; if (string.IsNullOrEmpty(lblFilePath.Text)) { lblFilePath.Text = LanguageManager.GetString("MessageTitle_FileNotFound"); } lblSettings.Text = objCache.SettingsFile; if (string.IsNullOrEmpty(lblSettings.Text)) { lblSettings.Text = strUnknown; } lblFilePath.SetToolTip(objCache.FilePath.CheapReplace(Utils.GetStartupPath, () => '<' + Application.ProductName + '>')); picMugshot.Image?.Dispose(); picMugshot.Image = objCache.Mugshot; // Populate character information fields. XPathNavigator objMetatypeDoc = XmlManager.LoadXPath("metatypes.xml"); if (objCache.Metatype != null) { XPathNavigator objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype?.CleanXPath() + "]"); if (objMetatypeNode == null) { objMetatypeDoc = XmlManager.LoadXPath("critters.xml"); objMetatypeNode = objMetatypeDoc.SelectSingleNode("/chummer/metatypes/metatype[name = " + objCache.Metatype?.CleanXPath() + "]"); } string strMetatype = objMetatypeNode?.SelectSingleNode("translate")?.Value ?? objCache.Metatype; if (!string.IsNullOrEmpty(objCache.Metavariant) && objCache.Metavariant != "None") { objMetatypeNode = objMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = " + objCache.Metavariant.CleanXPath() + "]"); strMetatype += LanguageManager.GetString("String_Space") + '(' + (objMetatypeNode?.SelectSingleNode("translate")?.Value ?? objCache.Metavariant) + ')'; } lblMetatype.Text = strMetatype; } else { lblMetatype.Text = LanguageManager.GetString("String_MetatypeLoadError"); } tabCharacterText.Visible = true; if (!string.IsNullOrEmpty(objCache.ErrorText)) { txtCharacterBio.Text = objCache.ErrorText; txtCharacterBio.ForeColor = ColorManager.ErrorColor; txtCharacterBio.BringToFront(); } else { txtCharacterBio.ForeColor = ColorManager.WindowText; } } else { tabCharacterText.Visible = false; txtCharacterBio.Clear(); txtCharacterBackground.Clear(); txtCharacterNotes.Clear(); txtGameNotes.Clear(); txtCharacterConcept.Clear(); lblCareerKarma.Text = string.Empty; lblMetatype.Text = string.Empty; lblPlayerName.Text = string.Empty; lblCharacterName.Text = string.Empty; lblCharacterAlias.Text = string.Empty; lblEssence.Text = string.Empty; lblFilePath.Text = string.Empty; lblFilePath.SetToolTip(string.Empty); lblSettings.Text = string.Empty; picMugshot.Image = null; } lblCareerKarmaLabel.Visible = !string.IsNullOrEmpty(lblCareerKarma.Text); lblMetatypeLabel.Visible = !string.IsNullOrEmpty(lblMetatype.Text); lblPlayerNameLabel.Visible = !string.IsNullOrEmpty(lblPlayerName.Text); lblCharacterNameLabel.Visible = !string.IsNullOrEmpty(lblCharacterName.Text); lblCharacterAliasLabel.Visible = !string.IsNullOrEmpty(lblCharacterAlias.Text); lblEssenceLabel.Visible = !string.IsNullOrEmpty(lblEssence.Text); lblFilePathLabel.Visible = !string.IsNullOrEmpty(lblFilePath.Text); lblSettingsLabel.Visible = !string.IsNullOrEmpty(lblSettings.Text); ProcessMugshotSizeMode(); tlpCharacterRoster.ResumeLayout(); }
private async void frmMasterIndex_Load(object sender, EventArgs e) { using (var op_load_frm_masterindex = Timekeeper.StartSyncron("op_load_frm_masterindex", null, CustomActivity.OperationType.RequestOperation, null)) { HashSet <string> setValidCodes = new HashSet <string>(); foreach (XPathNavigator xmlBookNode in (await XmlManager.LoadXPathAsync("books.xml")).Select("/chummer/books/book/code")) { setValidCodes.Add(xmlBookNode.Value); } string strSourceFilter = setValidCodes.Count > 0 ? new StringBuilder("(") .AppendJoin(" or ", setValidCodes.Select(x => "source = \'" + x + "\'")) .Append(')').ToString() : "source"; ConcurrentBag <ListItem> lstItemsForLoading = new ConcurrentBag <ListItem>(); ConcurrentBag <ListItem> lstFileNamesWithItemsForLoading = new ConcurrentBag <ListItem>(); using (_ = Timekeeper.StartSyncron("load_frm_masterindex_load_entries", op_load_frm_masterindex)) { // Prevents locking the UI thread while still benefitting from static scheduling of Parallel.ForEach await Task.Run(() => { Parallel.ForEach(_lstFileNames, strFileName => { XPathNavigator xmlBaseNode = XmlManager.LoadXPath(strFileName); xmlBaseNode = xmlBaseNode.SelectSingleNode("/chummer"); if (xmlBaseNode == null) { return; } bool blnLoopFileNameHasItems = false; foreach (XPathNavigator xmlItemNode in xmlBaseNode.Select(".//*[page and " + strSourceFilter + ']')) { blnLoopFileNameHasItems = true; string strName = xmlItemNode.SelectSingleNode("name")?.Value; string strDisplayName = xmlItemNode.SelectSingleNode("translate")?.Value ?? strName ?? xmlItemNode.SelectSingleNode("id")?.Value ?? LanguageManager.GetString("String_Unknown"); string strSource = xmlItemNode.SelectSingleNode("source")?.Value; string strPage = xmlItemNode.SelectSingleNode("page")?.Value; string strDisplayPage = xmlItemNode.SelectSingleNode("altpage")?.Value ?? strPage; string strEnglishNameOnPage = xmlItemNode.SelectSingleNode("nameonpage")?.Value ?? strName; string strTranslatedNameOnPage = xmlItemNode.SelectSingleNode("altnameonpage")?.Value ?? strDisplayName; string strNotes = xmlItemNode.SelectSingleNode("altnotes")?.Value ?? xmlItemNode.SelectSingleNode("notes")?.Value; MasterIndexEntry objEntry = new MasterIndexEntry( strDisplayName, strFileName, new SourceString(strSource, strPage, GlobalOptions.DefaultLanguage, GlobalOptions.InvariantCultureInfo), new SourceString(strSource, strDisplayPage, GlobalOptions.Language, GlobalOptions.CultureInfo), strEnglishNameOnPage, strTranslatedNameOnPage); lstItemsForLoading.Add(new ListItem(objEntry, strDisplayName)); if (!string.IsNullOrEmpty(strNotes)) { _dicCachedNotes.TryAdd(objEntry, strNotes); } } if (blnLoopFileNameHasItems) { lstFileNamesWithItemsForLoading.Add(new ListItem(strFileName, strFileName)); } }); }); } using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_entries", op_load_frm_masterindex)) { string strSpace = LanguageManager.GetString("String_Space"); string strFormat = "{0}" + strSpace + "[{1}]"; Dictionary <string, List <ListItem> > dicHelper = new Dictionary <string, List <ListItem> >(lstItemsForLoading.Count); foreach (ListItem objItem in lstItemsForLoading) { MasterIndexEntry objEntry = (MasterIndexEntry)objItem.Value; string strKey = objEntry.DisplayName.ToUpperInvariant(); if (dicHelper.TryGetValue(strKey, out List <ListItem> lstExistingItems)) { ListItem objExistingItem = lstExistingItems.FirstOrDefault(x => objEntry.DisplaySource.Equals(((MasterIndexEntry)x.Value).DisplaySource)); if (objExistingItem.Value != null) { ((MasterIndexEntry)objExistingItem.Value).FileNames.UnionWith(objEntry.FileNames); } else { List <ListItem> lstItemsNeedingNameChanges = lstExistingItems.Where(x => !objEntry.FileNames.IsSubsetOf(((MasterIndexEntry)x.Value).FileNames)).ToList(); if (lstItemsNeedingNameChanges.Count == 0) { _lstItems.Add(objItem); // Not using AddRange because of potential memory issues lstExistingItems.Add(objItem); } else { ListItem objItemToAdd = new ListItem(objItem.Value, string.Format(GlobalOptions.CultureInfo, strFormat, objItem.Name, string.Join(',' + strSpace, objEntry.FileNames))); _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues lstExistingItems.Add(objItemToAdd); foreach (ListItem objToRename in lstItemsNeedingNameChanges) { _lstItems.Remove(objToRename); lstExistingItems.Remove(objToRename); MasterIndexEntry objExistingEntry = (MasterIndexEntry)objToRename.Value; objItemToAdd = new ListItem(objToRename.Value, string.Format(GlobalOptions.CultureInfo, strFormat, objExistingEntry.DisplayName, string.Join(',' + strSpace, objExistingEntry.FileNames))); _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues lstExistingItems.Add(objItemToAdd); } } } } else { _lstItems.Add(objItem); // Not using AddRange because of potential memory issues dicHelper.Add(strKey, new List <ListItem>(objItem.Yield())); } } _lstFileNamesWithItems.AddRange(lstFileNamesWithItemsForLoading); } using (_ = Timekeeper.StartSyncron("load_frm_masterindex_sort_entries", op_load_frm_masterindex)) { _lstItems.Sort(CompareListItems.CompareNames); _lstFileNamesWithItems.Sort(CompareListItems.CompareNames); } using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_controls", op_load_frm_masterindex)) { _lstFileNamesWithItems.Insert(0, new ListItem(string.Empty, LanguageManager.GetString("String_All"))); cboFile.BeginUpdate(); cboFile.PopulateWithListItems(_lstFileNamesWithItems); try { cboFile.SelectedIndex = 0; } // For some reason, some unit tests will fire this exception even when _lstFileNamesWithItems is explicitly checked for having enough items catch (ArgumentOutOfRangeException) { cboFile.SelectedIndex = -1; } cboFile.EndUpdate(); lstItems.BeginUpdate(); lstItems.PopulateWithListItems(_lstItems); lstItems.SelectedIndex = -1; lstItems.EndUpdate(); _blnSkipRefresh = false; } } }
private void cmdOK_Click(object sender, EventArgs e) { // Make sure the kit and file name fields are populated. if (string.IsNullOrEmpty(txtName.Text)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_CreatePACKSKit_KitName"), LanguageManager.GetString("MessageTitle_CreatePACKSKit_KitName"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtFileName.Text)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_CreatePACKSKit_FileName"), LanguageManager.GetString("MessageTitle_CreatePACKSKit_FileName"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure the file name starts with custom and ends with _packs.xml. if (!txtFileName.Text.StartsWith("custom_", StringComparison.OrdinalIgnoreCase) || !txtFileName.Text.EndsWith("_packs.xml", StringComparison.OrdinalIgnoreCase)) { Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_CreatePACKSKit_InvalidFileName"), LanguageManager.GetString("MessageTitle_CreatePACKSKit_InvalidFileName"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // See if a Kit with this name already exists for the Custom category. // This was originally done without the XmlManager, but because amends and overrides and toggling custom data directories can change names, we need to use it. string strName = txtName.Text; if (XmlManager.LoadXPath("packs.xml", _objCharacter.Settings.EnabledCustomDataDirectoryPaths) .SelectSingleNode("/chummer/packs/pack[name = " + strName.CleanXPath() + " and category = \"Custom\"]") != null) { Program.MainForm.ShowMessageBox(this, string.Format(GlobalSettings.CultureInfo, LanguageManager.GetString("Message_CreatePACKSKit_DuplicateName"), strName), LanguageManager.GetString("MessageTitle_CreatePACKSKit_DuplicateName"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string strPath = Path.Combine(Utils.GetStartupPath, "data", txtFileName.Text); // If this is not a new file, read in the existing contents. XmlDocument objXmlCurrentDocument = null; if (File.Exists(strPath)) { try { objXmlCurrentDocument = new XmlDocument { XmlResolver = null }; objXmlCurrentDocument.LoadStandard(strPath); } catch (IOException ex) { Program.MainForm.ShowMessageBox(this, ex.ToString()); return; } catch (XmlException ex) { Program.MainForm.ShowMessageBox(this, ex.ToString()); return; } } using (FileStream objStream = new FileStream(strPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { using (XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8) { Formatting = Formatting.Indented, Indentation = 1, IndentChar = '\t' }) { objWriter.WriteStartDocument(); // <chummer> objWriter.WriteStartElement("chummer"); // <packs> objWriter.WriteStartElement("packs"); // If this is not a new file, write out the current contents. if (objXmlCurrentDocument != null) { using (XmlNodeList objXmlNodeList = objXmlCurrentDocument.SelectNodes("/chummer/*")) if (objXmlNodeList?.Count > 0) { foreach (XmlNode objXmlNode in objXmlNodeList) { objXmlNode.WriteContentTo(objWriter); } } } // <pack> objWriter.WriteStartElement("pack"); // <name /> objWriter.WriteElementString("name", txtName.Text); // <category /> objWriter.WriteElementString("category", "Custom"); // Export Attributes. if (chkAttributes.Checked) { int intBOD = _objCharacter.BOD.Value - (_objCharacter.BOD.MetatypeMinimum - 1); int intAGI = _objCharacter.AGI.Value - (_objCharacter.AGI.MetatypeMinimum - 1); int intREA = _objCharacter.REA.Value - (_objCharacter.REA.MetatypeMinimum - 1); int intSTR = _objCharacter.STR.Value - (_objCharacter.STR.MetatypeMinimum - 1); int intCHA = _objCharacter.CHA.Value - (_objCharacter.CHA.MetatypeMinimum - 1); int intINT = _objCharacter.INT.Value - (_objCharacter.INT.MetatypeMinimum - 1); int intLOG = _objCharacter.LOG.Value - (_objCharacter.LOG.MetatypeMinimum - 1); int intWIL = _objCharacter.WIL.Value - (_objCharacter.WIL.MetatypeMinimum - 1); int intEDG = _objCharacter.EDG.Value - (_objCharacter.EDG.MetatypeMinimum - 1); int intMAG = _objCharacter.MAG.Value - (_objCharacter.MAG.MetatypeMinimum - 1); int intMAGAdept = _objCharacter.MAGAdept.Value - (_objCharacter.MAGAdept.MetatypeMinimum - 1); int intDEP = _objCharacter.DEP.Value - (_objCharacter.DEP.MetatypeMinimum - 1); int intRES = _objCharacter.RES.Value - (_objCharacter.RES.MetatypeMinimum - 1); // <attributes> objWriter.WriteStartElement("attributes"); objWriter.WriteElementString("bod", intBOD.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("agi", intAGI.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("rea", intREA.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("str", intSTR.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("cha", intCHA.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("int", intINT.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("log", intLOG.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("wil", intWIL.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("edg", intEDG.ToString(GlobalSettings.InvariantCultureInfo)); if (_objCharacter.MAGEnabled) { objWriter.WriteElementString("mag", intMAG.ToString(GlobalSettings.InvariantCultureInfo)); if (_objCharacter.Settings.MysAdeptSecondMAGAttribute && _objCharacter.IsMysticAdept) { objWriter.WriteElementString("magadept", intMAGAdept.ToString(GlobalSettings.InvariantCultureInfo)); } } if (_objCharacter.RESEnabled) { objWriter.WriteElementString("res", intRES.ToString(GlobalSettings.InvariantCultureInfo)); } if (_objCharacter.DEPEnabled) { objWriter.WriteElementString("dep", intDEP.ToString(GlobalSettings.InvariantCultureInfo)); } // </attributes> objWriter.WriteEndElement(); } // Export Qualities. if (chkQualities.Checked) { bool blnPositive = false; bool blnNegative = false; // Determine if Positive or Negative Qualities exist. foreach (Quality objQuality in _objCharacter.Qualities) { switch (objQuality.Type) { case QualityType.Positive: blnPositive = true; break; case QualityType.Negative: blnNegative = true; break; } if (blnPositive && blnNegative) { break; } } // <qualities> objWriter.WriteStartElement("qualities"); // Positive Qualities. if (blnPositive) { // <positive> objWriter.WriteStartElement("positive"); foreach (Quality objQuality in _objCharacter.Qualities) { if (objQuality.Type == QualityType.Positive) { objWriter.WriteStartElement("quality"); if (!string.IsNullOrEmpty(objQuality.Extra)) { objWriter.WriteAttributeString("select", objQuality.Extra); } objWriter.WriteValue(objQuality.Name); objWriter.WriteEndElement(); } } // </positive> objWriter.WriteEndElement(); } // Negative Qualities. if (blnPositive) { // <negative> objWriter.WriteStartElement("negative"); foreach (Quality objQuality in _objCharacter.Qualities) { if (objQuality.Type == QualityType.Negative) { objWriter.WriteStartElement("quality"); if (!string.IsNullOrEmpty(objQuality.Extra)) { objWriter.WriteAttributeString("select", objQuality.Extra); } objWriter.WriteValue(objQuality.Name); objWriter.WriteEndElement(); } } // </negative> objWriter.WriteEndElement(); } // </qualities> objWriter.WriteEndElement(); } // Export Starting Nuyen. if (chkStartingNuyen.Checked) { decimal decNuyenBP = _objCharacter.NuyenBP; if (!_objCharacter.EffectiveBuildMethodUsesPriorityTables) { decNuyenBP /= 2.0m; } objWriter.WriteElementString("nuyenbp", decNuyenBP.ToString(GlobalSettings.InvariantCultureInfo)); } /* TODO: Add support for active and knowledge skills and skill groups * // Export Active Skills. * if (chkActiveSkills.Checked) * { * // <skills> * objWriter.WriteStartElement("skills"); * * // Active Skills. * foreach (Skill objSkill in _objCharacter.SkillsSection.Skills) * { * if (!objSkill.IsKnowledgeSkill && objSkill.Rating > 0) * { * // <skill> * objWriter.WriteStartElement("skill"); * objWriter.WriteElementString("name", objSkill.Name); * objWriter.WriteElementString("rating", objSkill.Rating.ToString()); * if (!string.IsNullOrEmpty(objSkill.Specialization)) * objWriter.WriteElementString("spec", objSkill.Specialization); * // </skill> * objWriter.WriteEndElement(); * } * } * * // Skill Groups. * foreach (SkillGroup objSkillGroup in _objCharacter.SkillsSection.SkillGroups) * { * if (objSkillGroup.BaseUnbroken && objSkillGroup.Rating > 0) * { * // <skillgroup> * objWriter.WriteStartElement("skillgroup"); * objWriter.WriteElementString("name", objSkillGroup.Name); * objWriter.WriteElementString("rating", objSkillGroup.Rating.ToString()); * // </skillgroup> * objWriter.WriteEndElement(); * } * } * // </skills> * objWriter.WriteEndElement(); * } * * // Export Knowledge Skills. * if (chkKnowledgeSkills.Checked) * { * // <knowledgeskills> * objWriter.WriteStartElement("knowledgeskills"); * foreach (KnowledgeSkill objSkill in _objCharacter.SkillsSection.Skills.OfType<KnowledgeSkill>()) * { * // <skill> * objWriter.WriteStartElement("skill"); * objWriter.WriteElementString("name", objSkill.Name); * objWriter.WriteElementString("rating", objSkill.Rating.ToString(GlobalSettings.InvariantCultureInfo)); * if (!string.IsNullOrEmpty(objSkill.Specialization)) * objWriter.WriteElementString("spec", objSkill.Specialization); * objWriter.WriteElementString("category", objSkill.SkillCategory); * // </skill> * objWriter.WriteEndElement(); * } * * // </knowledgeskills> * objWriter.WriteEndElement(); * } */ // Export Martial Arts. if (chkMartialArts.Checked) { // <martialarts> objWriter.WriteStartElement("martialarts"); foreach (MartialArt objArt in _objCharacter.MartialArts) { // <martialart> objWriter.WriteStartElement("martialart"); objWriter.WriteElementString("name", objArt.Name); if (objArt.Techniques.Count > 0) { // <techniques> objWriter.WriteStartElement("techniques"); foreach (MartialArtTechnique objTechnique in objArt.Techniques) { objWriter.WriteElementString("technique", objTechnique.Name); } // </techniques> objWriter.WriteEndElement(); } // </martialart> objWriter.WriteEndElement(); } // </martialarts> objWriter.WriteEndElement(); } // Export Spells. if (chkSpells.Checked) { // <spells> objWriter.WriteStartElement("spells"); foreach (Spell objSpell in _objCharacter.Spells) { objWriter.WriteStartElement("spell"); objWriter.WriteStartElement("name"); if (!string.IsNullOrEmpty(objSpell.Extra)) { objWriter.WriteAttributeString("select", objSpell.Extra); } objWriter.WriteValue(objSpell.Name); objWriter.WriteEndElement(); objWriter.WriteElementString("category", objSpell.Category); objWriter.WriteEndElement(); } // </spells> objWriter.WriteEndElement(); } // Export Complex Forms. if (chkComplexForms.Checked) { // <programs> objWriter.WriteStartElement("complexforms"); foreach (ComplexForm objComplexForm in _objCharacter.ComplexForms) { // <program> objWriter.WriteStartElement("complexform"); objWriter.WriteStartElement("name"); if (!string.IsNullOrEmpty(objComplexForm.Extra)) { objWriter.WriteAttributeString("select", objComplexForm.Extra); } objWriter.WriteValue(objComplexForm.Name); objWriter.WriteEndElement(); objWriter.WriteEndElement(); // </program> objWriter.WriteEndElement(); } // </programs> objWriter.WriteEndElement(); } // Export Cyberware/Bioware. if (chkCyberware.Checked) { bool blnCyberware = false; bool blnBioware = false; foreach (Cyberware objCharacterCyberware in _objCharacter.Cyberware) { switch (objCharacterCyberware.SourceType) { case Improvement.ImprovementSource.Bioware: blnBioware = true; break; case Improvement.ImprovementSource.Cyberware: blnCyberware = true; break; } if (blnCyberware && blnBioware) { break; } } if (blnCyberware) { // <cyberwares> objWriter.WriteStartElement("cyberwares"); foreach (Cyberware objCyberware in _objCharacter.Cyberware) { if (objCyberware.SourceType == Improvement.ImprovementSource.Cyberware) { // <cyberware> objWriter.WriteStartElement("cyberware"); objWriter.WriteElementString("name", objCyberware.Name); if (objCyberware.Rating > 0) { objWriter.WriteElementString("rating", objCyberware.Rating.ToString(GlobalSettings.InvariantCultureInfo)); } objWriter.WriteElementString("grade", objCyberware.Grade.Name); if (objCyberware.Children.Count > 0) { // <cyberwares> objWriter.WriteStartElement("cyberwares"); foreach (Cyberware objChildCyberware in objCyberware.Children) { if (objChildCyberware.Capacity != "[*]") { // <cyberware> objWriter.WriteStartElement("cyberware"); objWriter.WriteElementString("name", objChildCyberware.Name); if (objChildCyberware.Rating > 0) { objWriter.WriteElementString("rating", objChildCyberware.Rating.ToString(GlobalSettings.InvariantCultureInfo)); } if (objChildCyberware.GearChildren.Count > 0) { WriteGear(objWriter, objChildCyberware.GearChildren); } // </cyberware> objWriter.WriteEndElement(); } } // </cyberwares> objWriter.WriteEndElement(); } if (objCyberware.GearChildren.Count > 0) { WriteGear(objWriter, objCyberware.GearChildren); } // </cyberware> objWriter.WriteEndElement(); } } // </cyberwares> objWriter.WriteEndElement(); } if (blnBioware) { // <biowares> objWriter.WriteStartElement("biowares"); foreach (Cyberware objCyberware in _objCharacter.Cyberware) { if (objCyberware.SourceType == Improvement.ImprovementSource.Bioware) { // <bioware> objWriter.WriteStartElement("bioware"); objWriter.WriteElementString("name", objCyberware.Name); if (objCyberware.Rating > 0) { objWriter.WriteElementString("rating", objCyberware.Rating.ToString(GlobalSettings.InvariantCultureInfo)); } objWriter.WriteElementString("grade", objCyberware.Grade.ToString()); if (objCyberware.GearChildren.Count > 0) { WriteGear(objWriter, objCyberware.GearChildren); } // </bioware> objWriter.WriteEndElement(); } } // </biowares> objWriter.WriteEndElement(); } } // Export Lifestyle. if (chkLifestyle.Checked) { // <lifestyles> objWriter.WriteStartElement("lifestyles"); foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles) { // <lifestyle> objWriter.WriteStartElement("lifestyle"); objWriter.WriteElementString("name", objLifestyle.Name); objWriter.WriteElementString("months", objLifestyle.Increments.ToString(GlobalSettings.InvariantCultureInfo)); if (!string.IsNullOrEmpty(objLifestyle.BaseLifestyle)) { // This is an Advanced Lifestyle, so write out its properties. objWriter.WriteElementString("cost", objLifestyle.Cost.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo)); objWriter.WriteElementString("dice", objLifestyle.Dice.ToString(GlobalSettings.InvariantCultureInfo)); objWriter.WriteElementString("multiplier", objLifestyle.Multiplier.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo)); objWriter.WriteElementString("baselifestyle", objLifestyle.BaseLifestyle); if (objLifestyle.LifestyleQualities.Count > 0) { // <qualities> objWriter.WriteStartElement("qualities"); foreach (LifestyleQuality objQuality in objLifestyle.LifestyleQualities) { objWriter.WriteElementString("quality", objQuality.Name); } // </qualities> objWriter.WriteEndElement(); } } // </lifestyle> objWriter.WriteEndElement(); } // </lifestyles> objWriter.WriteEndElement(); } // Export Armor. if (chkArmor.Checked) { // <armors> objWriter.WriteStartElement("armors"); foreach (Armor objArmor in _objCharacter.Armor) { // <armor> objWriter.WriteStartElement("armor"); objWriter.WriteElementString("name", objArmor.Name); if (objArmor.ArmorMods.Count > 0) { // <mods> objWriter.WriteStartElement("mods"); foreach (ArmorMod objMod in objArmor.ArmorMods) { // <mod> objWriter.WriteStartElement("mod"); objWriter.WriteElementString("name", objMod.Name); if (objMod.Rating > 0) { objWriter.WriteElementString("rating", objMod.Rating.ToString(GlobalSettings.InvariantCultureInfo)); } // </mod> objWriter.WriteEndElement(); } // </mods> objWriter.WriteEndElement(); } if (objArmor.GearChildren.Count > 0) { WriteGear(objWriter, objArmor.GearChildren); } // </armor> objWriter.WriteEndElement(); } // </armors> objWriter.WriteEndElement(); } // Export Weapons. if (chkWeapons.Checked) { // <weapons> objWriter.WriteStartElement("weapons"); foreach (Weapon objWeapon in _objCharacter.Weapons) { // Don't attempt to export Cyberware and Gear Weapons since those are handled by those object types. The default Unarmed Attack Weapon should also not be exported. if (objWeapon.Category != "Cyberware" && objWeapon.Category != "Gear" && objWeapon.Name != "Unarmed Attack") { // <weapon> objWriter.WriteStartElement("weapon"); objWriter.WriteElementString("name", objWeapon.Name); // Weapon Accessories. if (objWeapon.WeaponAccessories.Count > 0) { // <accessories> objWriter.WriteStartElement("accessories"); foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories) { // Don't attempt to export items included in the Weapon. if (!objAccessory.IncludedInWeapon) { // <accessory> objWriter.WriteStartElement("accessory"); objWriter.WriteElementString("name", objAccessory.Name); objWriter.WriteElementString("mount", objAccessory.Mount); objWriter.WriteElementString("extramount", objAccessory.ExtraMount); if (objAccessory.GearChildren.Count > 0) { WriteGear(objWriter, objAccessory.GearChildren); } // </accessory> objWriter.WriteEndElement(); } } // </accessories> objWriter.WriteEndElement(); } // Underbarrel Weapon. if (objWeapon.UnderbarrelWeapons.Count > 0) { foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons) { if (!objUnderbarrelWeapon.IncludedInWeapon) { objWriter.WriteElementString("underbarrel", objUnderbarrelWeapon.Name); } } } // </weapon> objWriter.WriteEndElement(); } } // </weapons> objWriter.WriteEndElement(); } // Export Gear. if (chkGear.Checked) { WriteGear(objWriter, _objCharacter.Gear); } // Export Vehicles. if (chkVehicles.Checked) { // <vehicles> objWriter.WriteStartElement("vehicles"); foreach (Vehicle objVehicle in _objCharacter.Vehicles) { bool blnWeapons = false; // <vehicle> objWriter.WriteStartElement("vehicle"); objWriter.WriteElementString("name", objVehicle.Name); if (objVehicle.Mods.Count > 0) { // <mods> objWriter.WriteStartElement("mods"); foreach (VehicleMod objVehicleMod in objVehicle.Mods) { // Only write out the Mods that are not part of the base vehicle. if (!objVehicleMod.IncludedInVehicle) { // <mod> objWriter.WriteStartElement("mod"); objWriter.WriteElementString("name", objVehicleMod.Name); if (objVehicleMod.Rating > 0) { objWriter.WriteElementString("rating", objVehicleMod.Rating.ToString(GlobalSettings.InvariantCultureInfo)); } // </mod> objWriter.WriteEndElement(); // See if this is a Weapon Mount with Weapons. if (objVehicleMod.Weapons.Count > 0) { blnWeapons = true; } } else { // See if this is a Weapon Mount with Weapons. if (objVehicleMod.Weapons.Count > 0) { blnWeapons = true; } } } // </mods> objWriter.WriteEndElement(); } // If there are Weapons, add them. if (blnWeapons) { // <weapons> objWriter.WriteStartElement("weapons"); foreach (VehicleMod objVehicleMod in objVehicle.Mods) { foreach (Weapon objWeapon in objVehicleMod.Weapons) { // <weapon> objWriter.WriteStartElement("weapon"); objWriter.WriteElementString("name", objWeapon.Name); // Weapon Accessories. if (objWeapon.WeaponAccessories.Count > 0) { // <accessories> objWriter.WriteStartElement("accessories"); foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories) { // Don't attempt to export items included in the Weapon. if (!objAccessory.IncludedInWeapon) { // <accessory> objWriter.WriteStartElement("accessory"); objWriter.WriteElementString("name", objAccessory.Name); objWriter.WriteElementString("mount", objAccessory.Mount); objWriter.WriteElementString("extramount", objAccessory.ExtraMount); // </accessory> objWriter.WriteEndElement(); } } // </accessories> objWriter.WriteEndElement(); } // Underbarrel Weapon. if (objWeapon.UnderbarrelWeapons.Count > 0) { foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons) { objWriter.WriteElementString("underbarrel", objUnderbarrelWeapon.Name); } } // </weapon> objWriter.WriteEndElement(); } } // </weapons> objWriter.WriteEndElement(); } // Gear. if (objVehicle.GearChildren.Count > 0) { WriteGear(objWriter, objVehicle.GearChildren); } // </vehicle> objWriter.WriteEndElement(); } // </vehicles> objWriter.WriteEndElement(); } // </pack> objWriter.WriteEndElement(); // </packs> objWriter.WriteEndElement(); // </chummer> objWriter.WriteEndElement(); objWriter.WriteEndDocument(); } } Program.MainForm.ShowMessageBox(this, string.Format(GlobalSettings.CultureInfo, LanguageManager.GetString("Message_CreatePACKSKit_SuiteCreated"), txtName.Text), LanguageManager.GetString("MessageTitle_CreatePACKSKit_SuiteCreated"), MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; }
private void frmMasterIndex_Load(object sender, EventArgs e) { using (var op_load_frm_masterindex = Timekeeper.StartSyncron("op_load_frm_masterindex", null, CustomActivity.OperationType.RequestOperation, null)) { HashSet <string> setValidCodes = new HashSet <string>(); XmlNodeList lstBookNodes = XmlManager.Load("books.xml").SelectNodes("/chummer/books/book/code"); if (lstBookNodes?.Count > 0) { foreach (XmlNode xmlBookNode in lstBookNodes) { setValidCodes.Add(xmlBookNode.InnerText); } } string strSourceFilter = setValidCodes.Count > 0 ? new StringBuilder("(") .AppendJoin(" or ", setValidCodes.Select(x => "source = \'" + x + "\'")) .Append(')').ToString() : "source"; ConcurrentBag <ListItem> lstItemsForLoading = new ConcurrentBag <ListItem>(); ConcurrentBag <ListItem> lstFileNamesWithItemsForLoading = new ConcurrentBag <ListItem>(); using (_ = Timekeeper.StartSyncron("load_frm_masterindex_load_entries", op_load_frm_masterindex)) { Parallel.ForEach(_lstFileNames, strFileName => { XPathNavigator xmlBaseNode = XmlManager.LoadXPath(strFileName).CreateNavigator().SelectSingleNode("/chummer"); if (xmlBaseNode != null) { bool blnLoopFileNameHasItems = false; foreach (XPathNavigator xmlItemNode in xmlBaseNode.Select(".//*[page and " + strSourceFilter + ']')) { blnLoopFileNameHasItems = true; string strName = xmlItemNode.SelectSingleNode("name")?.Value; string strDisplayName = xmlItemNode.SelectSingleNode("translate")?.Value ?? strName ?? xmlItemNode.SelectSingleNode("id")?.Value ?? LanguageManager.GetString("String_Unknown"); string strSource = xmlItemNode.SelectSingleNode("source")?.Value; string strPage = xmlItemNode.SelectSingleNode("page")?.Value; string strDisplayPage = xmlItemNode.SelectSingleNode("altpage")?.Value ?? strPage; string strEnglishNameOnPage = xmlItemNode.SelectSingleNode("nameonpage")?.Value ?? strName; string strTranslatedNameOnPage = xmlItemNode.SelectSingleNode("altnameonpage")?.Value ?? strDisplayName; string strNotes = xmlItemNode.SelectSingleNode("altnotes")?.Value ?? xmlItemNode.SelectSingleNode("notes")?.Value; MasterIndexEntry objEntry = new MasterIndexEntry( strDisplayName, strFileName, new SourceString(strSource, strPage, GlobalOptions.DefaultLanguage, GlobalOptions.InvariantCultureInfo), new SourceString(strSource, strDisplayPage, GlobalOptions.Language, GlobalOptions.CultureInfo), strEnglishNameOnPage, strTranslatedNameOnPage); lstItemsForLoading.Add(new ListItem(objEntry, strDisplayName)); if (!string.IsNullOrEmpty(strNotes)) { _dicCachedNotes.TryAdd(objEntry, strNotes); } } if (blnLoopFileNameHasItems) { lstFileNamesWithItemsForLoading.Add(new ListItem(strFileName, strFileName)); } } }); } using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_entries", op_load_frm_masterindex)) { string strSpace = LanguageManager.GetString("String_Space"); Dictionary <string, List <ListItem> > dicHelper = new Dictionary <string, List <ListItem> >(lstItemsForLoading.Count); foreach (ListItem objItem in lstItemsForLoading) { MasterIndexEntry objEntry = (MasterIndexEntry)objItem.Value; string strKey = objEntry.DisplayName.ToUpperInvariant(); if (dicHelper.TryGetValue(strKey, out List <ListItem> lstExistingItems)) { ListItem objExistingItem = lstExistingItems.FirstOrDefault(x => objEntry.DisplaySource.Equals(((MasterIndexEntry)x.Value).DisplaySource)); if (objExistingItem.Value != null) { ((MasterIndexEntry)objExistingItem.Value).FileNames.UnionWith(objEntry.FileNames); } else { List <ListItem> lstItemsNeedingNameChanges = lstExistingItems.Where(x => !objEntry.FileNames.IsSubsetOf(((MasterIndexEntry)x.Value).FileNames)).ToList(); if (lstItemsNeedingNameChanges.Count == 0) { _lstItems.Add(objItem); // Not using AddRange because of potential memory issues lstExistingItems.Add(objItem); } else { ListItem objItemToAdd = new ListItem(objItem.Value, new StringBuilder(objItem.Name) .Append(strSpace).Append('[').AppendJoin(',' + strSpace, objEntry.FileNames).Append(']').ToString()); _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues lstExistingItems.Add(objItemToAdd); foreach (ListItem objToRename in lstItemsNeedingNameChanges) { _lstItems.Remove(objToRename); lstExistingItems.Remove(objToRename); MasterIndexEntry objExistingEntry = (MasterIndexEntry)objToRename.Value; objItemToAdd = new ListItem(objToRename.Value, new StringBuilder(objExistingEntry.DisplayName) .Append(strSpace).Append('[').AppendJoin(',' + strSpace, objExistingEntry.FileNames).Append(']').ToString()); _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues lstExistingItems.Add(objItemToAdd); } } } } else { _lstItems.Add(objItem); // Not using AddRange because of potential memory issues dicHelper.Add(strKey, new List <ListItem>(objItem.Yield())); } } _lstFileNamesWithItems.AddRange(lstFileNamesWithItemsForLoading); } using (_ = Timekeeper.StartSyncron("load_frm_masterindex_sort_entries", op_load_frm_masterindex)) { _lstItems.Sort(CompareListItems.CompareNames); _lstFileNamesWithItems.Sort(CompareListItems.CompareNames); } using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_controls", op_load_frm_masterindex)) { _lstFileNamesWithItems.Insert(0, new ListItem(string.Empty, LanguageManager.GetString("String_All"))); cboFile.BeginUpdate(); cboFile.ValueMember = nameof(ListItem.Value); cboFile.DisplayMember = nameof(ListItem.Name); cboFile.DataSource = _lstFileNamesWithItems; cboFile.SelectedIndex = 0; cboFile.EndUpdate(); lstItems.BeginUpdate(); lstItems.ValueMember = nameof(ListItem.Value); lstItems.DisplayMember = nameof(ListItem.Name); lstItems.DataSource = _lstItems; lstItems.SelectedIndex = -1; lstItems.EndUpdate(); _blnSkipRefresh = false; } } }