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);
            }
        }
        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);
                }
            }
        }