private DialogResult SaveFile(bool saveAs = false) { DialogResult dr = DialogResult.OK; if (_msbt.File == null || saveAs) { sfdSaveEntity.InitialDirectory = Settings.Default.InitialDirectory; dr = sfdSaveEntity.ShowDialog(); } if ((_msbt.File == null || saveAs) && dr == DialogResult.OK) { _msbt.File = new FileInfo(sfdSaveEntity.FileName); Settings.Default.InitialDirectory = new FileInfo(sfdSaveEntity.FileName).DirectoryName; Settings.Default.Save(); Settings.Default.Reload(); } if (dr == DialogResult.OK) { _msbt.Save(); _hasChanges = false; UpdateTextView(); UpdateOriginalText(); UpdateTextPreview(); UpdateHexView(); UpdateForm(); } slbActions.Text = "Successfully saved " + FileName(); return(dr); }
private void batchImportXMSBTToolStripMenuItem_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Select a directory containing MSBT and XMSBT files of the same name:"; fbd.ShowNewFolderButton = false; fbd.SelectedPath = Settings.Default.XMSBTDirectory; if (fbd.ShowDialog() == DialogResult.OK) { Settings.Default.XMSBTDirectory = fbd.SelectedPath; if (Directory.Exists(fbd.SelectedPath)) { DirectoryInfo dir = new DirectoryInfo(fbd.SelectedPath); FileInfo[] msbtFiles = dir.GetFiles("*.msbt"); FileInfo[] xmsbtFiles = dir.GetFiles("*.xmsbt"); string result = ""; bool addLabels = MessageBox.Show("Add labels in the XMSBT files that don't exist in the MSBT files?", "Add Labels?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; Dictionary <string, FileInfo> matches = new Dictionary <string, FileInfo>(); foreach (FileInfo file in msbtFiles) { string name = file.FullName.Substring(0, file.FullName.Length - 4); foreach (FileInfo xFile in xmsbtFiles) { if (name == xFile.FullName.Substring(0, xFile.FullName.Length - 5)) { matches.Add(name, file); break; } } } if (matches.Count > 0) { foreach (string file in matches.Keys) { try { MSBT msbt = new MSBT(matches[file].FullName); msbt.ImportXMSBT(matches[file].FullName.Substring(0, matches[file].FullName.Length - 4) + "xmsbt", addLabels); msbt.Save(); } catch (Exception ex) { result = ex.Message; } } if (result.Length == 0) { result = "Successfully batch imported from XMSBT."; } } else { result = "There are no MSBT files that match an XMSBT file in the selected directory."; } MessageBox.Show(result, "XMSBT Batch Import Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } } Settings.Default.Save(); Settings.Default.Reload(); }