Ejemplo n.º 1
0
 public void Add(OsuSong os)
 {
     if (originList == null)
     {
         originList = new List <OsuSong>();
     }
     originList.Add(os);
 }
Ejemplo n.º 2
0
 public void AddtoCurrentList(OsuSong os)
 {
     if (currentPlaylist != null)
     {
         currentPlaylist.Items.Add(os);
         UpdateMediaList();
         listBox_MediaList.SetSelected(listBox_MediaList.Items.Count - 1, true);
     }
 }
Ejemplo n.º 3
0
        private void removeFromDictionary(OsuSong os)
        {
            string id = os.BeatmapID;

            if (id == null)
            {
                id = os.OsuFilename;
            }
            SongDictionary.Remove(id);
        }
Ejemplo n.º 4
0
        private void addToDictionary(OsuSong os)
        {
            string id = os.BeatmapID;

            if (id == null)
            {
                id = os.OsuFilename;
            }
            SongDictionary[id] = os;
        }
Ejemplo n.º 5
0
        public static Image getBackgroundImage(OsuSong os)
        {
            string bgFile = os.BackgroundFilename;
            Image  image  = null;

            if (ImageCache.TryGetValue(bgFile, out image))
            {
                return(image);
            }
            else
            {
                image = os.BackgroundImage;
                ImageCache.Add(bgFile, image);
                return(image);
            }
        }
Ejemplo n.º 6
0
        public List <OsuSong> getSongsList(Form parent, void_SingleInt_InvokeMethod progressBarUpdate)
        {
            if (myThread != null && myThread.ThreadState == ThreadState.Running)
            {
                threadEnd = true;
                myThread.Abort();
            }

            DirectoryInfo[] dirs = songDir.GetDirectories();
            double          count = 0, length = dirs.Length;

            foreach (DirectoryInfo di in dirs)
            {
                foreach (FileInfo fi in di.GetFiles())
                {
                    if (fi.Extension == ".osu")
                    {
                        count++;
                        OsuSong os = new OsuSong(fi);
                        addToDictionary(os);
                        if (parent != null && progressBarUpdate != null)
                        {
                            parent.Invoke(progressBarUpdate, (int)(count / length * 100));
                        }
                        break;
                    }
                }
            }
            osuSongs = SongDictionary.Values.ToList();
            CreateSongListCache();

            if (parent != null && progressBarUpdate != null)
            {
                parent.Invoke(progressBarUpdate, 100);
            }

            osuSongs.Sort((x, y) => { return(x.TitleASCII.CompareTo(y.TitleASCII)); });

            ActiveSongListChangedEvent();
            return(osuSongs);
        }
Ejemplo n.º 7
0
        private void moveItem(int i)
        {
            if (listBox_MediaList.SelectedIndex >= 0 && currentPlaylist != null)
            {
                OsuSong tmp = currentPlaylist.Items[listBox_MediaList.SelectedIndex];
                currentPlaylist.Items.RemoveAt(listBox_MediaList.SelectedIndex);
                int index = listBox_MediaList.SelectedIndex + i;

                if (index < 0)
                {
                    index = 0;
                }
                else if (index > currentPlaylist.Items.Count - 1)
                {
                    index = currentPlaylist.Items.Count;
                }

                currentPlaylist.Items.Insert(index, tmp);
                UpdatePlaylists();
                listBox_MediaList.SetSelected(index, true);
            }
        }
Ejemplo n.º 8
0
        private void LoadLists()
        {
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            IEnumerable <string> files = Directory.GetFiles(dataPath).Where(s => s.EndsWith(".xml"));

            foreach (string file in files)
            {
                StreamReader sr = File.OpenText(file);
                if (sr.ReadLine() == OsuPlaylist.Header)
                {
                    OsuPlaylist tmp = new OsuPlaylist(sr.ReadLine());
                    while (!sr.EndOfStream)
                    {
                        string s = sr.ReadLine();
                        if (s == "")
                        {
                            continue;
                        }
                        OsuSong os = OsuView.getInstance().getOsuSongByID(s);
                        if (os != null)
                        {
                            tmp.Items.Add(os);
                        }
                        else
                        {
                            tmp.Items.Add(new OsuSong(s));
                        }
                    }

                    Playlists.Add(tmp);
                }
                sr.Close();
            }
            UpdatePlaylists();
        }
Ejemplo n.º 9
0
        //載入cache後檢查硬碟與cache中的osuSongs差異,並修正
        private void Refresh()
        {
            int   remove;
            int   add;
            float tookTime;

            DateTime beforeTime = DateTime.Now;
            //currentDirs = 當前硬碟上所有譜面資料夾
            List <string> currentDirs = new List <string>();

            foreach (DirectoryInfo di in songDir.GetDirectories())
            {
                foreach (FileInfo fi in di.GetFiles())
                {
                    if (fi.Extension == ".osu")
                    {
                        currentDirs.Add(fi.DirectoryName.ToLower());
                        break;
                    }
                }
            }

            //紀錄稍後需從osuSongs中移除的索引值
            Stack <int> needToRemove = new Stack <int>();

            for (int i = 0; i < osuSongs.Count; i++)
            {
                string dir   = osuSongs[i].OsuFilename;
                int    index = dir.LastIndexOf('\\');
                dir = dir.Remove(index, dir.Length - index).ToLower();

                //當前osuSongs中的osu file資料夾是否存在於 currentDirs
                //存在則從 currentDirs 中除名
                //不存在則紀錄index,並在稍後從osuSongs中移除
                //最後留下的 currentDirs 為目前osuSongs中沒有但硬碟上存在的osu file資料夾清單
                index = currentDirs.IndexOf(dir);
                if (index != -1)
                {
                    currentDirs.RemoveAt(index);
                }
                else
                {
                    needToRemove.Push(i);
                }
            }

            remove = needToRemove.Count;
            add    = currentDirs.Count;

            //songDir 資料夾無發生任何變化
            if (needToRemove.Count == 0 && currentDirs.Count == 0)
            {
                tookTime = (DateTime.Now - beforeTime).Milliseconds / (float)1000;
                SongListRefreshed(this, new SongListRefreshedEventArgs(osuSongs, remove, add, tookTime));
                return;
            }

            foreach (int index in needToRemove)
            {
                removeFromDictionary(osuSongs[index]);
                osuSongs.RemoveAt(index);
            }
            currentDirs.ForEach(path =>
            {
                foreach (FileInfo fi in new DirectoryInfo(path).GetFiles())
                {
                    if (fi.Extension == ".osu")
                    {
                        OsuSong os = new OsuSong(fi);
                        osuSongs.Add(os);
                        addToDictionary(os);
                        break;
                    }
                }
            });

            tookTime = (DateTime.Now - beforeTime).Milliseconds / (float)1000;

            ActiveSongListChangedEvent();
            SongListRefreshed(this, new SongListRefreshedEventArgs(osuSongs, remove, add, tookTime));
        }