Ejemplo n.º 1
0
        public static Beatmap UpdateFromHolly(this Beatmap beatmap, BeatmapEntry entry)
        {
            beatmap.Artist             = entry.Artist;
            beatmap.ArtistUnicode      = entry.ArtistUnicode;
            beatmap.Title              = entry.Title;
            beatmap.TitleUnicode       = entry.TitleUnicode;
            beatmap.Creator            = entry.Creator;
            beatmap.Version            = entry.Version;
            beatmap.BeatmapFileName    = entry.BeatmapFileName;
            beatmap.LastModifiedTime   = entry.LastModifiedTime;
            beatmap.DiffSrNoneStandard = entry.DiffStarRatingStandard.ContainsKey(Mods.None)
                  ? entry.DiffStarRatingStandard[Mods.None]
                  : -1;
            beatmap.DiffSrNoneTaiko = entry.DiffStarRatingTaiko.ContainsKey(Mods.None)
                  ? entry.DiffStarRatingTaiko[Mods.None]
                  : -1;
            beatmap.DiffSrNoneCtB   = entry.DiffStarRatingCtB.ContainsKey(Mods.None) ? entry.DiffStarRatingCtB[Mods.None] : -1;
            beatmap.DiffSrNoneMania = entry.DiffStarRatingMania.ContainsKey(Mods.None)
                  ? entry.DiffStarRatingMania[Mods.None]
                  : -1;
            beatmap.DrainTimeSeconds = entry.DrainTimeSeconds;
            beatmap.TotalTime        = entry.TotalTime;
            beatmap.AudioPreviewTime = entry.AudioPreviewTime;
            beatmap.BeatmapId        = entry.BeatmapId;
            beatmap.BeatmapSetId     = entry.BeatmapSetId;
            beatmap.GameMode         = entry.GameMode.ParseHollyToOSharp();
            beatmap.SongSource       = entry.SongSource;
            beatmap.SongTags         = entry.SongTags;
            beatmap.FolderNameOrPath = entry.FolderName?.TrimEnd();
            beatmap.AudioFileName    = entry.AudioFileName;

            beatmap.Id = Zip($"!{beatmap.FolderNameOrPath}|{beatmap.Version}|{beatmap.InOwnDb}");
            return(beatmap);
        }
Ejemplo n.º 2
0
        //public string AudioFileName { get; set; }
        //public string BeatmapChecksum { get; set; }
        //public RankStatus RankedStatus { get; set; }
        //public ushort CountHitCircles { get; set; }
        //public ushort CountSliders { get; set; }
        //public ushort CountSpinners { get; set; }
        //public float ApproachRate { get; set; }
        //public float CircleSize { get; set; }
        //public float HpDrainRate { get; set; }
        //public float OveralDifficulty { get; set; }
        //public double SliderVelocity { get; set; }
        //public List<Timing> TimingPoints { get; set; }
        //public int ThreadId { get; set; } //what's this?
        //public Rank GradeStandard { get; set; }
        //public Rank GradeTaiko { get; set; }
        //public Rank GradeCtB { get; set; }
        //public Rank GradeMania { get; set; }
        //public short OffsetLocal { get; set; }
        //public float StackLeniency { get; set; }
        //public short OffsetOnline { get; set; }
        //public string TitleFont { get; set; }
        //public bool Unplayed { get; set; }
        //public DateTime LastPlayed { get; set; }
        //public bool IsOsz2 { get; set; }
        //public DateTime LastCheckAgainstOsuRepo { get; set; }
        //public bool IgnoreBeatmapSounds { get; set; }
        //public bool IgnoreBeatmapSkin { get; set; }
        //public bool DisableStoryBoard { get; set; }
        //public bool DisableVideo { get; set; }
        //public bool VisualOverride { get; set; }
        //public byte ManiaScrollSpeed { get; set; }

        #endregion

        public BeatmapInfo UpdateFromHolly(BeatmapEntry entry)
        {
            Artist             = entry.Artist;
            ArtistUnicode      = entry.ArtistUnicode;
            Title              = entry.Title;
            TitleUnicode       = entry.TitleUnicode;
            Creator            = entry.Creator;
            Version            = entry.Version;
            BeatmapFileName    = entry.BeatmapFileName;
            LastModifiedTime   = entry.LastModifiedTime;
            DiffSrNoneStandard = entry.DiffStarRatingStandard[Mods.None];
            DiffSrNoneTaiko    = entry.DiffStarRatingTaiko[Mods.None];
            DiffSrNoneCtB      = entry.DiffStarRatingCtB[Mods.None];
            DiffSrNoneMania    = entry.DiffStarRatingMania[Mods.None];
            DrainTimeSeconds   = entry.DrainTimeSeconds;
            TotalTime          = entry.TotalTime;
            AudioPreviewTime   = entry.AudioPreviewTime;
            BeatmapId          = entry.BeatmapId;
            BeatmapSetId       = entry.BeatmapSetId;
            GameMode           = entry.GameMode.ParseHollyToOSharp();
            SongSource         = entry.SongSource;
            SongTags           = entry.SongTags;
            FolderName         = entry.FolderName;

            return(this);
        }
Ejemplo n.º 3
0
        public void OsuTitleChanged(String title)
        {
            // sample osu!cuttingedge b20180510 - Wada Kouji - FIRE!! ~TV Size~ [GET A FIRE POWER!!]
            String res = title;

            if (res.IndexOf(" - ") > 0)
            {
                res = res.Remove(0, res.IndexOf(" - ") + 3);
                foreach (BeatmapEntry bm in osuDatabase.Beatmaps)
                {
                    if ($"{bm.Artist} - {bm.Title} [{bm.Version}]" == res)
                    {
                        BuildLiveDisplay(bm);
                        return;
                    }
                }

                // if no title is found in database, parse "Unknown beatmap"
                BeatmapEntry unknown = new BeatmapEntry();
                unknown.Title   = "Unknown Title";
                unknown.Artist  = "";
                unknown.Version = "";
                BuildLiveDisplay(unknown);
            }
            else if (currentBeatmap != null)
            {
                BeatmapEntry unknown = new BeatmapEntry();
                unknown.Title   = "Waiting for beatmap...";
                unknown.Artist  = "";
                unknown.Version = "";
                BuildLiveDisplay(unknown);
            }
        }
Ejemplo n.º 4
0
        public void ReadFromStream(SerializationReader r)
        {
            OsuVersion        = r.ReadInt32();
            FolderCount       = r.ReadInt32();
            AccountUnlocked   = r.ReadBoolean();
            AccountUnlockDate = r.ReadDateTime();
            AccountName       = r.ReadString();

            Beatmaps = new List <BeatmapEntry>();
            int length = r.ReadInt32();

            for (int i = 0; i < length; i++)
            {
                int currentIndex = (int)r.BaseStream.Position;
                int entryLength  = r.ReadInt32();

                Beatmaps.Add(BeatmapEntry.ReadFromReader(r, false, OsuVersion));

                if (r.BaseStream.Position != currentIndex + entryLength + 4)
                {
                    Debug.Fail($"Length doesn't match, {r.BaseStream.Position} instead of expected {currentIndex + entryLength + 4}");
                }
            }
            AccountRank = (PlayerRank)r.ReadByte();
        }
Ejemplo n.º 5
0
 public BeatmapLittle(BeatmapEntry bm)
 {
     title        = bm.Title;
     artist       = bm.Artist;
     songTags     = bm.SongTags;
     beatmapId    = bm.BeatmapId;
     beatmapSetID = bm.BeatmapSetId;
 }
Ejemplo n.º 6
0
 public SelectCollectionPage(MainWindow mainWindow, BeatmapEntry entry)
 {
     InitializeComponent();
     ViewModel       = (SelectCollectionPageViewModel)DataContext;
     _entry          = entry;
     ViewModel.Entry = entry;
     _mainWindow     = mainWindow;
     RefreshList();
 }
Ejemplo n.º 7
0
        public BeatmapDisplay(GraphicsDevice gd, ContentManager content, BeatmapEntry bmEntry)
        {
            this.bmEntry = bmEntry;
            this.gd      = gd;
            spriteBatch  = new SpriteBatch(gd);
            this.content = content;

            curvedBorder = content.Load <Effect>("border-radius");
            curvedBorder.Parameters["MaskTexture"].SetValue(content.Load <Texture2D>("MaskTexture"));
            textCutOff = content.Load <Effect>("TextCutoff");

            scrollableTexts = new Dictionary <string, ScrollableText>();

            this.Init();
        }
        public override void OnStatusChange(OsuStatus last_status, OsuStatus status)
        {
            current_status = status;

            if (last_status == status)
            {
                return;
            }
            if ((status != OsuStatus.Playing) && (status != OsuStatus.Rank))
            {
                if (OsuStatusHelper.IsListening(status))
                {
                    TrigListen();
                }
                else
                {
                    RefPanelPlugin.OnBeatmapChanged(null);
                }
            }
            else
            {
                if (current_mod.Mod != ModsInfo.Mods.Unknown || current_mod.Mod != ModsInfo.Mods.None)
                {
                    //fix for https://puu.sh/zelua/d60b98d496.jpg
                    return;
                }

                BeatmapEntry beatmap = new BeatmapEntry()
                {
                    OutputType   = CurrentOutputType = OutputType.Listen,
                    BeatmapId    = beatmapID,
                    BeatmapSetId = beatmapSetID,
                    OsuFilePath  = OsuFilePath,
                    ExtraParam   = new System.Collections.Generic.Dictionary <string, object> {
                        { "ortdp_beatmap", current_beatmap },
                        { "mode", RefPlugin.ListenerManager.GetCurrentData(OsuRTDataProvider.Listen.ProvideDataMask.GameMode).PlayMode }
                    }
                };

                RefPanelPlugin.OnBeatmapChanged(new BeatmapChangedParameter()
                {
                    beatmap = beatmap
                });
            }
        }
Ejemplo n.º 9
0
 public static void AddToCollection(Collection col, BeatmapEntry entry)
 {
     if (string.IsNullOrEmpty(col.ImagePath))
     {
         OsuFile osuFile =
             new OsuFile(Path.Combine(Domain.OsuSongPath, entry.FolderName, entry.BeatmapFileName));
         if (osuFile.Events.BackgroundInfo != null)
         {
             var imgPath = Path.Combine(Domain.OsuSongPath, entry.FolderName, osuFile.Events.BackgroundInfo.Filename);
             if (File.Exists(imgPath))
             {
                 col.ImagePath = imgPath;
                 DbOperator.UpdateCollection(col);
             }
         }
     }
     DbOperator.AddMapToCollection(entry, col);
 }
Ejemplo n.º 10
0
 public static void AddMapToCollection(BeatmapEntry entry, Collection collection)
 {
     using (ApplicationDbContext context = new ApplicationDbContext())
     {
         try
         {
             MapInfo map = InnerGetMapFromDb(entry.GetIdentity(), context);
             context.Relations.Add(new CollectionRelation(Guid.NewGuid().ToString(), collection.Id,
                                                          map.Id));
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Console.WriteLine(@"Failed: " + ex);
             throw;
         }
     }
 }
Ejemplo n.º 11
0
        public static async Task AddToCollectionAsync(Collection col, BeatmapEntry entry)
        {
            if (string.IsNullOrEmpty(col.ImagePath))
            {
                var osuFile =
                    await OsuFile.ReadFromFileAsync(Path.Combine(Domain.OsuSongPath, entry.FolderName,
                                                                 entry.BeatmapFileName));

                if (osuFile.Events.BackgroundInfo != null)
                {
                    var imgPath = Path.Combine(Domain.OsuSongPath, entry.FolderName, osuFile.Events.BackgroundInfo.Filename);
                    if (File.Exists(imgPath))
                    {
                        col.ImagePath = imgPath;
                        DbOperate.UpdateCollection(col);
                    }
                }
            }
            DbOperate.AddMapToCollection(entry, col);
        }
Ejemplo n.º 12
0
        private void extractBeatmap(BeatmapEntry bmp)
        {
            try
            {
                string inFile    = Path.Combine(Configs.SongsPath, bmp.FolderName, bmp.AudioFileName);
                string entryName = validChars(bmp.Title) + " - " + validChars(bmp.Artist) + " [" + validChars(bmp.Version) + "] (" + validChars(bmp.Creator) + ")";
                string outFile   = Path.Combine(OutputSubFolder, entryName + @".mp3");

                if (!System.IO.File.Exists(outFile))
                {
                    copyAudioFile(inFile, outFile, entryName, bmp);
                }
                else
                {
                    Log.Add("[Info] For beatmap: " + entryName + " = " + "Beatmap was previously exported");
                }
            }
            catch (Exception e)
            {
                Log.Add("[Error] While reading map data = " + e.Message);
            }
        }
Ejemplo n.º 13
0
 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, BeatmapEntry entry, bool isFaved)
 {
     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;
     Entry         = entry;
     IsFaved       = isFaved;
 }
Ejemplo n.º 14
0
        public void ReadFromStream(SerializationReader r)
        {
            OsuVersion        = r.ReadInt32();
            FolderCount       = r.ReadInt32();
            AccountUnlocked   = r.ReadBoolean();
            AccountUnlockDate = r.ReadDateTime();
            AccountName       = r.ReadString();

            Beatmaps = new List <BeatmapEntry>();

            int length = r.ReadInt32();

            for (int i = 0; i < length; i++)
            {
                int currentIndex = (int)r.BaseStream.Position;
                int entryLength  = 0;

                // After version 20191107, the size of the beatmap entry is no longer present
                // https://github.com/ppy/osu-wiki/commit/7ce3b8988d9945fe5867029a65750b40d66a3820
                const int lengthOsuVersion = 20191107;

                if (OsuVersion < lengthOsuVersion)
                {
                    entryLength = r.ReadInt32();
                }

                Beatmaps.Add(BeatmapEntry.ReadFromReader(r, false, OsuVersion));

                if (OsuVersion < lengthOsuVersion && r.BaseStream.Position != currentIndex + entryLength + 4)
                {
                    Debug.Fail($"Length doesn't match, {r.BaseStream.Position} instead of expected {currentIndex + entryLength + 4}");
                }
            }

            AccountRank = (PlayerRank)r.ReadByte();
        }
Ejemplo n.º 15
0
 public void BuildLiveDisplay(BeatmapEntry beatmap)
 {
     currentBeatmap = new BeatmapDisplay(GraphicsDevice, Content, beatmap);
 }
Ejemplo n.º 16
0
        /// <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);
            }
        }
Ejemplo n.º 17
0
 public static void RemoveFromRecent(BeatmapEntry entry)
 {
     RemoveFromRecent(entry.GetIdentity());
 }
Ejemplo n.º 18
0
 public static void UpdateMap(BeatmapEntry entry, int offset)
 {
     UpdateMap(entry.GetIdentity());
 }
Ejemplo n.º 19
0
 public static MapIdentity GetIdentity(this BeatmapEntry entry) => entry != null ?
 new MapIdentity(entry.FolderName, entry.Version) : default;
Ejemplo n.º 20
0
        public void extract(string mode, Configurations configs, OsuDb odb, CollectionDb cdb)
        {
            Configs   = configs;
            Mode      = mode;
            ValidMode = validChars(mode);
            Odb       = odb;
            Cdb       = cdb;
            Result    = false;

            if (Odb.Beatmaps.Count != 0)
            {
                Log = new List <string>();

                if (!System.IO.File.Exists(Configs.ImgPath))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        Properties.Resources.Defaultsongthumbnail.Save(ms, ImageFormat.Jpeg);
                        ms.Position     = 0;
                        PicDefault.Data = TagLib.ByteVector.FromStream(ms);
                    }
                }
                else
                {
                    PicDefault.Data = TagLib.ByteVector.FromPath(Configs.ImgPath);
                }

                try
                {
                    Directory.CreateDirectory(Path.Combine(Configs.OutPath, ValidMode));
                    OutputSubFolder = Path.Combine(Configs.OutPath, ValidMode);

                    if (Mode == "Complete library")
                    {
                        PrBarMax = 0;
                        BeatmapEntry oldBeatmap = Odb.Beatmaps[0];
                        foreach (BeatmapEntry beatmap in Odb.Beatmaps)
                        {
                            if (oldBeatmap.BeatmapSetId != beatmap.BeatmapSetId)
                            {
                                PrBarMax++;
                            }
                            oldBeatmap = beatmap;
                        }
                        PrBarMax++;
                    }
                    else
                    {
                        PrBarMax = 0;

                        //Select collection
                        foreach (Collection col in Cdb.Collections)
                        {
                            if (col.Name == Mode)
                            {
                                SelectedCollection = col;
                            }
                        }

                        foreach (string hash in SelectedCollection.BeatmapHashes)
                        {
                            PrBarMax++;
                        }
                    }

                    viewUpdate(true, PrBarMax);
                    BackgroundWorker1.RunWorkerAsync();
                }
                catch (Exception)
                {
                    MessageBox.Show("Unable to create directory:" + Path.Combine(Configs.OutPath, ValidMode) + Environment.NewLine + Environment.NewLine + "Please check if the fonder is read only or protected...", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Your osu seems to have 0 songs thats weird..." + Environment.NewLine + Environment.NewLine + "Please put some maps in it or try another installation...", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 21
0
        private void copyAudioFile(string input, string output, string entryName, BeatmapEntry bmp)
        {
            try
            {
                System.IO.File.Copy(input, output, true);

                if (Configs.OverwriteAlbum || Configs.OverwriteArtist || Configs.OverwriteTitle)
                {
                    File = TagLib.File.Create(output);
                    TagLib.File fileAux = null;

                    if (useAuxFile())
                    {
                        fileAux = File;
                    }

                    if (forceTitle()) //ask title
                    {
                        File.Tag.Title = bmp.Title;
                    }
                    else if (notForceTitle())
                    {
                        if (fileAux.Tag.Title == null)
                        {
                            File.Tag.Title = bmp.Title;
                        }
                    }

                    if (forceAlbum()) //ask album
                    {
                        File.Tag.Album = ValidMode;
                    }
                    else if (notForceTitle())
                    {
                        if (fileAux.Tag.Album == null)
                        {
                            File.Tag.Album = ValidMode;
                        }
                    }

                    if (forceArtist())
                    {
                        updateArtist(bmp.Artist);
                    }
                    else if (notForceArtist())
                    {
                        if (fileAux.Tag.AlbumArtists.Count() == 0 && fileAux.Tag.Performers.Count() == 0)
                        {
                            updateArtist(bmp.Artist);
                        }
                        else if (fileAux.Tag.AlbumArtists.Count() != 0 && fileAux.Tag.Performers.Count() == 0)
                        {
                            updateArtist(File.Tag.AlbumArtists[0]);
                        }
                        else if (fileAux.Tag.Performers.Count() != 0 && fileAux.Tag.AlbumArtists.Count() == 0)
                        {
                            updateArtist(File.Tag.Performers[0]);
                        }
                    }

                    if (Configs.IncludeThumbnails && Configs.ForceImage)
                    {
                        embedPicture(PicDefault);
                    }
                    else if (Configs.IncludeThumbnails)
                    {
                        BeatmapFile beatmapFile = BeatmapFile.Read(Path.Combine(Configs.SongsPath, bmp.FolderName, bmp.BeatmapFileName), true);

                        string imagePath;
                        if (beatmapFile.BackgroundImageFile != null && System.IO.File.Exists(imagePath = Path.Combine(Configs.SongsPath, bmp.FolderName, beatmapFile.BackgroundImageFile)))
                        {
                            try
                            {
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    Image png = Image.FromFile(imagePath);

                                    png.Save(ms, ImageFormat.Jpeg);
                                    ms.Position = 0;
                                    png.Dispose();

                                    Pic.Data = TagLib.ByteVector.FromStream(ms);
                                    embedPicture(Pic);
                                }
                            }
                            catch (Exception)
                            {
                                embedPicture(PicDefault);
                            }
                        }
                        else
                        {
                            embedPicture(PicDefault);
                        }
                    }

                    File.Save();

                    if (useAuxFile())
                    {
                        fileAux.Dispose();
                    }
                }
            }
            catch (FileNotFoundException fileMissing)
            {
                Log.Add("[Error] For beatmap: " + entryName + " = " + fileMissing.Message);
            }
            catch (UnauthorizedAccessException noAccess)
            {
                Log.Add("[Error] For beatmap: " + entryName + " = " + noAccess.Message);
            }
            catch (TagLib.UnsupportedFormatException unsupportedFile)
            {
                Log.Add("[Error] For beatmap: " + entryName + " = " + unsupportedFile.Message);
            }
            catch (TagLib.CorruptFileException corrupt)
            {
                Log.Add("[Error] For beatmap: " + entryName + " = " + corrupt.Message);
            }
            catch (Exception exeption)
            {
                Log.Add("[Error] For beatmap: " + entryName + " = " + exeption.Message);
            }
        }
Ejemplo n.º 22
0
 public static void RemoveMapFromCollection(BeatmapEntry entry, Collection collection)
 {
     RemoveMapFromCollection(entry.GetIdentity(), collection);
 }
Ejemplo n.º 23
0
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (Mode == "Complete library")
            {
                int i = 0;
                int j = 1;

                BeatmapEntry oldBeatmap = Odb.Beatmaps[0];
                BeatmapEntry beatmap    = Odb.Beatmaps[0];

                while (!Cancel && j < Odb.Beatmaps.Count)
                {
                    if (oldBeatmap.BeatmapSetId != beatmap.BeatmapSetId)
                    {
                        i++;
                        extractBeatmap(oldBeatmap);
                        BackgroundWorker1.ReportProgress(i);
                    }

                    oldBeatmap = beatmap;
                    beatmap    = Odb.Beatmaps[j];
                    j++;
                }

                if (!Cancel)
                {
                    i++;
                    extractBeatmap(oldBeatmap);
                    BackgroundWorker1.ReportProgress(i);
                    Result = true;
                }
                else
                {
                    Cancel = false;
                }
            }
            else
            {
                int i = 0;
                int j = 0;

                //Iterate though maps
                BeatmapEntry beatmap = Odb.Beatmaps[0];
                while (!Cancel && j < Odb.Beatmaps.Count && i < SelectedCollection.BeatmapHashes.Count)
                {
                    foreach (string hash in SelectedCollection.BeatmapHashes)
                    {
                        if (beatmap.BeatmapChecksum == hash)
                        {
                            i++;
                            extractBeatmap(beatmap);
                            BackgroundWorker1.ReportProgress(i);
                        }
                    }

                    beatmap = Odb.Beatmaps[j];
                    j++;
                }

                if (!Cancel)
                {
                    Result = true;
                }
                else
                {
                    Cancel = false;
                }
            }
        }
Ejemplo n.º 24
0
 public static Beatmap ParseFromHolly(BeatmapEntry entry)
 {
     return((new Beatmap()).UpdateFromHolly(entry));
 }
Ejemplo n.º 25
0
        /// <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>();
            ComponentPlayer audioPlayer = null;
            var             dbInst      = InstanceManage.GetInstance <OsuDbInst>();

            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); //todo: 700 ms
                    audioPlayer = playerInst.AudioPlayer;
                    await audioPlayer.InitializeAsync();

                    audioPlayer.ProgressRefreshInterval = 500;
                    SignUpPlayerEvent(audioPlayer);

                    /* Set Meta */
                    var nowIdentity = new MapIdentity(fi.Directory.Name, osuFile.Metadata.Version);

                    MapInfo mapInfo = DbOperate.GetMapFromDb(nowIdentity);
                    //BeatmapEntry entry = App.PlayerList.Entries.GetBeatmapByIdentity(nowIdentity);
                    BeatmapEntry entry = dbInst.Beatmaps.FilterByIdentity(nowIdentity);

                    LblTitle.Content  = osuFile.Metadata.TitleMeta.ToUnicodeString();
                    LblArtist.Content = osuFile.Metadata.ArtistMeta.ToUnicodeString();
                    ((ToolTip)NotifyIcon.TrayToolTip).Content =
                        (string)LblArtist.Content + " - " + (string)LblTitle.Content;
                    bool isFaved = SetFaved(nowIdentity); //50 ms
                    audioPlayer.HitsoundOffset = mapInfo.Offset;
                    Offset.Value = audioPlayer.HitsoundOffset;

                    InstanceManage.GetInstance <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,
                                        audioPlayer?.Duration ?? 0,
                                        nowIdentity,
                                        mapInfo,
                                        entry,
                                        isFaved); // 20 ms

                    /* Set Lyric */
                    SetLyricSynchronously(); //todo: 900ms

                    /* Set Progress */
                    //PlayProgress.Value = App.HitsoundPlayer.SingleOffset;
                    PlayProgress.Maximum = audioPlayer.Duration;
                    PlayProgress.Value   = 0;

                    PlayerViewModel.Current.Duration = InstanceManage.GetInstance <PlayersInst>().AudioPlayer.Duration;
                    //LblTotal.Content = new TimeSpan(0, 0, 0, 0, audioPlayer.Duration).ToString(@"mm\:ss");
                    //LblNow.Content = new TimeSpan(0, 0, 0, 0, audioPlayer.PlayTime).ToString(@"mm\:ss");

                    /* Set Storyboard */
                    if (true)
                    {
                        // Todo: Set Storyboard
                    }

                    /* Set Video */
                    bool showVideo = PlayerViewModel.Current.EnableVideo && !ViewModel.IsMiniMode;
                    if (VideoElement != null)
                    {
                        await ClearVideoElement(showVideo);

                        if (showVideo)
                        {
                            var videoName = 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        = -(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 (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();

                    //RunSurfaceUpdate();
                    DbOperate.UpdateMap(nowIdentity);
                }
                catch (RepeatTimingSectionException ex)
                {
                    var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK,
                                             MessageBoxImage.Warning);
                    if (result == MessageBoxResult.OK)
                    {
                        if (audioPlayer == null)
                        {
                            return;
                        }
                        if (audioPlayer.PlayerStatus != PlayerStatus.Playing)
                        {
                            PlayNextAsync(false, true);
                        }
                    }
                }
                catch (BadOsuFormatException ex)
                {
                    var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK,
                                             MessageBoxImage.Warning);
                    if (result == MessageBoxResult.OK)
                    {
                        if (audioPlayer == null)
                        {
                            return;
                        }
                        if (audioPlayer.PlayerStatus != PlayerStatus.Playing)
                        {
                            PlayNextAsync(false, true);
                        }
                    }
                }
                catch (VersionNotSupportedException ex)
                {
                    var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK,
                                             MessageBoxImage.Warning);
                    if (result == MessageBoxResult.OK)
                    {
                        if (audioPlayer == null)
                        {
                            return;
                        }
                        if (audioPlayer.PlayerStatus != PlayerStatus.Playing)
                        {
                            PlayNextAsync(false, true);
                        }
                    }
                }
                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)
                        {
                            PlayNextAsync(false, true);
                        }
                    }

                    Console.WriteLine(ex);
                }
            }
            else
            {
                MsgBox.Show(this, string.Format(@"所选文件不存在{0}。", InstanceManage.GetInstance <OsuDbInst>().Beatmaps == null
                        ? ""
                        : " ,可能是db没有及时更新。请关闭此播放器或osu后重试"),
                            Title, MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }