Esempio n. 1
0
        private void convertButton_Click(object sender, EventArgs e)
        {
            if (this.converterWorker.IsBusy)
            {
                MessageBox.Show("You are already converting stuff.");
                return;
            }

            var files  = this.filesBox.Items.OfType <string>().ToArray();
            var output = this.outputTextbox.Text;

            if (files.Length == 0)
            {
                MessageBox.Show("No files selected for conversion.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            BCSTMConverter.CheckIfVgmStreamAvailable();

            this.InitializeUI(files.Length);

            TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);

            this.cancellationTokenSource = new CancellationTokenSource();

            var outputPath = SetOutputPath(output);

            this.Log($"Output path: {outputPath}");

            var arguments = new object[] { files, outputPath };

            this.converterWorker.RunWorkerAsync(arguments);
        }
Esempio n. 2
0
        private void converterWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // lmao
            var args   = (object[])e.Argument;
            var files  = (string[])args[0];
            var output = (string)args[1];

            this.taskIsRunning = true;

            var options = new ParallelOptions {
                CancellationToken = this.cancellationTokenSource.Token
            };

            Parallel.ForEach(
                files,
                (currentFile, loopState) =>
            {
                if (options.CancellationToken.IsCancellationRequested)
                {
                    KillRunningConversionProcesses();
                    this.converterWorker.ReportProgress(0, "Cancelled.");
                    loopState.Break();
                }
                var wav = true;
                if (!this.radioButton2.Checked)
                {
                    wav = false;
                }
                string result;
                BCSTMConverter.Run(currentFile, output, out result, wav);
                this.converterWorker.ReportProgress(0, result);
            });
        }