Beispiel #1
0
        public async void UpdateStatus(string message = "Ready")
        {
            FormMethods.EnableCloseButton(this);
            switch (message)
            {
            case "Ready":
                if (OpenedFile.Initialized)
                {
                    if (File.Exists(OpenedFile.Info["Path"]))
                    {
                        slb_status.Text = OpenedFile.Metadata["Status"];
                    }
                    else
                    {
                        slb_status.Text = "Please check the path of " + OpenedFile.Info["NameShort_OnError"] + "!";
                    }
                    return;
                }
                slb_status.Text = message;
                break;

            case "Close":
                // The key won't be set if user tries to drag and drop
                // an invalid file while no other file is opened
                if (OpenedFile.Info.ContainsKey("NameShort"))
                {
                    slb_status.Text = "Closed the file: " + OpenedFile.Info["NameShort"];
                    await Task.Delay(2000);
                }

                // Another file might've been opened in the meantime when the previous file was closed
                // Was another file opened during the Task.Delay?
                if (OpenedFile.Initialized)
                {
                    slb_status.Text = "Opened the file: " + OpenedFile.Info["NameShort"];
                    return;
                }
                else
                {
                    slb_status.Text = "Ready";
                }
                break;

            default:
                slb_status.Text = message;
                break;
            }
        }
Beispiel #2
0
        private void FileDump(object sender, EventArgs e)
        {
            MainDump mainDump = new MainDump(OpenedFile.Info["Path"], lst_exportExtensions.SelectedItem.ToString().ToLower())
            {
                StartPosition = FormStartPosition.CenterParent,
                Text          = String.Format("Dump Info | {0}", Text)
            };

            mainDump.Size = (this.Width / 2 > 832 && this.Height / 2 > 538) ? new Size(this.Width / 2, 538) : new Size(this.Width, 538);
            mainDump.ShowDialog();

            if (mainDump.Confirmed)
            {
                UpdateStatus("Dumping info...");
                FormMethods.EnableCloseButton(this, false);
                Dictionary <string, Dictionary <string, object> > Options = mainDump.Options;

                try
                {
                    if ((bool)Options["DumpFileInfo"]["Use"])
                    {
                        string   path  = (string)Options["DumpFileInfo"]["FileLocation"];
                        string[] lines = OpenedFile.DumpInformation(Options);
                        File.WriteAllLines(path, lines);
                    }

                    if ((bool)Options["SaveExportInfo"]["Use"])
                    {
                        string path = (string)Options["SaveExportInfo"]["FileLocation"];
                        string line = OpenedFile.GenerateConversionParams(null, false, true);
                        File.WriteAllText(path, String.Format("{0}\r\n", line));
                    }
                }
                catch (Exception ex)
                {
                    UpdateStatus();
                    MessageBox.Show(ex.Message, "Error dumping file information | " + Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                UpdateStatus();
                MessageBox.Show("Info dumped successfully!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Beispiel #3
0
        private void FileExport(object sender, EventArgs e)
        {
            UpdateStatus("Converting the file...");

            // If the file was missing or inaccessible, but suddenly is, relock it again
            OpenedFile.Lock(true);

            if (OpenedFile.ExportInfo["ExtensionNoDot"] == null)
            {
                UpdateStatus();
                MessageBox.Show("Please select the exported file's extension!", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (OpenedFile.Info["ExtensionNoDot"] == OpenedFile.ExportInfo["ExtensionNoDot"])
            {
                DialogResult dialogResult = MessageBox.Show("The file you're trying to export has the same extension as the original file. Some of the changes might not be applied.\r\nContinue?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                if (dialogResult != DialogResult.Yes)
                {
                    UpdateStatus();
                    return;
                }
            }

            if (OpenedFile.ExportLoop["Enabled"] == 1)
            {
                if (OpenedFile.ExportInfo["ExtensionNoDot"] == "wav")
                {
                    // Encoding the loop information into the wave file
                    // is useful only for conversions done later on (to a format that supports it)
                    DialogResult dialogResult = MessageBox.Show("While the wave file can hold loop information, it won't be read by most media players.\r\nExport the loop information anyway?", Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    switch (dialogResult)
                    {
                    case DialogResult.Yes:
                        break;

                    case DialogResult.No:
                        chk_loop.Checked = false;
                        break;

                    case DialogResult.Cancel:
                    default:
                        UpdateStatus();
                        return;
                    }
                }
            }
            else
            {
                if (OpenedFile.ExportLoop["Enabled"] == 1)
                {
                    DialogResult dialogResult = MessageBox.Show("The imported file has loop information, which will be lost upon export.\r\nContinue the export without the loop information?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    if (dialogResult != DialogResult.Yes)
                    {
                        UpdateStatus();
                        return;
                    }
                }
            }

            // Select the save location
            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                InitialDirectory = Path.GetDirectoryName(OpenedFile.Info["Path"]),
                Title            = "Export " + OpenedFile.Info["NameNoExtension"] + "." + OpenedFile.ExportInfo["ExtensionNoDot"],
                CheckFileExists  = false,
                CheckPathExists  = true,
                DefaultExt       = OpenedFile.ExportInfo["ExtensionNoDot"],
                Filter           = OpenedFile.ExportInfo["ExtensionNoDot"].ToUpper() + " audio file (*." + OpenedFile.ExportInfo["ExtensionNoDot"] + ")|*." + OpenedFile.ExportInfo["ExtensionNoDot"],
                FilterIndex      = 1,
                RestoreDirectory = true
            };

            if (FeatureConfig["PrefillExportFileName"])
            {
                saveFileDialog.FileName = OpenedFile.Info["NameNoExtension"] + "." + OpenedFile.ExportInfo["ExtensionNoDot"];
            }

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                OpenedFile.ExportInfo["Path"]        = saveFileDialog.FileName;
                OpenedFile.ExportInfo["PathEscaped"] = String.Format("\"{0}\"", Path.GetFullPath(OpenedFile.ExportInfo["Path"]));
                FormMethods.EnableCloseButton(this, false);
                try
                {
                    if (OpenedFile.Convert())
                    {
                        UpdateStatus();
                        string successMessage = "Task performed successfully.";
                        if (FeatureConfig["ShowTimeElapsed"])
                        {
                            successMessage += String.Format(" Time elapsed: {0}", OpenedFile.ExportResult["TimeElapsed"]);
                        }
                        MessageBox.Show(successMessage, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    OpenedFile.Lock(true);
                    UpdateStatus();

                    string exceptionTitle = "Fatal Error";
                    if (ex is NotSupportedException)
                    {
                        exceptionTitle = "Conversion Error";
                    }
                    if (ex is ArgumentException)
                    {
                        exceptionTitle = "Error";
                    }
                    MessageBox.Show(ex.Message, String.Format("{0} | {1}", exceptionTitle, Text), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    FormMethods.EnableCloseButton(this);
                }
            }
            UpdateStatus();
            return;
        }