static void ExportPsarc(string psarcFile, CmdOptions options) { var archiveName = Path.GetFileNameWithoutExtension(psarcFile); try { var browser = new PsarcBrowser(psarcFile); var songList = browser.GetSongList(); var toolkitInfo = browser.GetToolkitInfo(); if (options.ListSongs) { foreach (var song in songList) { Console.WriteLine("[{0}] {1} - {2} ({3}, {4}) {{{5}}}", song.Identifier, song.Artist, song.Title, song.Album, song.Year, string.Join(", ", song.Arrangements)); } return; } // collect all songs to convert var toConvert = new List <SongInfo>(); if (options.Tracks == null || options.Tracks.Count == 0) { // if nothing was specified, convert all songs toConvert = toConvert.Concat(songList).ToList(); } else { foreach (var songId in options.Tracks) { var songInfo = songList.FirstOrDefault(x => x.Identifier == songId); if (songInfo != null) { toConvert.Add(songInfo); } } } for (int i = 0; i < toConvert.Count; ++i) { var song = toConvert[i]; var score = new Score(); // figure out which arrangements to convert var arrangements = song.Arrangements; if (options.Arrangements != null && options.Arrangements.Count > 0) { arrangements = arrangements.Intersect(options.Arrangements).ToList(); } Console.WriteLine("({1}/{2}) Converting song {0} ...", song.Identifier, i + 1, toConvert.Count); foreach (var arr in arrangements) { var arrangement = browser.GetArrangement(song.Identifier, arr); if (arrangement == null) { Console.WriteLine(" Failed to get arrangement {0}", arr); continue; } if (arrangement.ArrangementProperties.Metronome == 1) { // CDLC feature: optional arrangements can be generated which feature only // metronome ticks, no music. However, the tab is identical to the normal // track, so we don't need this unless it was explicitly requested. if (options.Arrangements == null || options.Arrangements.Count == 0) { Console.WriteLine(" Arrangement {0} is a metronome track, ignore.", arr); continue; } } ExportArrangement(score, arrangement, arr, options.DifficultyLevel, psarcFile, toolkitInfo); if (options.SplitArrangements) { string baseFileName = ConstructFileName(options.FileNameFormat, score, song.Identifier, archiveName, toolkitInfo); baseFileName = CleanFileName(string.Format("{0} ({1})", baseFileName, arr)); SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat); // remember to remove the track from the score again score.Tracks.Clear(); } } if (!options.SplitArrangements) { score.SortTracks(); string baseFileName = CleanFileName( ConstructFileName(options.FileNameFormat, score, song.Identifier, archiveName, toolkitInfo)); SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat); } } Console.WriteLine(); } catch (IOException e) { Console.WriteLine("Error encountered:"); Console.WriteLine(e.Message); } }
/// <summary> /// Load a PSARC file into memory and /// convert to GuitarPro file(s) /// </summary> /// <param name="inputFilePath"></param> /// <param name="outputDir"></param> /// <param name="songListShort"></param> /// <param name="outputFormat"></param> /// <param name="allDif"></param> public void PsarcToGp5(string inputFilePath, string outputDir, IList <SongInfoShort> songListShort = null, string outputFormat = "gp5", bool allDif = false) { Console.WriteLine("Opening archive {0} ...", inputFilePath); Console.WriteLine(); try { var browser = new PsarcBrowser(inputFilePath); var songList = browser.GetSongList(); var toolkitInfo = browser.GetToolkitInfo(); // collect all songs to convert var toConvert = new List <SongInfo>(); // if nothing was specified, convert all songs if (songListShort == null || songListShort.Count == 0) { toConvert = toConvert.Concat(songList).ToList(); } else { // convert only the user selected songs and arrangements toConvert = SongInfoShortToSongInfo(songListShort, songList); } foreach (var song in toConvert) { var score = new Score(); // get all default or user specified arrangements for the song var arrangements = song.Arrangements; Console.WriteLine("Converting song " + song.Identifier + "..."); foreach (var arr in arrangements) { var arrangement = (Song2014)browser.GetArrangement(song.Identifier, arr); // get maximum difficulty for the arrangement var mf = new ManifestFunctions(GameVersion.RS2014); int maxDif = mf.GetMaxDifficulty(arrangement); if (allDif) // create separate file for each difficulty { for (int difLevel = 0; difLevel <= maxDif; difLevel++) { ExportArrangement(score, arrangement, difLevel, inputFilePath, toolkitInfo); Console.WriteLine("Difficulty Level: {0}", difLevel); var baseFileName = CleanFileName( String.Format("{0} - {1}", score.Artist, score.Title)); baseFileName += String.Format(" ({0})", arr); baseFileName += String.Format(" (level {0:D2})", difLevel); SaveScore(score, baseFileName, outputDir, outputFormat); // remember to remove the track from the score again score.Tracks.Clear(); } } else // combine maximum difficulty arrangements into one file { Console.WriteLine("Maximum Difficulty Level: {0}", maxDif); ExportArrangement(score, arrangement, maxDif, inputFilePath, toolkitInfo); } } if (!allDif) // only maximum difficulty { var baseFileName = CleanFileName( String.Format("{0} - {1}", score.Artist, score.Title)); SaveScore(score, baseFileName, outputDir, outputFormat); } } Console.WriteLine(); } catch (IOException e) { Console.WriteLine("Error encountered:"); Console.WriteLine(e.Message); } }