Example #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());
        }
Example #2
0
        private void ToDecode()
        {
            string targetPath = _save.OutputPath;
            string tFile      = null;

            for (int i = 0; i < lstFiles.Items.Count; i++)
            {
                string sourceFile = lstFiles.Items[i].ToString();
                msg.Log("正在转换:" + sourceFile);
                try
                {
                    using (FileStream stmSource = File.Open(sourceFile, FileMode.Open))
                    {
                        FileInfo     finfo    = new FileInfo(sourceFile);
                        string       sourceEx = finfo.Extension.Trim('.');
                        IMusicDecode decode   = DecoderManager.CreateDecode(sourceEx);
                        if (decode == null)
                        {
                            msg.LogError(sourceEx + "文件不存在解码");
                            return;
                        }
                        decode.Load(stmSource, sourceEx);

                        tFile = GetTargetPath(targetPath, sourceFile, decode);



                        decode.Dump(tFile);
                    }
                } catch (Exception ex)
                {
                    msg.LogError(ex.ToString());
                }
                msg.Log(sourceFile + " 转换完毕");
                SetProcess(i);
            }
            SetProcess(0);
            MessageBox.Show("转换完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            msg.Log("转换完毕");
            EnableDecode(false);
            this.Invoke((EventHandler) delegate
            {
                lstFiles.Items.Clear();
            });
        }