/// <summary> /// Writes the DLCSong to disk within the given directory. /// For example given a song called "custom" and a directory called J:\customs, /// you'll end up with J:\customs\custom\custom.mogg, J:\customs\custom\custom.rbsong, etc /// </summary> /// <param name="song">The song to write</param> /// <param name="dir">The parent directory of the song directory</param> public static void WriteDLCSong(DLCSong song, string dir) { var shortname = song.SongData.Shortname; var songPath = Path.Combine(dir, "songs", shortname); Directory.CreateDirectory(songPath); using (var lipsyncFile = File.OpenWrite(Path.Combine(songPath, $"{shortname}.lipsync_ps4"))) { new LipsyncWriter(lipsyncFile).WriteStream(song.Lipsync); } using (var mogg = File.OpenWrite(Path.Combine(songPath, $"{shortname}.mogg"))) using (var conMogg = song.Mogg.GetStream()) { conMogg.CopyTo(mogg); } File.WriteAllText(Path.Combine(songPath, $"{shortname}.mogg.dta"), song.MoggDta.ToFileString()); File.WriteAllText(Path.Combine(songPath, shortname + ".moggsong"), song.MoggSong.ToFileString()); using (var rbmid = File.OpenWrite(Path.Combine(songPath, $"{shortname}.rbmid_ps4"))) RBMidWriter.WriteStream(song.RBMidi, rbmid); using (var rbsongFile = File.OpenWrite(Path.Combine(songPath, $"{shortname}.rbsong"))) new RBSongWriter(rbsongFile).WriteStream(song.RBSong); using (var songdtaFile = File.OpenWrite(Path.Combine(songPath, $"{shortname}.songdta_ps4"))) SongDataWriter.WriteStream(song.SongData, songdtaFile); if (song.SongData.AlbumArt) { using (var artFile = File.OpenWrite(Path.Combine(songPath, $"{shortname}.png_ps4"))) Texture.TextureWriter.WriteStream(song.Artwork, artFile); } }
/// <summary> /// Generates a 16-char ID for a PKG /// </summary> /// <param name="song">Song to use for generation</param> /// <returns>16 char id</returns> public static string GenId(DLCSong song) { var shortname = new Regex("[^a-zA-Z0-9]").Replace(song.SongData.Shortname, ""); var pkgName = shortname.ToUpper().Substring(0, Math.Min(shortname.Length, 12)).PadRight(12, 'X'); string pkgNum = (song.SongData.SongId % 10000).ToString().PadLeft(4, '0'); return(pkgName + pkgNum); }
public static void DLCSongToFsFiles(DLCSong song, FSDir songsDir) { var shortname = song.SongData.Shortname; var songDir = new FSDir() { name = shortname, Parent = songsDir }; songsDir.Dirs.Add(songDir); songDir.Files.Add(WriterToFile( $"{shortname}.lipsync_ps4", s => new LipsyncWriter(s).WriteStream(song.Lipsync))); songDir.Files.Add(new FSFile( s => { using (var mogg = song.Mogg.GetStream()) mogg.CopyTo(s); }, $"{shortname}.mogg", song.Mogg.Size)); var moggFileString = Encoding.UTF8.GetBytes(song.MoggDta.ToFileString()); songDir.Files.Add(new FSFile( s => s.Write(moggFileString, 0, moggFileString.Length), $"{shortname}.mogg.dta", moggFileString.Length)); var moggSongFileString = Encoding.UTF8.GetBytes(song.MoggSong.ToFileString()); songDir.Files.Add(new FSFile( s => s.Write(moggSongFileString, 0, moggSongFileString.Length), $"{shortname}.moggsong", moggSongFileString.Length)); songDir.Files.Add(WriterToFile( $"{shortname}.rbmid_ps4", s => RBMidWriter.WriteStream(song.RBMidi, s))); songDir.Files.Add(WriterToFile( $"{shortname}.rbsong", s => new RBSongWriter(s).WriteStream(song.RBSong))); songDir.Files.Add(WriterToFile( $"{shortname}.songdta_ps4", s => SongDataWriter.WriteStream(song.SongData, s))); if (song.SongData.AlbumArt) { songDir.Files.Add(WriterToFile( $"{shortname}.png_ps4", s => Texture.TextureWriter.WriteStream(song.Artwork, s))); } foreach (var f in songDir.Files) { f.Parent = songDir; } }