Esempio n. 1
0
 public MainWindowViewModel() : base()
 {
     //初始化菜单
     InitializeMenus();
     //主窗口退出则强制退出所有
     CloseCommand = new RelayCommand <Window>((win) => Task.Run(() => {
         //清空所有通知
         ToastNotificationManagerCompat.Uninstall();
         //退出Tan8播放器
         Tan8PlayUtil.Exit();
         //退出程序
         Environment.Exit(0);
     }));
 }
Esempio n. 2
0
        public void OnTan8PlayButtonClickV2(Object sender, RoutedEventArgs e)
        {
            //事件按钮对象
            var eventButton = (Button)sender;

            //如果ListBox没有初始化, 则根据触发节点寻找
            if (null == pianoScoreListBox)
            {
                DependencyObject dep = (DependencyObject)e.OriginalSource;
                while ((dep != null) && !(dep is ListBox))
                {
                    dep = VisualTreeHelper.GetParent(dep);
                }
                if (dep == null)
                {
                    return;
                }
                //找到之后赋值给成员对象
                pianoScoreListBox = dep as ListBox;
            }

            //根据触发按钮获取点击的行
            var selected = ((ListBoxItem)pianoScoreListBox.ContainerFromElement(eventButton)).Content;

            //检查曲谱可否播放
            var tan8Music    = SQLite.SqlRow(string.Format("SELECT name, ver FROM tan8_music WHERE ypid = {0}", (selected as PianoScore).id.GetValueOrDefault()));
            var folderName   = tan8Music[0];
            var ver          = Convert.ToInt32(tan8Music[1]);
            var playFileName = ver == 1 ? "play.ypa2" : "play.ypdx";
            var playFilePath = Path.Combine(ConfigUtil.Instance.PianoScorePath, (selected as PianoScore).id.GetValueOrDefault().ToString(), playFileName);

            //手动选中行
            pianoScoreListBox.SelectedItem = selected;
            if (!File.Exists(playFilePath))
            {
                //无法播放的曲谱打开所在文件夹
                var fullPath = Path.Combine(ConfigUtil.Instance.PianoScorePath, (selected as PianoScore).id.GetValueOrDefault().ToString());
                if (Directory.Exists(fullPath))
                {
                    System.Diagnostics.Process.Start(fullPath);
                }
                return;
            }
            //播放所选曲谱
            Tan8PlayUtil.Exit();
            Tan8PlayUtil.ExePlayById((selected as PianoScore).id.GetValueOrDefault(), ver, false);
        }