コード例 #1
0
ファイル: MetaData.cs プロジェクト: NeonOcean/STBLXMLEditor
        public MetaData(STBLXMLFile stblFile = null)
        {
            if (stblFile != null)
            {
                STBLFile = stblFile;
            }

            InitializeComponent();

            Forms.SetupLanguageComboBox(FallbackLanguageSelector, STBL.GetLanguage(STBLFile.FallbackLanguage));

            LastSTBLGroupValue               = STBLFile.STBLGroup;
            STBLGroupDecimalTextBox.Text     = STBLFile.STBLGroup.ToString("0");
            STBLGroupHexadecimalTextBox.Text = STBLFile.STBLGroup.ToString("x").ToUpper();

            LastSTBLInstanceValue               = STBLFile.STBLInstance;
            STBLInstanceDecimalTextBox.Text     = STBLFile.STBLInstance.ToString("0");
            STBLInstanceHexadecimalTextBox.Text = STBLFile.STBLInstance.ToString("x").ToUpper();

            STBLNameTextBox.Text = STBLFile.STBLName;

            if (STBLFile.STBLName == "")
            {
                UpdateSTBLNameTextBoxColors(STBLNameTextBox);
            }

            BuildIdentifiersCheckBox.Checked = STBLFile.BuildIdentifiers;

            LastIdentifiersGroupValue               = STBLFile.IdentifiersGroup;
            IdentifiersGroupDecimalTextBox.Text     = STBLFile.IdentifiersGroup.ToString("0");
            IdentifiersGroupHexadecimalTextBox.Text = STBLFile.IdentifiersGroup.ToString("x").ToUpper();

            LastIdentifiersInstanceValue               = STBLFile.IdentifiersInstance;
            IdentifiersInstanceDecimalTextBox.Text     = STBLFile.IdentifiersInstance.ToString("0");
            IdentifiersInstanceHexadecimalTextBox.Text = STBLFile.IdentifiersInstance.ToString("x").ToUpper();

            IdentifiersNameTextBox.Text = STBLFile.IdentifiersName;
        }
コード例 #2
0
        public static void ExportToPackageFiles(STBLXMLFile exportingFile, string exportDirectoryPath, bool buildSourceInfoFiles)
        {
            Directory.CreateDirectory(exportDirectoryPath);

            STBL.Languages fallbackLanguage = STBL.GetLanguage(exportingFile.FallbackLanguage);

            foreach (STBL.Languages language in STBL.GetAllLanguages())
            {
                string languageFileName = string.Format(exportingFile.STBLName, new STBL.LanguageFileName(language));

                string stblFileName = languageFileName + "." + STBLFileExtension;
                string stblFilePath = Path.Combine(exportDirectoryPath, stblFileName);

                using (BinaryWriter exportFileWriter = new BinaryWriter(new FileStream(stblFilePath, FileMode.Create))) {
                    string[] texts           = new string[exportingFile.Entries.Count];
                    ushort[] textsByteCounts = new ushort[exportingFile.Entries.Count];
                    uint     entryByteCount  = 0;

                    for (int entryIndex = 0; entryIndex < exportingFile.Entries.Count; entryIndex++)
                    {
                        string entryLanguageText = exportingFile.Entries[entryIndex].GetText(language);

                        if (entryLanguageText == null)
                        {
                            entryLanguageText = exportingFile.Entries[entryIndex].GetText(fallbackLanguage);
                        }

                        if (entryLanguageText == null)
                        {
                            entryLanguageText = exportingFile.Entries[entryIndex].Identifier;
                        }

                        texts[entryIndex] = entryLanguageText;

                        textsByteCounts[entryIndex] = (ushort)Encoding.UTF8.GetByteCount(texts[entryIndex]);
                        entryByteCount += textsByteCounts[entryIndex] + 1u;
                    }

                    exportFileWriter.Write(Encoding.UTF8.GetBytes("STBL"));
                    exportFileWriter.Write((byte)5);
                    exportFileWriter.Write((ushort)0);
                    exportFileWriter.Write((uint)exportingFile.Entries.Count);
                    exportFileWriter.Write(0u);
                    exportFileWriter.Write((ushort)0);
                    exportFileWriter.Write(entryByteCount);

                    for (int textsIndex = 0; textsIndex < exportingFile.Entries.Count; textsIndex++)
                    {
                        exportFileWriter.Write(exportingFile.Entries[textsIndex].Key);
                        exportFileWriter.Write((byte)0);
                        exportFileWriter.Write(textsByteCounts[textsIndex]);
                        exportFileWriter.Write(texts[textsIndex].ToCharArray());
                    }
                }

                if (buildSourceInfoFiles)
                {
                    string sourceInfoFilePath = stblFilePath + "." + SourceInfoFileExtension;

                    string languageInstanceHexadecimal = ((int)language).ToString("x2") + exportingFile.STBLInstance.ToString("x").Substring(2);
                    ulong  languageInstance            = ulong.Parse(languageInstanceHexadecimal, NumberStyles.HexNumber);

                    Tools.WriteXML(sourceInfoFilePath, new SourceInfo()
                    {
                        Name       = languageFileName,
                        TypeID     = 570775514,
                        GroupID    = exportingFile.STBLGroup,
                        InstanceID = languageInstance
                    });
                }
            }
        }
コード例 #3
0
        public Predicate <STBLXMLEntry> GetFilterPredicate()
        {
            string keyFilterLower = KeyFilter?.ToLower();

            Regex identifierFilterRegex = null;

            if (IdentifierFilterUseRegex)
            {
                identifierFilterRegex = new Regex(IdentifierFilter, RegexOptions.Multiline | (IdentifierFilterMatchCase ? RegexOptions.None : RegexOptions.IgnoreCase));
            }

            Regex textFilterRegex = null;

            if (TextFilterUseRegex)
            {
                textFilterRegex = new Regex(TextFilter, RegexOptions.Multiline | (TextFilterMatchCase ? RegexOptions.None : RegexOptions.IgnoreCase));
            }

            return(delegate(STBLXMLEntry entry) {
                if (KeyFilter != null)
                {
                    string itemKeyDecimal = entry.Key.ToString();
                    string itemKeyHexadecimal = "0x" + entry.Key.ToString("x");

                    if (!itemKeyDecimal.Contains(keyFilterLower) && !itemKeyHexadecimal.Contains(keyFilterLower))
                    {
                        return true;
                    }
                }

                if (IdentifierFilter != null)
                {
                    if (!IdentifierFilterUseRegex || identifierFilterRegex == null)
                    {
                        if (entry.Identifier.IndexOf(IdentifierFilter, IdentifierFilterMatchCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) < 0)
                        {
                            return true;
                        }
                    }
                    else
                    {
                        if (!identifierFilterRegex.IsMatch(entry.Identifier))
                        {
                            return true;
                        }
                    }
                }

                if (TextFilter != null)
                {
                    foreach (STBL.Languages languague in STBL.GetAllLanguages())
                    {
                        string languageText = entry.GetText(languague);

                        if (languageText == null)
                        {
                            continue;
                        }

                        if (!TextFilterUseRegex || textFilterRegex == null)
                        {
                            if (languageText.IndexOf(TextFilter, TextFilterMatchCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) < 0)
                            {
                                return true;
                            }
                        }
                        else
                        {
                            if (!textFilterRegex.IsMatch(languageText))
                            {
                                return true;
                            }
                        }
                    }
                }


                if (UntranslatedFilter != null)
                {
                    try {
                        STBL.Languages untranslatedFilterLanguague = STBL.GetLanguage((int)UntranslatedFilter);

                        if (entry.GetText(untranslatedFilterLanguague) != null)
                        {
                            return true;
                        }
                    } catch { }
                }

                return false;
            });
        }