Exemplo n.º 1
0
        private string GetTargetPath(string targetPath, string sourceFile, IMusicDecode decode)
        {
            FileInfo finfo = new FileInfo(sourceFile);

            if (string.IsNullOrWhiteSpace(targetPath))
            {
                targetPath = AppSave.FormatPath(finfo.DirectoryName);
            }
            StringBuilder retName   = new StringBuilder();
            string        fName     = finfo.Name.Substring(0, finfo.Name.Length - finfo.Extension.Length);
            string        newExName = decode.Format;
            int           index     = 0;

            do
            {
                retName.Clear();
                retName.Append(targetPath);
                retName.Append(fName);
                if (index > 0)
                {
                    retName.Append("(");
                    retName.Append(index.ToString());
                    retName.Append(")");
                }
                retName.Append(".");
                retName.Append(newExName);
                index++;
            } while (File.Exists(retName.ToString()));

            return(retName.ToString());
        }
Exemplo n.º 2
0
        private void btnDecode_Click(object sender, EventArgs e)
        {
            if (_thdDecode != null)
            {
                EnableDecode(false);
                return;
            }

            if (string.IsNullOrWhiteSpace(cmbTarget.Text))
            {
                MessageBox.Show("请填入输出目录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (lstFiles.Items.Count <= 0)
            {
                MessageBox.Show("请选择要输出的文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string targetPath = cmbTarget.Text;

            if (cmbTarget.Text == "<歌曲同目录>")
            {
                targetPath = null;
            }
            if (targetPath != null)
            {
                targetPath = AppSave.FormatPath(targetPath);
                if (!Directory.Exists(targetPath))
                {
                    try
                    {
                        Directory.CreateDirectory(targetPath);
                    }catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            _save.OutputPath = targetPath;
            _save.Save();

            pb.Maximum = lstFiles.Items.Count;
            EnableDecode(true);
            _thdDecode = new Thread(new ThreadStart(ToDecode));
            _thdDecode.Start();
        }