예제 #1
0
        // 批量保存
        private void BatchSave()
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            try
            {
                saveDialog.FileName = "直接选择保存路径即可,无需修改此处内容";
                saveDialog.Filter   = "lrc文件(*.lrc)|*.lrc|txt文件(*.txt)|*.txt";
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    string localFilePath = saveDialog.FileName.ToString();
                    // 获取文件后缀
                    string fileSuffix = localFilePath.Substring(localFilePath.LastIndexOf("."));
                    //获取文件路径,不带文件名
                    string filePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));

                    foreach (var item in globalSaveVOMap)
                    {
                        string       outputFileName = NeteaseMusicUtils.GetOutputName(item.Value.songVO, globalSearchInfo);
                        string       path           = filePath + "/" + NeteaseMusicUtils.GetSafeFilename(outputFileName) + fileSuffix;
                        StreamWriter sw             = new StreamWriter(path, false, NeteaseMusicUtils.GetEncoding(globalSearchInfo.Encoding));
                        sw.Write(NeteaseMusicUtils.GetOutputLyric(item.Value.lyricVO.Lyric, item.Value.lyricVO.TLyric, globalSearchInfo));
                        sw.Flush();
                        sw.Close();
                    }
                    MessageBox.Show(ErrorMsg.SAVE_SUCCESS, "提示");
                }
            }
            catch (Exception ew)
            {
                MessageBox.Show("批量保存失败,错误信息:\n" + ew.Message);
            }

            // 输出日志
            StringBuilder log = new StringBuilder();

            foreach (var songIdStr in globalSearchInfo.SearchIds)
            {
                if (globalSaveVOMap.ContainsKey(songIdStr))
                {
                    log.Append("ID: " + songIdStr + ", Result: success\r\n");
                }
                else
                {
                    log.Append("ID: " + songIdStr + ", Result: failure\r\n");
                }
            }
            UpdateLrcTextBox(log.ToString());
        }
예제 #2
0
        // 单个保存
        private void SingleSave(string songIdStr)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            try
            {
                SaveVO saveVO = new SaveVO();
                if (!globalSaveVOMap.TryGetValue(songIdStr, out saveVO))
                {
                    MessageBox.Show(ErrorMsg.MUST_SEARCH_BEFORE_SAVE, "提示");
                    return;
                }

                string outputFileName = NeteaseMusicUtils.GetOutputName(saveVO.songVO, globalSearchInfo);
                if (outputFileName == null)
                {
                    MessageBox.Show(ErrorMsg.FILE_NAME_IS_EMPTY, "提示");
                    return;
                }
                else
                {
                    outputFileName = NeteaseMusicUtils.GetSafeFilename(outputFileName);
                }

                saveDialog.FileName = outputFileName;
                saveDialog.Filter   = "lrc文件(*.lrc)|*.lrc|txt文件(*.txt)|*.txt";
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    StreamWriter sw = new StreamWriter(saveDialog.FileName, false, NeteaseMusicUtils.GetEncoding(globalSearchInfo.Encoding));
                    sw.Write(textBox_lrc.Text);
                    sw.Flush();
                    sw.Close();
                    MessageBox.Show(ErrorMsg.SAVE_SUCCESS, "提示");
                }
            }
            catch (Exception ew)
            {
                MessageBox.Show("保存失败!错误信息:\n" + ew.Message);
            }
        }