public static Smap GetSmapFromSdat(string pSdatPath) { Smap smap = new Smap(); string fullPath = Path.GetFullPath(pSdatPath); if (!File.Exists(fullPath)) { throw new FileNotFoundException(String.Format("Cannot find file <{0}>", fullPath)); } else { using (FileStream fs = File.OpenRead(fullPath)) { Type dataType = FormatUtil.getObjectType(fs); if (dataType != null && dataType.Name.Equals("Sdat")) { Sdat sdat = new Sdat(); sdat.Initialize(fs, fullPath); smap = new Smap(sdat); } } } return(smap); }
public static string ExtractSdat(string pSdatPath) { string fullPath = Path.GetFullPath(pSdatPath); string outputPath = null; string waveArcOutputPath; if (!File.Exists(fullPath)) { throw new FileNotFoundException(String.Format("Cannot find file <{0}>", fullPath)); } else { Swar swar = new Swar(); string swavOutputPath; using (FileStream fs = File.OpenRead(fullPath)) { Type dataType = FormatUtil.getObjectType(fs); if (dataType != null && dataType.Name.Equals("Sdat")) { string filePrefix = Path.GetFileNameWithoutExtension(fullPath); outputPath = Path.Combine(Path.GetDirectoryName(fullPath), filePrefix); Sdat sdat = new Sdat(); sdat.Initialize(fs, fullPath); sdat.ExtractBanks(fs, outputPath); sdat.ExtractSseqs(fs, outputPath); sdat.ExtractSeqArc(fs, outputPath); sdat.ExtractStrms(fs, outputPath); waveArcOutputPath = sdat.ExtractWaveArcs(fs, outputPath); // extract SWAVs if (!String.IsNullOrEmpty(waveArcOutputPath)) { foreach (string f in Directory.GetFiles(waveArcOutputPath, "*" + Swar.FILE_EXTENSION)) { using (FileStream swarFs = File.Open(f, FileMode.Open, FileAccess.Read)) { dataType = FormatUtil.getObjectType(swarFs); if (dataType != null && dataType.Name.Equals("Swar")) { swavOutputPath = Path.Combine(waveArcOutputPath, Path.GetFileNameWithoutExtension(f)); swar.Initialize(swarFs, f); ExtractAndWriteSwavFromSwar(swarFs, swar, swavOutputPath); } } } } sdat.BuildSmap(outputPath, filePrefix); } } } return(outputPath); }
public static void BuildPlaylistForFile(M3uBuilderStruct pM3uBuilderStruct) { using (FileStream fs = File.OpenRead(pM3uBuilderStruct.Path)) { Type dataType = FormatUtil.getObjectType(fs); System.Text.Encoding enc = System.Text.Encoding.ASCII; if (dataType != null && (typeof(IEmbeddedTagsFormat).IsAssignableFrom(dataType))) { string filename = Path.GetFileName(pM3uBuilderStruct.Path); string trackItem = String.Empty; INezPlugPlaylistFormat vgmData = (INezPlugPlaylistFormat)Activator.CreateInstance(dataType); fs.Seek(0, SeekOrigin.Begin); vgmData.Initialize(fs, pM3uBuilderStruct.Path); string outputFile = Path.GetDirectoryName(pM3uBuilderStruct.Path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(pM3uBuilderStruct.Path) + ".m3u"; using (StreamWriter sw = File.CreateText(outputFile)) { sw.WriteLine("#######################################################"); sw.WriteLine("#"); sw.WriteLine("# Game: " + enc.GetString(FileUtil.ReplaceNullByteWithSpace(vgmData.SongName)).Trim()); sw.WriteLine("# Artist: " + enc.GetString(FileUtil.ReplaceNullByteWithSpace(vgmData.SongArtist)).Trim()); sw.WriteLine("# Copyright: " + enc.GetString(FileUtil.ReplaceNullByteWithSpace(vgmData.SongCopyright)).Trim()); sw.WriteLine("#"); sw.WriteLine("#######################################################"); sw.WriteLine(); for (int i = vgmData.StartingSong[0] - 1; i < vgmData.TotalSongs[0]; i++) { if (pM3uBuilderStruct.UseKnurekFormatParsing) { trackItem = BuildKnurekFormatPlaylistTrackItem(i, vgmData, pM3uBuilderStruct.Path); } else { trackItem = BuildPlaylistTrackItem(i, vgmData, pM3uBuilderStruct.Path); } sw.WriteLine(trackItem); if (pM3uBuilderStruct.OnePlaylistPerFile) { BuildSingleFilePlaylist(pM3uBuilderStruct.Path, vgmData, trackItem, i); } else if (pM3uBuilderStruct.UseKnurekFormatParsing) { BuildSingleFileKnurekFormatPlaylist(pM3uBuilderStruct.Path, vgmData, trackItem, i); } } } // using (StreamWriter sw...) } } }
public static bool IsGenhFile(string path) { bool ret = false; using (FileStream typeFs = File.Open(path, FileMode.Open, FileAccess.Read)) { Type dataType = FormatUtil.getObjectType(typeFs); if (dataType != null && dataType.Name.Equals("Genh")) { ret = true; } } return(ret); }
public static void BuildM3uForFile(NsfM3uBuilderStruct pNsfM3uBuilderStruct) { using (FileStream fs = File.OpenRead(pNsfM3uBuilderStruct.Path)) { Type dataType = FormatUtil.getObjectType(fs); System.Text.Encoding enc = System.Text.Encoding.ASCII; if (dataType != null && dataType.Name.Equals("Nsfe")) { string filename = Path.GetFileName(pNsfM3uBuilderStruct.Path); string trackItem = String.Empty; Nsfe nsfeData = new Nsfe(); fs.Seek(0, SeekOrigin.Begin); nsfeData.Initialize(fs, pNsfM3uBuilderStruct.Path); string outputFile = Path.GetDirectoryName(pNsfM3uBuilderStruct.Path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(pNsfM3uBuilderStruct.Path) + ".m3u"; using (StreamWriter sw = File.CreateText(outputFile)) { string[] playlist = nsfeData.Playlist.Split(','); sw.WriteLine("#######################################################"); sw.WriteLine("#"); sw.WriteLine("# Game: " + nsfeData.SongName); sw.WriteLine("# Artist: " + nsfeData.SongArtist); sw.WriteLine("# Copyright: " + nsfeData.SongCopyright); sw.WriteLine("# Ripper: " + nsfeData.NsfRipper); sw.WriteLine("#"); sw.WriteLine("#######################################################"); sw.WriteLine(); // Build by playlist if it exists if (!String.IsNullOrEmpty(nsfeData.Playlist)) { int fileIndex = 1; int index; foreach (string s in nsfeData.Playlist.Split(',')) { index = int.Parse(s.Trim()); trackItem = NsfUtil.BuildTrackItem(index, nsfeData, pNsfM3uBuilderStruct.Path); sw.WriteLine(trackItem); if (pNsfM3uBuilderStruct.OnePlaylistPerFile) { NsfUtil.BuildSingleFileM3u(pNsfM3uBuilderStruct.Path, nsfeData, trackItem, fileIndex, index); } fileIndex++; } } // Use default order if playlist does not exist else { // !!! CHANGE TO START FROM nsfeData.StartingSong??????? for (int i = 0; i < nsfeData.TotalSongs[0]; i++) { trackItem = NsfUtil.BuildTrackItem(i, nsfeData, pNsfM3uBuilderStruct.Path); sw.WriteLine(trackItem); if (pNsfM3uBuilderStruct.OnePlaylistPerFile) { NsfUtil.BuildSingleFileM3u(pNsfM3uBuilderStruct.Path, nsfeData, trackItem, i, i); } } } } NsfUtil.NsfeToNsf(nsfeData, pNsfM3uBuilderStruct.Path); } } }