public void AddMapExport(MapIdentity id, string exportFilePath) { MapInfo map = InnerGetMapFromDb(id, Ctx); map.ExportFile = exportFilePath; Ctx.SaveChanges(); }
public static void RemoveMapFromCollection(MapIdentity id, Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { MapInfo map = InnerGetMapFromDb(id, context); context.Relations.RemoveRange(context.Relations.Where(k => k.CollectionId == collection.Id && k.MapId == map.Id)); context.SaveChanges(); //todo: not suitable position var currentInfo = InstanceManage.GetInstance <PlayerList>().CurrentInfo; if (currentInfo != null) { if (collection.Locked && currentInfo.Identity.Equals(id)) { currentInfo.IsFavorite = false; } } } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public CurrentInfo(string artist, string artistUnicode, string title, string titleUnicode, string creator, string source, List <string> tags, int beatmapId, int beatmapsetId, double stars, double hp, double cs, double ar, double od, long songLength, MapIdentity identity, MapInfo mapInfo, Beatmap beatmap, bool isFavorite, string path) { Artist = artist; ArtistUnicode = artistUnicode; Title = title; TitleUnicode = titleUnicode; Creator = creator; Source = source; Tags = tags; BeatmapId = beatmapId; BeatmapsetId = beatmapsetId; Stars = stars; HP = hp; CS = cs; AR = ar; OD = od; SongLength = songLength; Identity = identity; MapInfo = mapInfo; Beatmap = beatmap; IsFavorite = isFavorite; Path = path; }
public void RemoveFromRecent(MapIdentity id) { MapInfo map = InnerGetMapFromDb(id, Ctx); map.LastPlayTime = null; Ctx.SaveChanges(); }
public void RemoveMapExport(MapIdentity id) { MapInfo map = InnerGetMapFromDb(id, Ctx); map.ExportFile = string.Empty; Ctx.SaveChanges(); }
public static Beatmap FilterByIdentity(MapIdentity identity) { using (var context = new BeatmapDbContext()) { return(context.Beatmaps.Where(k => k != null).FirstOrDefault(k => k.FolderName == identity.FolderName && k.Version == identity.Version)); } }
public MapInfo GetMapFromDb(MapIdentity id) { var map = ThreadedProvider.Query <MapInfo>(TABLE_MAP, new Where[] { ("version", id.Version), ("folder", id.FolderName) },
public static void RemoveFromRecent(MapIdentity id) { using (ApplicationDbContext context = new ApplicationDbContext()) { MapInfo map = InnerGetMapFromDb(id, context); map.LastPlayTime = null; context.SaveChanges(); } }
public void UpdateMap(MapIdentity id, int offset = 0) { MapInfo map = InnerGetMapFromDb(id, Ctx); map.LastPlayTime = DateTime.Now; if (offset != 0) { map.Offset = offset; } Ctx.SaveChanges(); }
public bool TryAddMapExport(MapIdentity mapIdentity, string path) { try { _dbOperator.AddMapExport(mapIdentity, path); return(true); } catch (Exception ex) { Notification.Push($"Error while removing collection: {ex.Message}"); return(false); } }
public bool TryRemoveFromRecent(MapIdentity identity) { try { _dbOperator.RemoveFromRecent(identity); return(true); } catch (Exception ex) { Notification.Push($"Error while removing beatmap from recent: {ex.Message}"); return(false); } }
private static MapInfo InnerGetMapFromDb(MapIdentity id, ApplicationDbContext context) { var map = context.MapInfos.FirstOrDefault(k => k.Version == id.Version && k.FolderName == id.FolderName); if (map == null) { context.MapInfos.Add(new MapInfo(Guid.NewGuid().ToString(), id.Version, id.FolderName, 0, null)); context.SaveChanges(); map = context.MapInfos.First(k => k.Version == id.Version && k.FolderName == id.FolderName); } return(map); }
public static MapInfo GetMapFromDb(MapIdentity id) { using (ApplicationDbContext mapContext = new ApplicationDbContext()) { try { return(InnerGetMapFromDb(id, mapContext)); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
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); }
public static void RemoveMapExport(MapIdentity id) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { MapInfo map = InnerGetMapFromDb(id, context); map.ExportFile = string.Empty; context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public static void RemoveMapFromCollection(MapIdentity id, Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { MapInfo map = InnerGetMapFromDb(id, context); context.Relations.RemoveRange(context.Relations.Where(k => k.CollectionId == collection.Id && k.MapId == map.Id)); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public void RemoveMapFromCollection(MapIdentity id, Collection collection) { MapInfo map = InnerGetMapFromDb(id, Ctx); Ctx.Relations.RemoveRange(Ctx.Relations.Where(k => k.CollectionId == collection.Id && k.MapId == map.Id)); Ctx.SaveChanges(); //todo: not suitable position var currentInfo = Services.Get <PlayerList>().CurrentInfo; if (currentInfo != null) { if (collection.Locked && currentInfo.Identity.Equals(id)) { currentInfo.IsFavorite = false; } } }
public static void UpdateMap(MapIdentity id, int offset = 0) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { MapInfo map = InnerGetMapFromDb(id, context); map.LastPlayTime = DateTime.Now; if (offset != 0) { map.Offset = offset; } context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public static Beatmap FilterByIdentity(MapIdentity identity) { return(Beatmaps.Where(k => k != null).FirstOrDefault(k => k.FolderName == identity.FolderName && k.Version == identity.Version)); }
public static BeatmapEntry FilterByIdentity(this IEnumerable <BeatmapEntry> list, MapIdentity identity) { return(list.Where(k => k != null).FirstOrDefault(k => k.FolderName == identity.FolderName && k.Version == identity.Version)); }
public MapInfo GetMapFromDb(MapIdentity id) { return(InnerGetMapFromDb(id, Ctx)); }
/// <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); } }
private bool IsMapFavorite(MapIdentity identity) { var info = _appDbOperator.GetMapFromDb(identity); return(IsMapFavorite(info)); }
/// <summary> /// Play a new file by file path. /// </summary> private async Task PlayNewFile(string path, bool play) { var sw = Stopwatch.StartNew(); var playerInst = InstanceManage.GetInstance <PlayersInst>(); var dbInst = InstanceManage.GetInstance <OsuDbInst>(); ComponentPlayer audioPlayer = null; if (path == null) { return; } if (File.Exists(path)) { try { var osuFile = await OsuFile.ReadFromFileAsync(path); //50 ms 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*/ playerInst.SetAudioPlayer(path, osuFile); audioPlayer = playerInst.AudioPlayer; SignUpPlayerEvent(audioPlayer); await audioPlayer.InitializeAsync(); //700 ms /* Set Meta */ var nowIdentity = new MapIdentity(fi.Directory.Name, osuFile.Metadata.Version); MapInfo mapInfo = DbOperate.GetMapFromDb(nowIdentity); Beatmap beatmap = BeatmapQuery.FilterByIdentity(nowIdentity); bool isFavorite = IsMapFavorite(mapInfo); //50 ms audioPlayer.HitsoundOffset = mapInfo.Offset; Offset.Value = audioPlayer.HitsoundOffset; var 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, beatmap?.DiffSrNoneStandard ?? 0, osuFile.Difficulty.HpDrainRate, osuFile.Difficulty.CircleSize, osuFile.Difficulty.ApproachRate, osuFile.Difficulty.OverallDifficulty, audioPlayer.Duration, nowIdentity, mapInfo, beatmap, isFavorite); // 20 ms InstanceManage.GetInstance <PlayerList>().CurrentInfo = currentInfo; ViewModel.Player.CurrentInfo = currentInfo; /*start of ui*/ LblTitle.Content = osuFile.Metadata.TitleMeta.ToUnicodeString(); LblArtist.Content = osuFile.Metadata.ArtistMeta.ToUnicodeString(); ((ToolTip)NotifyIcon.TrayToolTip).Content = (string)LblArtist.Content + " - " + (string)LblTitle.Content; /*end of ui*/ /* Set Lyric */ SetLyricSynchronously(); /* Set Progress */ PlayProgress.Maximum = audioPlayer.Duration; PlayProgress.Value = 0; PlayerViewModel.Current.Duration = InstanceManage.GetInstance <PlayersInst>().AudioPlayer.Duration; /* Set Storyboard */ if (true) { // Todo: Set Storyboard } /* Set Video */ bool showVideo = PlayerViewModel.Current.EnableVideo && !ViewModel.IsMiniMode; if (VideoElement != null) { await SafelyRecreateVideoElement(showVideo); if (showVideo) { var videoName = osuFile.Events.VideoInfo?.Filename; if (videoName == null) { VideoElement.Source = null; VideoElementBorder.Visibility = Visibility.Hidden; } else { var vPath = Path.Combine(dir, videoName); if (File.Exists(vPath)) { VideoElement.Source = new Uri(vPath); _videoOffset = -(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 = Visibility.Hidden; } } } } /* Set Background */ if (osuFile.Events.BackgroundInfo != null) { var bgPath = Path.Combine(dir, 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.DataModels.FirstOrDefault(k => k.GetIdentity().Equals(nowIdentity)); recentPlayPage.RecentList.SelectedItem = item; break; case CollectionPage collectionPage: collectionPage.MapList.SelectedItem = collectionPage.ViewModel.Beatmaps.FirstOrDefault(k => k.GetIdentity().Equals(nowIdentity)); break; } _videoPlay = play; if (play) { if (showVideo && VideoElement?.Source != null) { // use event to control here. //VideoPlay(); //App.HitsoundPlayer.Play(); } else { audioPlayer.Play(); } } //if (!App.PlayerList.Entries.Any(k => k.GetIdentity().Equals(nowIdentity))) // App.PlayerList.Entries.Add(entry); PlayerConfig.Current.CurrentPath = path; PlayerConfig.SaveCurrent(); DbOperate.UpdateMap(nowIdentity); } catch (Exception ex) { var result = MsgBox.Show(this, @"发生未处理的异常问题:" + (ex.InnerException ?? ex), Title, MessageBoxButton.OK, MessageBoxImage.Error); if (result == MessageBoxResult.OK) { if (audioPlayer == null) { return; } if (audioPlayer.PlayerStatus != PlayerStatus.Playing) { await PlayNextAsync(false, true); } } Console.WriteLine(ex); } } else { MsgBox.Show(this, @"所选文件不存在,可能是db没有及时更新。请关闭此播放器或osu后重试。", Title, MessageBoxButton.OK, MessageBoxImage.Warning); } sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); }