private bool SetFaved(MapIdentity identity) { var map = DbOperator.GetMapFromDb(identity); var album = DbOperator.GetCollectionsByMap(map); bool faved = album != null && album.Any(k => k.Locked); BtnLike.Background = faved ? (ViewModel.IsMiniMode ? (Brush)ToolControl.FindResource("FavedS") : (Brush)ToolControl.FindResource("Faved")) : (ViewModel.IsMiniMode ? (Brush)ToolControl.FindResource("FavS") : (Brush)ToolControl.FindResource("Fav")); return(faved); }
/// <summary> /// Play a new file by file path. /// </summary> private async Task PlayNewFile(string path, bool play) { if (path == null) { return; } if (File.Exists(path)) { try { var osu = new OsuFile(path); var fi = new FileInfo(path); if (!fi.Exists) { throw new FileNotFoundException("Cannot locate.", fi.FullName); } var dir = fi.Directory.FullName; /* Clear */ ClearHitsoundPlayer(); /* Set new hitsound player*/ App.HitsoundPlayer = new HitsoundPlayer(path, osu); _cts = new CancellationTokenSource(); /* Set Meta */ MapIdentity nowIdentity = new MapIdentity(fi.Directory.Name, App.HitsoundPlayer.Osufile.Metadata.Version); MapInfo mapInfo = DbOperator.GetMapFromDb(nowIdentity); //BeatmapEntry entry = App.PlayerList.Entries.GetBeatmapByIdentity(nowIdentity); BeatmapEntry entry = App.Beatmaps.GetBeatmapByIdentity(nowIdentity); OsuFile osuFile = App.HitsoundPlayer.Osufile; LblTitle.Content = App.HitsoundPlayer.Osufile.Metadata.GetUnicodeTitle(); LblArtist.Content = App.HitsoundPlayer.Osufile.Metadata.GetUnicodeArtist(); ((ToolTip)NotifyIcon.TrayToolTip).Content = (string)LblArtist.Content + " - " + (string)LblTitle.Content; bool isFaved = SetFaved(nowIdentity); App.HitsoundPlayer.SingleOffset = mapInfo.Offset; Offset.Value = App.HitsoundPlayer.SingleOffset; App.PlayerList.CurrentInfo = new CurrentInfo(osuFile.Metadata.Artist, osuFile.Metadata.ArtistUnicode, osuFile.Metadata.Title, osuFile.Metadata.TitleUnicode, osuFile.Metadata.Creator, osuFile.Metadata.Source, osuFile.Metadata.TagList, osuFile.Metadata.BeatmapID, osuFile.Metadata.BeatmapSetID, entry != null ? (entry.DiffStarRatingStandard.ContainsKey(Mods.None) ? entry.DiffStarRatingStandard[Mods.None] : 0) : 0, osuFile.Difficulty.HPDrainRate, osuFile.Difficulty.CircleSize, osuFile.Difficulty.ApproachRate, osuFile.Difficulty.OverallDifficulty, App.MusicPlayer?.Duration ?? 0, nowIdentity, mapInfo, entry, isFaved); /* Set Lyric */ SetLyric(); /* Set Progress */ //PlayProgress.Value = App.HitsoundPlayer.SingleOffset; PlayProgress.Maximum = App.HitsoundPlayer.Duration; PlayProgress.Value = 0; LblTotal.Content = new TimeSpan(0, 0, 0, 0, App.HitsoundPlayer.Duration).ToString(@"mm\:ss"); LblNow.Content = new TimeSpan(0, 0, 0, 0, App.HitsoundPlayer.PlayTime).ToString(@"mm\:ss"); #if DEBUG /* Set Storyboard */ if (false) { if (_sbWindow == null || _sbWindow.IsClosed) { _sbWindow = new StoryboardWindow(); _sbWindow.Show(); App.StoryboardProvider = new Media.Storyboard.StoryboardProvider(_sbWindow); } App.StoryboardProvider.LoadStoryboard(dir, App.HitsoundPlayer.Osufile); } #endif /* Set Video */ bool showVideo = ViewModel.EnableVideo && !ViewModel.IsMiniMode; if (VideoElement != null) { await ClearVideoElement(showVideo); if (showVideo) { var videoName = App.HitsoundPlayer.Osufile.Events.VideoInfo?.Filename; if (videoName == null) { VideoElement.Source = null; VideoElementBorder.Visibility = System.Windows.Visibility.Hidden; } else { var vPath = Path.Combine(dir, videoName); if (File.Exists(vPath)) { VideoElement.Source = new Uri(vPath); _videoOffset = -App.HitsoundPlayer.Osufile.Events.VideoInfo.Offset; if (_videoOffset >= 0) { _waitAction = () => { }; _position = TimeSpan.FromMilliseconds(_videoOffset); } else { _waitAction = () => { Thread.Sleep(TimeSpan.FromMilliseconds(-_videoOffset)); }; } } else { VideoElement.Source = null; VideoElementBorder.Visibility = System.Windows.Visibility.Hidden; } } } } /* Set Background */ if (App.HitsoundPlayer.Osufile.Events.BackgroundInfo != null) { var bgPath = Path.Combine(dir, App.HitsoundPlayer.Osufile.Events.BackgroundInfo.Filename); BlurScene.Source = File.Exists(bgPath) ? new BitmapImage(new Uri(bgPath)) : null; Thumb.Source = File.Exists(bgPath) ? new BitmapImage(new Uri(bgPath)) : null; } else { BlurScene.Source = null; } /* Start Play */ switch (MainFrame.Content) { case RecentPlayPage recentPlayPage: var item = recentPlayPage.ViewModels.FirstOrDefault(k => k.GetIdentity().Equals(nowIdentity)); recentPlayPage.RecentList.SelectedItem = item; break; case CollectionPage collectionPage: collectionPage.MapList.SelectedItem = collectionPage.ViewModels.FirstOrDefault(k => k.GetIdentity().Equals(nowIdentity)); break; } _videoPlay = play; if (play) { if (showVideo && VideoElement?.Source != null) { VideoPlay(); //App.HitsoundPlayer.Play(); } else { App.HitsoundPlayer.Play(); } } //if (!App.PlayerList.Entries.Any(k => k.GetIdentity().Equals(nowIdentity))) // App.PlayerList.Entries.Add(entry); App.Config.CurrentPath = path; App.SaveConfig(); RunSurfaceUpdate(); DbOperator.UpdateMap(nowIdentity); } catch (MultiTimingSectionException ex) { var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { if (App.HitsoundPlayer == null) { return; } if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing) { PlayNext(false, true); } } } catch (BadOsuFormatException ex) { var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { if (App.HitsoundPlayer == null) { return; } if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing) { PlayNext(false, true); } } } catch (VersionNotSupportedException ex) { var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { if (App.HitsoundPlayer == null) { return; } if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing) { PlayNext(false, true); } } } catch (Exception ex) { var result = MsgBox.Show(this, @"发生未处理的异常问题:" + (ex.InnerException ?? ex), Title, MessageBoxButton.OK, MessageBoxImage.Error); if (result == MessageBoxResult.OK) { if (App.HitsoundPlayer == null) { return; } if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing) { PlayNext(false, true); } } Console.WriteLine(ex); } } else { MsgBox.Show(this, string.Format(@"所选文件不存在{0}。", App.Beatmaps == null ? "" : " ,可能是db没有及时更新。请关闭此播放器或osu后重试"), Title, MessageBoxButton.OK, MessageBoxImage.Warning); } }