// Sort by org and service name public static MappingFile SortMappingFile(this MappingFile mappingFile) { Guard.ArgumentNotNull(mappingFile, nameof(mappingFile)); Guard.ArgumentNotNull(mappingFile.OrganizationInfos, nameof(mappingFile.OrganizationInfos)); mappingFile.OrganizationInfos.Sort((x, y) => string.CompareOrdinal(x.OrganizationName, y.OrganizationName)); foreach (var organizationInfo in mappingFile.OrganizationInfos) { organizationInfo.Services?.Sort((x, y) => string.CompareOrdinal(x.TocTitle, y.TocTitle)); } return(mappingFile); }
private void Button_Save_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog(); openFile.Filter = @"XML Files|*.xml"; openFile.RestoreDirectory = true; openFile.CheckFileExists = false; openFile.ShowDialog(); if (string.IsNullOrEmpty(openFile.FileName)) { return; } MappingFile mFile = new MappingFile(); mFile.TableName = this._TableInfo.Name; mFile.Fields.AddRange(this._FieldInfos); File.WriteAllText(openFile.FileName, SerializeHelper.XmlSerializeObject <MappingFile>(mFile)); }
private void _loadDatButton_Click(object sender, RoutedEventArgs e) { // Show window (create new first, as closed windows cannot be reopened) _currentFileSelectionWindow = new FileSelectionWindow(); if (!(_currentFileSelectionWindow.ShowDialog() ?? false)) { return; } // Check whether genie file exists if (!File.Exists(_currentFileSelectionWindow.BaseGenieFilePath)) { // Error MessageBox.Show($"The given genie file path is invalid: '{_currentFileSelectionWindow.BaseGenieFilePath}'"); return; } // Catch errors _languageFiles = new List <string>(); try { // Find language files if (File.Exists(_currentFileSelectionWindow.LanguageX1P1DllFilePath)) { _languageFiles.Add(_currentFileSelectionWindow.LanguageX1P1DllFilePath); } if (File.Exists(_currentFileSelectionWindow.LanguageX1DllFilePath)) { _languageFiles.Add(_currentFileSelectionWindow.LanguageX1DllFilePath); } if (File.Exists(_currentFileSelectionWindow.LanguageDllFilePath)) { _languageFiles.Add(_currentFileSelectionWindow.LanguageDllFilePath); } // Load genie file _genieFile = new GenieLibrary.GenieFile(GenieLibrary.GenieFile.DecompressData(new IORAMHelper.RAMBuffer(_currentFileSelectionWindow.BaseGenieFilePath))); } catch (IOException ex) { // Error MessageBox.Show($"Unable to load given genie file: {ex.Message}"); return; } // Check for mapping requirement _mappingFile = null; if (!string.IsNullOrWhiteSpace(_currentFileSelectionWindow.MappingFilePath) && File.Exists(_currentFileSelectionWindow.MappingFilePath)) { // Read mapping _mappingFile = new MappingFile(new IORAMHelper.RAMBuffer(_currentFileSelectionWindow.MappingFilePath)); if (!_mappingFile.CheckCompabilityToGenieFile(_genieFile)) { MessageBox.Show($"The given mapping file does not match the given DAT file."); } } else if (_genieFile.Researches.Exists(r => r.Name.StartsWith("#BDep"))) { MessageBox.Show($"This file was probably created using an editor that dynamically reassigns unit and research IDs.\nIt is strongly recommended to reload using a valid mapping file."); } // Create balancing data object BalancingFile = new BalancingFile(_genieFile, _languageFiles.ToArray(), _mappingFile); _balancingFilePath = ""; // Set filterable lists UnitEntryList = new GenericCollectionView <KeyValuePair <short, UnitEntry> >(CollectionViewSource.GetDefaultView(_balancingFile.UnitEntries)); OnPropertyChanged(nameof(UnitEntryList)); // Update child windows if (_projectileWindow != null) { _projectileWindow.GenieFile = _genieFile; } // Reset window title CurrentWindowTitle = WindowTitlePrefix; // Enable UI controls EnableEditorPanel = true; }
private void Button_Load_Click(object sender, RoutedEventArgs e) { #region Check if Table and Sheet has been selected first. if (this._TableInfo == null) { MessageBox.Show("Please select a Table from the dropdownlist."); return; } if (this._SheetInfo == null) { MessageBox.Show("Please select a sheet in an excel file."); return; } #endregion #region Select the mapping file and read it MappingFile mFileData = null; System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog(); openFile.Filter = @"XML Files|*.xml"; openFile.RestoreDirectory = true; openFile.ShowDialog(); if (File.Exists(openFile.FileName)) { try { string xml = File.ReadAllText(openFile.FileName); mFileData = SerializeHelper.XmlDeserializeObject <MappingFile>(xml); } catch (Exception ex) { MessageBox.Show("DEBUG: " + ex.Message); mFileData = null; } } else { mFileData = null; } #endregion #region Rebuild the list of FieldInfos with the data in the mapping file if (mFileData != null) { if (String.Compare(this._TableInfo.Name, mFileData.TableName, true) != 0) { MessageBox.Show("The mapping file is configured for Table: " + mFileData.TableName + ", not for the selected one: " + this._TableInfo.Name); } else { this._FieldInfos = this._TableInfo.GetFieldInfos(); foreach (FieldInfo fieldInfo in _FieldInfos) { FieldInfo mappingField = mFileData.GetFieldInfo(fieldInfo.Name); if (mappingField != null) { fieldInfo.DefaultValue = mappingField.DefaultValue; fieldInfo.ExcelColumnIndex = mappingField.ExcelColumnIndex.HasValue ? mappingField.ExcelColumnIndex.Value > 0 ? mappingField.ExcelColumnIndex : null : null; fieldInfo.FunctionIDs = mappingField.FunctionIDs; fieldInfo.FunctionArgs = mappingField.FunctionArgs; fieldInfo.IsUnique = mappingField.IsUnique; } } } } #endregion #region Refresh the DataGrid_Fields DataGrid_Fields.ItemsSource = this._FieldInfos; #endregion }