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); }
static void Main(string[] args) { string pathTo2sf; string pathToSdat; string filePrefix; string smapPath = String.Empty; bool processSuccess = false; string emptyFolderFileName; if (args.Length != 3) { usage(); return; } else { pathTo2sf = args[0]; pathToSdat = args[1]; filePrefix = args[2]; } if (!Directory.Exists(pathTo2sf)) { Console.WriteLine(String.Format("Cannot find directory <{0}>", pathTo2sf)); return; } if (!File.Exists(pathToSdat)) { Console.WriteLine(String.Format("Cannot find file <{0}>", pathToSdat)); return; } if (!String.IsNullOrEmpty(smapPath) && !File.Exists(smapPath)) { Console.WriteLine(String.Format("Cannot find file <{0}>", smapPath)); return; } string sseq2MidPath = Path.Combine(Path.Combine(".", "helper"), "sseq2mid.exe"); string psfpointPath = Path.Combine(Path.Combine(".", "helper"), "psfpoint.exe"); // delete old .bat file string psfpointBatchFilePath = Path.Combine(Path.Combine(pathTo2sf, "text"), PSFPOINT_BATCH_TXT); Console.WriteLine(); if (File.Exists(psfpointBatchFilePath)) { Console.WriteLine("Deleting Old Batch File"); File.Delete(psfpointBatchFilePath); } // Extract SDAT Console.WriteLine("Extracting SDAT"); string extractedSdatPath = Path.Combine(Path.GetDirectoryName(pathToSdat), Path.GetFileNameWithoutExtension(pathToSdat)); if (Directory.Exists(extractedSdatPath)) { extractedSdatPath += String.Format("_temp_{0}", new Random().Next().ToString()); } string extractedSseqPath = Path.Combine(extractedSdatPath, "Seq"); FileStream fs = File.Open(pathToSdat, FileMode.Open, FileAccess.Read); Sdat sdat = new Sdat(); sdat.Initialize(fs, pathToSdat); sdat.ExtractSseqs(fs, extractedSdatPath); fs.Close(); fs.Dispose(); // Make SMAP Console.WriteLine("Building Internal SMAP"); Smap smap = new Smap(sdat); // Loop through SMAP and build timing script Console.WriteLine("Building Timing Script"); string emptyFileDir = Path.Combine(pathTo2sf, EMPTY_FILE_DIRECTORY); int totalSequences = smap.SseqSection.Length; int i = 1; // Initialize Bass if (smap.SseqSection.Length > 0) { Console.WriteLine("Going to sleep for 5 seconds to avoid the freeware billboard..."); Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, null); Thread.Sleep(5000); Console.WriteLine("Ok, back to work..."); } foreach (Smap.SmapSeqStruct s in smap.SseqSection) { Console.Write("\r" + String.Format("Processing [{0}/{1}]", i.ToString().PadLeft(4, '0'), totalSequences.ToString().PadLeft(4, '0'))); string rippedFileName = String.Format("{0}-{1}.mini2sf", filePrefix, s.number.ToString("X4")); string rippedFilePath = Path.Combine(pathTo2sf, rippedFileName); // check if file is empty or not if (s.fileID == Smap.EMPTY_FILE_ID) { // move to empty dir if (!Directory.Exists(emptyFileDir)) { Directory.CreateDirectory(emptyFileDir); } if (File.Exists(rippedFilePath)) { emptyFolderFileName = Path.Combine(emptyFileDir, rippedFileName); File.Copy(rippedFilePath, emptyFolderFileName, true); File.Delete(rippedFilePath); } } else { string sseqFilePath = Path.Combine(extractedSseqPath, s.name); // convert sseq file to midi processSuccess = convertSseqFile(sseq2MidPath, pathTo2sf, sseqFilePath); // time file if (processSuccess) { processSuccess = buildFileTimingBatch(pathTo2sf, rippedFilePath, sseqFilePath); } } i++; } // run timing script Console.WriteLine(Environment.NewLine + "Executing Timing Script"); executeBatchScript(psfpointPath, pathTo2sf); // Cleanup Console.WriteLine("Cleaning Up"); doCleanup(extractedSdatPath, pathTo2sf, psfpointPath); }