示例#1
0
        //加载音乐
        private void LoadMusic()
        {
            musicRootPath = GetString(Resource.String.music_root_path);
            File f = new File(musicRootPath);

            if (!f.Exists())
            {
                txtTitle.Text = "歌曲路径不存在!";
                this.Finish();
            }
            musicPath.Clear();
            File[] dirInfo = f.ListFiles();
            if (dirInfo.Length == 0)
            {
                txtTitle.Text = "歌单不存在!";
                this.Finish();
            }
            foreach (File NextFolder in dirInfo)
            {
                mysqlConnector.AddNewList(NextFolder.Name);
                if (NextFolder.IsFile)
                {
                    continue;
                }
                File[] fileInfo = NextFolder.ListFiles();
                foreach (File NextFile in fileInfo)
                {
                    Match match_nc = Regex.Match(NextFile.Name, @"(.*?)\s-\s(.*)\.mp3");
                    Match match_xm = Regex.Match(NextFile.Name, @"(.*?)_(.*)\.mp3");
                    if (match_nc.Success || match_xm.Success)
                    {
                        Match match    = match_nc.Success ? match_nc : match_xm;
                        int   nc_or_xm = match_nc.Success ? 2 : 1;
                        Music music    = new Music
                        {
                            musicPath    = NextFile.Path,
                            musicName    = match.Groups[nc_or_xm].ToString(),
                            fileName     = System.IO.Path.GetFileNameWithoutExtension(NextFile.Name),
                            belongToList = NextFolder.Name
                        };
                        Match singer_match = Regex.Match(match.Groups[3 - nc_or_xm].ToString(), @"(.*?)(、|&|\s|,)(.*)");
                        if (singer_match.Success)
                        {
                            music.singer      = singer_match.Groups[1].ToString();
                            music.otherSinger = singer_match.Groups[3].ToString();
                        }
                        else
                        {
                            music.singer = match.Groups[3 - nc_or_xm].ToString();
                        }
                        musicPath.Add(music);
                    }
                }
            }
        }