Ejemplo n.º 1
0
        private void RBAPatchSongsDta(bool isRBS)
        {
            var fsongsraw = tempfolder + "songs.dta.raw";
            var fsongsdta = tempfolder + "songs.dta";

            try
            {
                // Create an instance of StreamReader to read from a file.
                using (var srSongsRaw = new StreamReader(fsongsraw, Encoding.Default))
                {
                    var swSongsDta = new StreamWriter(fsongsdta, false, Encoding.Default);
                    using (swSongsDta)
                    {
                        // copy the first line
                        var line = srSongsRaw.ReadLine();
                        swSongsDta.WriteLine(line);
                        // patch 'song' in the second line to be '<basename>'
                        line = srSongsRaw.ReadLine();
                        if (line != null && line.Contains("'song'"))
                        {
                            line = "   '" + basesongname + "'";
                        }
                        swSongsDta.WriteLine(line);
                        // Read and display lines from the file until the end of
                        // the file is reached.
                        while ((line = srSongsRaw.ReadLine()) != null)
                        {
                            if (line.Contains("'name'"))
                            {
                                swSongsDta.WriteLine(line);
                                line = srSongsRaw.ReadLine();
                                if (line != null && !line.Contains("songs/"))
                                {
                                    SongTitle = Parser.GetSongName(line);
                                }
                                // -          "songs/song/song" => "songs/<basename>/<basename"
                                if (line != null && line.Contains("songs/"))
                                {
                                    if (isRBS)
                                    {
                                        basesongname = Parser.GetInternalName(line);
                                    }
                                    else
                                    {
                                        line = "         \"songs/" + basesongname + "/" + basesongname + "\"";
                                    }
                                }
                            }
                            else if (line.Contains("songs/") && line.Contains(".mid"))
                            {
                                line = "         \"songs/" + basesongname + "/" + basesongname + ".mid";
                            }
                            else if (line.Contains("'artist'"))
                            {
                                swSongsDta.WriteLine(line);
                                line       = srSongsRaw.ReadLine();
                                SongArtist = Parser.GetArtistName(line);
                            }
                            // -    ('song_id' 0) => ('song_id' <basename>)
                            else if (line.Contains("('song_id' 0)"))
                            {
                                line = "   ('song_id' " + basesongname + ")";
                            }
                            else if (line.Contains("('real_bass' 0)") || line.Contains("('real_guitar' 0)"))
                            {
                                // Swallow this line - don't put it in the final songs.dta
                                // because it prevents you from making a separate upgrades.dta
                                //only if there is no pro bass in the song!
                                line = "";
                            }
                            if (line != "")
                            {
                                swSongsDta.WriteLine(line);
                            }
                            if (srSongsRaw.EndOfStream)
                            {
                                break;
                            }
                        }
                    }
                    swSongsDta.Dispose();
                    srSongsRaw.Dispose();
                }
            }
            catch (Exception ex)
            {
                Log("There was an error:");
                Log(ex.Message);
            }
        }