コード例 #1
0
        private void ex_Expanded(object sender, RoutedEventArgs e)
        {
            Expander expend = (Expander)sender;

            if (expend.Content != null)
            {
                return;
            }
            ILrcSercherInfoItem lrcSercherItem = expend.DataContext as ILrcSercherInfoItem;

            byte[] buff;
            string LrcTempDownPath = "lrc_temp";

            if (File.Exists(lrcSercherItem.FilePath))
            {//在本地存在
                using (FileStream FS = File.OpenRead(lrcSercherItem.FilePath))
                {
                    buff = new byte[(int)FS.Length];
                    FS.Read(buff, 0, (int)FS.Length);
                    LrcTempEditorText = BeforeEncodingClass.GetText(buff);
                    LrcTempEditorText = LrcTempEditorText.Replace("\\n", "\r\n");
                    TextBox textBox = new TextBox()
                    {
                        Text = LrcTempEditorText
                    };
                    textBox.TextChanged += TextBox_TextChanged;
                    expend.Content       = textBox;
                }
            }
            else if (lrcSercherItem.LrcUri != null)
            {//在网络存在
                downThread = new Thread((ThreadStart) delegate
                {
                    Dispatcher.Invoke((ThreadStart) delegate
                    {
                        expend.Content = new TextBox()
                        {
                            Text = "正在下载中。。。"
                        };
                    });
                    lrcSercherItem.DownloadLrc(LrcTempDownPath);
                    LrcTempEditorText = File.ReadAllText(LrcTempDownPath);
                    Dispatcher.Invoke((ThreadStart) delegate
                    {
                        TextBox textBox = new TextBox()
                        {
                            Text = LrcTempEditorText
                        };
                        textBox.TextChanged += TextBox_TextChanged;
                        expend.Content       = textBox;
                    });
                });
                downThread.Start();
            }
            else
            {
                LrcTempEditorText = "";
            }
        }
コード例 #2
0
        private void ListLrcSelect_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //获取数据项
            ILrcSercherInfoItem item = ListLrcSelect.SelectedItem as ILrcSercherInfoItem;

            try
            {
                if (item == null)
                {
                    item = Helper.UIhelper.FindPrent <ListViewItem>((DependencyObject)e.OriginalSource).DataContext as ILrcSercherInfoItem;
                }
            }
            catch (Exception)
            {
                return;
            }
            if (item == null)
            {
                return;
            }
            //组合将要保存到LRC目录的路径
            string fileName = ArtistTextBox.Text + " - " + MusicNameTextBox.Text + ".lrc";

            fileName = Helper.OtherHelper.ReplaceValidFileName(fileName, ' ');
            string path = GlobalConfigClass._Config.LrcDir + "//" + fileName;

            //处理同名
            if (File.Exists(path) && MessageBoxResult.No == MessageBox.Show("文件已经存在,是否覆盖", "确认覆盖LRC", MessageBoxButton.YesNo))
            {
                return;
            }
            //处理未下载(未编辑)
            if (LrcTempEditorText == null || LrcTempEditorText.Count() < 7)
            {
                return;
            }
            //文件写入
            File.WriteAllText(path, LrcTempEditorText);
            item.FilePath = path;
            Playing.ChangeLrcAndPlayingPage(path);
        }