private void ScanForSongsRecursively(object folder)
    {
        List <SongInfo> list = new List <SongInfo>();

        string[] chartFiles    = Directory.GetFiles(dir, "*.chart", SearchOption.AllDirectories);
        string[] midFiles      = Directory.GetFiles(dir, "*.mid", SearchOption.AllDirectories);
        string[] combinedFiles = chartFiles.Concat(midFiles).ToArray();

        foreach (string s in combinedFiles)
        {
            switch (s.Substring(s.Length - 1, 1))
            {
            case "t":
                try
                {
                    ChartReader testReader        = new ChartReader();
                    Song        _testCurrentChart = new Song();
                    _testCurrentChart = testReader.ReadChartFile(s);
                    list.Add(CreateSongInfo(s, Song.ChartType.chart));
                }
                catch (Exception e)
                {
                }
                break;

            case "d":
                try
                {
                    SongMID midFile = MidReader.ReadMidi(s, false);
                    ChartWriter.WriteChart(midFile, dir + "/notes.chart", false);
                    ChartReader testReader        = new ChartReader();
                    Song        _testCurrentChart = new Song();
                    _testCurrentChart = testReader.ReadChartFile(@dir + "/notes.chart");
                    File.Delete(@dir + "/notes.chart");
                    list.Add(CreateSongInfo(s, Song.ChartType.mid));
                }
                catch (Exception e)
                {
                }
                break;
            }
        }

        lock (lockObject)
        {
            songs = list;
        }
    }
示例#2
0
    private IEnumerator SendRequest(string url)
    {
        using (UnityWebRequest request = UnityWebRequest.Get(url))
        {
            yield return(request.SendWebRequest());

            // entire file is returned via downloadHandler
            ChartReader chartReader = new ChartReader();
            Chart = chartReader.ReadChartFile(request.downloadHandler.text);
            print(request.downloadHandler.text);
            // or
            //byte[] fileContents = request.downloadHandler.data;

            // do whatever you need to do with the file contents
        }
    }
    private SongInfo CreateSongInfo(string s, Song.ChartType type)
    {
        SongInfo temp = new SongInfo();

        string path = Path.GetDirectoryName(s);

        string[] songINIFile = Directory.GetFiles(path, "*.ini", SearchOption.AllDirectories);

        if (songINIFile.Length > 0 && File.Exists(path + "//song.ini"))
        {
            foreach (string line in File.ReadAllLines(path + "//song.ini"))
            {
                if (line.Contains("artist ") || line.Contains("artist="))
                {
                    string spaceRemove = line.Replace("= ", "=").Replace(" =", "=");
                    temp.Artist = spaceRemove.Substring(7);
                }

                if (line.Contains("name ") || line.Contains("name="))
                {
                    string spaceRemove = line.Replace("= ", "=").Replace(" =", "=");
                    temp.SongName = spaceRemove.Substring(5);
                }

                if (line.Contains("charter ") || line.Contains("charter="))
                {
                    string spaceRemove = line.Replace("= ", "=").Replace(" =", "=");
                    temp.Charter = spaceRemove.Substring(8);
                }
                if (line.Contains("album ") || line.Contains("album="))
                {
                    string spaceRemove = line.Replace("= ", "=").Replace(" =", "=");
                    temp.Album = spaceRemove.Substring(6);
                }

                if (line.Contains("delay ") || line.Contains("delay="))
                {
                    string spaceRemove = line.Replace("= ", "=").Replace(" =", "=");
                    temp.offset = Math.Abs((long)Convert.ToUInt64(spaceRemove.Substring(6)));
                }

                if (line.Contains("preview_start_time ") || line.Contains("preview_start_time="))
                {
                    string spaceRemove = line.Replace("= ", "=").Replace(" =", "=");
                    string value       = spaceRemove.Substring(19);
                    uint   _time       = 0;
                    uint.TryParse(value, out _time);
                    long time = Math.Abs(_time);
                    temp.PreviewStartTime = time;
                }
            }
            temp.type        = type;
            temp.fileLoction = s;

            return(temp);
        }
        else
        {
            ChartReader chartReader   = new ChartReader();
            Song        _currentChart = new Song();
            _currentChart = chartReader.ReadChartFile(s);

            temp.Artist           = _currentChart.data.info.chartArtist;
            temp.SongName         = _currentChart.data.info.chartName;
            temp.Charter          = _currentChart.data.info.chartCharter;
            temp.PreviewStartTime = (long)_currentChart.data.info.previewStart;
            temp.type             = type;
            temp.offset           = (long)_currentChart.data.info.offset;
            temp.Album            = "Album Unknown";
            temp.fileLoction      = s;
        }

        return(temp);
    }