Example #1
0
        private void importXMSBTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title            = "Select an XMSBT File...";
            ofd.Filter           = "XMSBT (*.xmsbt)|*.xmsbt";
            ofd.InitialDirectory = Settings.Default.XMSBTDirectory;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Settings.Default.XMSBTDirectory = new FileInfo(ofd.FileName).DirectoryName;

                if (File.Exists(ofd.FileName))
                {
                    bool addLabels = MessageBox.Show("Add labels in the XMSBT that don't exist in the MSBT file?", "Add Labels?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;

                    string result = _msbt.ImportXMSBT(ofd.FileName, addLabels);

                    MessageBox.Show(result, "XMSBT Import Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            LoadFile();

            Settings.Default.Save();
            Settings.Default.Reload();
        }
Example #2
0
        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();
        }