public void CommitModifiedData(Languages lang, StubbleSource source) { Dictionary <UInt64, StubbleEntry> entrylist; if (!mModifiedEntries.TryGetValue(lang, out entrylist)) { return; } Dictionary <UInt64, StubbleEntry> loadedlist; if (!mLoadedEntries.TryGetValue(lang, out loadedlist)) { loadedlist = new Dictionary <ulong, StubbleEntry>(); mLoadedEntries[lang] = loadedlist; } foreach (KeyValuePair <UInt64, StubbleEntry> entry in entrylist) { entry.Value.Source = source; loadedlist[entry.Key] = entry.Value; } mModifiedEntries.Remove(lang); }
public int LoadEntries(StringSource target, StubbleSource source, Languages lang, OverwriteMode overwrite, IEnumerable<KeyValuePair<UInt64, string>> entries) { if (source.SourceTable == DBPFReference.MinValue && overwrite != OverwriteMode.All && overwrite != OverwriteMode.None) throw new InvalidOperationException(); Dictionary<UInt64, StubbleEntry> targetlist; if (target == StringSource.Modified) { if (!mModifiedEntries.TryGetValue(lang, out targetlist)) { targetlist = new Dictionary<ulong, StubbleEntry>(); mModifiedEntries[lang] = targetlist; } } else if (target == StringSource.Loaded) { if (!mLoadedEntries.TryGetValue(lang, out targetlist)) { targetlist = new Dictionary<ulong, StubbleEntry>(); mLoadedEntries[lang] = targetlist; } } else { throw new InvalidOperationException(); } int added = 0; foreach (KeyValuePair<UInt64, string> entry in entries) { if (overwrite != OverwriteMode.All) { StubbleEntry oldentry; if (targetlist.TryGetValue(entry.Key, out oldentry)) { if (overwrite == OverwriteMode.None) continue; if (overwrite == OverwriteMode.Priority) { if ((UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance) continue; } else { if (source.SourceTable != oldentry.Source.SourceTable && (UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance) continue; } } } StubbleEntry newentry = new StubbleEntry(); newentry.Value = entry.Value; newentry.Source = source; targetlist[entry.Key] = newentry; added++; } return added; }
public void CommitModifiedData(Languages lang, StubbleSource source) { Dictionary<UInt64, StubbleEntry> entrylist; if (!mModifiedEntries.TryGetValue(lang, out entrylist)) return; Dictionary<UInt64, StubbleEntry> loadedlist; if (!mLoadedEntries.TryGetValue(lang, out loadedlist)) { loadedlist = new Dictionary<ulong, StubbleEntry>(); mLoadedEntries[lang] = loadedlist; } foreach (KeyValuePair<UInt64, StubbleEntry> entry in entrylist) { entry.Value.Source = source; loadedlist[entry.Key] = entry.Value; } mModifiedEntries.Remove(lang); }
private void PerformLoad(bool asnewfile) { if (openFileDialog1.ShowDialog(this) != DialogResult.OK) return; int loaded = 0; bool cleared = !asnewfile; try { Stream stream = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); using (stream) { byte[] header = new byte[4]; stream.Read(header, 0, 4); stream.Position = 0; if (Encoding.ASCII.GetString(header) == "DBPF") { DBPFFile file = new DBPFFile(stream); using (file) { foreach (DBPFIndexEntry entry in file.Index) { if (entry.Reference.Type == 0x220557DA) { StubbleSource source = new StubbleSource(); source.SourceFile = openFileDialog1.FileName; source.SourceTable = entry.Reference; if (!cleared) { cleared = true; mStubbleEntries.ClearUserData(); mCurExporter = null; } DBPFDataStream filedata = file.Open(entry.Reference); using (filedata) { // Force file-at-once read filedata.GetData(); loaded += mStubbleEntries.LoadEntries(STBLVault.StringSource.Loaded, source, (Languages)(entry.Reference.Instance >> 56), STBLVault.OverwriteMode.PriorityOrEqual, STBLVault.GetDictionaryLoader(filedata)); } } } if (loaded == 0) { MessageBox.Show(this, "No STBL entries found", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (!unmodifiedStringsToolStripMenuItem.Checked) unmodifiedStringsToolStripMenuItem.Checked = true; else RepopulateTree(); } } else { ImportExport.ImportCSV importopts = new STBLBrowser.ImportExport.ImportCSV(); if (importopts.ShowDialog(this) == DialogResult.OK) { StubbleSource source = new StubbleSource(); source.SourceFile = openFileDialog1.FileName; loaded += mStubbleEntries.LoadEntries(STBLVault.StringSource.Loaded, source, importopts.ImportLanguage, STBLVault.OverwriteMode.All, importopts.ImportStrings(this, stream)); if (loaded == 0) { MessageBox.Show(this, "No STBL entries found", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } STBLVault.SyncKeyNameMap(); if (!unmodifiedStringsToolStripMenuItem.Checked) unmodifiedStringsToolStripMenuItem.Checked = true; else RepopulateTree(); } } } if (asnewfile) Text = "Stubble String Table Editor - " + openFileDialog1.FileName; } catch (Exception ex) { MessageBox.Show(this, string.Format("Error reading file: {0}", ex.Message), "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int LoadEntries(StringSource target, StubbleSource source, Languages lang, OverwriteMode overwrite, IEnumerable <KeyValuePair <UInt64, string> > entries) { if (source.SourceTable == DBPFReference.MinValue && overwrite != OverwriteMode.All && overwrite != OverwriteMode.None) { throw new InvalidOperationException(); } Dictionary <UInt64, StubbleEntry> targetlist; if (target == StringSource.Modified) { if (!mModifiedEntries.TryGetValue(lang, out targetlist)) { targetlist = new Dictionary <ulong, StubbleEntry>(); mModifiedEntries[lang] = targetlist; } } else if (target == StringSource.Loaded) { if (!mLoadedEntries.TryGetValue(lang, out targetlist)) { targetlist = new Dictionary <ulong, StubbleEntry>(); mLoadedEntries[lang] = targetlist; } } else { throw new InvalidOperationException(); } int added = 0; foreach (KeyValuePair <UInt64, string> entry in entries) { if (overwrite != OverwriteMode.All) { StubbleEntry oldentry; if (targetlist.TryGetValue(entry.Key, out oldentry)) { if (overwrite == OverwriteMode.None) { continue; } if (overwrite == OverwriteMode.Priority) { if ((UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance) { continue; } } else { if (source.SourceTable != oldentry.Source.SourceTable && (UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance) { continue; } } } } StubbleEntry newentry = new StubbleEntry(); newentry.Value = entry.Value; newentry.Source = source; targetlist[entry.Key] = newentry; added++; } return(added); }