private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { try { if (saveFileDialog1.ShowDialog(this) == DialogResult.OK) { ImportExport.IExport exporter; string filename = saveFileDialog1.FileName; string extension = Path.GetExtension(filename).ToLower(); if ((saveFileDialog1.FilterIndex == 1 || extension == ".package") && !(extension == ".csv" || extension == ".txt")) { exporter = new ImportExport.ExportPackage(); } else { exporter = new ImportExport.ExportCSV(); } exporter.STBLData = mStubbleEntries; if (exporter.Export(this, filename)) { mCurFilename = filename; mCurExporter = exporter; Text = "Stubble String Table Editor - " + filename; dataGridView1.Invalidate(); } } } catch (Exception ex) { MessageBox.Show(this, "Error saving\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); } }