示例#1
0
        public void Export(string filename, Languages lang)
        {
            StringBuilder line = new StringBuilder();

            System.IO.StreamWriter writer = new System.IO.StreamWriter(filename, false, Encoding.UTF8);
            bool quotestrings             = quoteStrings.Checked;
            bool quoteall = quoteAll.Checked;
            bool nonames  = idNumber.Checked;
            bool barehex  = hexNums.Checked;
            char seperator;

            if (tabDelim.Checked || textBox2.Text.Length < 1)
            {
                seperator = '\t';
            }
            else
            {
                seperator = textBox2.Text[0];
            }
            using (writer)
            {
                foreach (KeyValuePair <UInt64, string> entry in mData.GetEntriesForLanguage(lang, STBLVault.StringSource.Loaded | STBLVault.StringSource.Modified))
                {
                    bool   keydone = false;
                    string keyname;
                    if (!nonames && STBLVault.LookupKey(entry.Key, out keyname))
                    {
                        if (keyname.IndexOf(seperator) < 0 && keyname.IndexOf('\n') < 0)
                        {
                            if (quotestrings)
                            {
                                writer.Write('"');
                                QuoteString(writer, keyname);
                                writer.Write('"');
                            }
                            else
                            {
                                writer.Write(keyname);
                            }
                            keydone = true;
                        }
                    }
                    if (!keydone)
                    {
                        if (quoteall)
                        {
                            writer.Write('"');
                        }
                        if (!barehex)
                        {
                            writer.Write("0x");
                        }
                        writer.Write(entry.Key.ToString("X16"));
                        if (quoteall)
                        {
                            writer.Write('"');
                        }
                    }
                    writer.Write(seperator);
                    if (quotestrings)
                    {
                        writer.Write('"');
                        QuoteString(writer, entry.Value);
                        writer.WriteLine('"');
                    }
                    else
                    {
                        NonQuoteString(writer, entry.Value);
                        writer.WriteLine();
                    }
                }
            }
        }
        private void GatherSaveData(DBPFFile dbfile, Dictionary <DBPFReference, KeyValuePair <DBPFIndexEntry, byte[]> > toreplace, List <KeyValuePair <DBPFIndexEntry, byte[]> > toadd)
        {
            STBLWriter copysource = null;

            // Copy the reference language entries
            if (checkBox2.Checked)
            {
                copysource = new STBLWriter();
                foreach (KeyValuePair <UInt64, string> entry in mData.GetEntriesForLanguage((Languages)comboBox1.Items[comboBox1.SelectedIndex], STBLVault.StringSource.Modified | STBLVault.StringSource.Loaded))
                {
                    copysource.Add(entry.Key, entry.Value);
                }
            }

            for (int loop = 0; loop < (int)Languages.Language_Count; loop++)
            {
                // Skip languages there is nothing to write for
                if (!mData.HasEntriesForLanguage((Languages)loop, STBLVault.StringSource.Loaded | STBLVault.StringSource.Modified) &&
                    copysource == null)
                {
                    continue;
                }

                STBLWriter newentry;
                if (copysource != null)
                {
                    newentry = copysource.Copy();
                }
                else
                {
                    newentry = new STBLWriter();
                }
                newentry.Instance = mInstance;
                newentry.Language = (Languages)loop;

                // Overwrite or underwrite the user defined entries
                if (copysource != null && checkBox1.Checked)
                {
                    foreach (KeyValuePair <UInt64, string> entry in mData.GetEntriesForLanguage((Languages)loop, STBLVault.StringSource.Modified | STBLVault.StringSource.Loaded))
                    {
                        newentry.AddIfNotExists(entry.Key, entry.Value);
                    }
                }
                else
                {
                    foreach (KeyValuePair <UInt64, string> entry in mData.GetEntriesForLanguage((Languages)loop, STBLVault.StringSource.Modified | STBLVault.StringSource.Loaded))
                    {
                        newentry.Add(entry.Key, entry.Value);
                    }
                }

                // Load in the existing entry if requested
                if (radioButton2.Checked)
                {
                    DBPFReference oldref = new DBPFReference(0x220557DA, 0, mInstance | ((UInt64)loop << 56));
                    if (dbfile.Index.ContainsKey(oldref))
                    {
                        DBPFDataStream oldfile = dbfile.Open(oldref);
                        using (oldfile)
                        {
                            oldfile.GetData();
                            if (checkBox3.Checked)
                            {
                                // Merge overwriting old with new
                                foreach (KeyValuePair <UInt64, string> oldentry in STBLVault.GetDictionaryLoader(oldfile))
                                {
                                    newentry.AddIfNotExists(oldentry.Key, oldentry.Value);
                                }
                            }
                            else
                            {
                                // Merge overwriting new with old
                                foreach (KeyValuePair <UInt64, string> oldentry in STBLVault.GetDictionaryLoader(oldfile))
                                {
                                    newentry.Add(oldentry.Key, oldentry.Value);
                                }
                            }
                        }
                    }
                }

                // Create the STBL format data blob
                KeyValuePair <DBPFIndexEntry, byte[]> dbentry = newentry.Export();
                if (dbfile.Index.ContainsKey(dbentry.Key.Reference))
                {
                    toreplace[dbentry.Key.Reference] = dbentry;
                }
                else
                {
                    toadd.Add(dbentry);
                }
            }
        }