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); }
private void Make2sfFiles(Mk2sfStruct pMk2sfStruct) { string sdatDestinationPath; string TwoSFDestinationPath; string sdatPrefix; string testpackDestinationPath; string unallowedDestinationPath; string strmDestinationPath; Sdat sdat; // Build Paths if (String.IsNullOrEmpty(pMk2sfStruct.GameSerial)) { sdatDestinationPath = Path.Combine(pMk2sfStruct.DestinationFolder, Path.GetFileName(pMk2sfStruct.SourcePath)); } else { sdatDestinationPath = Path.Combine(pMk2sfStruct.DestinationFolder, pMk2sfStruct.GameSerial + Path.GetExtension(pMk2sfStruct.SourcePath)); } TwoSFDestinationPath = Path.Combine(pMk2sfStruct.DestinationFolder, Path.GetFileNameWithoutExtension(sdatDestinationPath)); sdatPrefix = Path.GetFileNameWithoutExtension(sdatDestinationPath); testpackDestinationPath = Path.Combine(pMk2sfStruct.DestinationFolder, Path.GetFileName(TESTPACK_FULL_PATH)); unallowedDestinationPath = Path.Combine(TwoSFDestinationPath, "UnAllowed Sequences"); strmDestinationPath = TwoSFDestinationPath; // Copy SDAT to destination folder try { File.Copy(pMk2sfStruct.SourcePath, sdatDestinationPath, false); } catch (Exception sdatException) { throw new IOException(String.Format("Error: Cannot copy SDAT <{0}> to destination directory: {1}.", sdatDestinationPath, sdatException.Message)); } // Copy STRMs this.progressStruct.Clear(); this.progressStruct.GenericMessage = "Copying STRM files" + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, progressStruct); using (FileStream sdatStream = File.OpenRead(sdatDestinationPath)) { sdat = new Sdat(); sdat.Initialize(sdatStream, sdatDestinationPath); sdat.ExtractStrms(sdatStream, strmDestinationPath); } // Update Volume for (int i = 0; i < pMk2sfStruct.VolumeChangeList.Length; i++) { if (pMk2sfStruct.VolumeChangeList[i].newValue != pMk2sfStruct.VolumeChangeList[i].oldValue) { sdat.UpdateSseqVolume(i, pMk2sfStruct.VolumeChangeList[i].newValue); } } // Optimize SDAT this.progressStruct.Clear(); this.progressStruct.GenericMessage = "Optimizing SDAT" + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, progressStruct); using (FileStream sdatStream = File.OpenRead(sdatDestinationPath)) { sdat = new Sdat(); sdat.Initialize(sdatStream, sdatDestinationPath); } sdat.OptimizeForZlib(pMk2sfStruct.AllowedSequences); // Copy testpack.nds File.Copy(TESTPACK_FULL_PATH, testpackDestinationPath, true); // Create 2SF output path if (!Directory.Exists(TwoSFDestinationPath)) { Directory.CreateDirectory(TwoSFDestinationPath); } // Build 2SFs this.progressStruct.Clear(); this.progressStruct.GenericMessage = "Build 2SFs" + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, progressStruct); XsfUtil.Make2sfSet(testpackDestinationPath, sdatDestinationPath, GetMinAllowedSseq(pMk2sfStruct.AllowedSequences), GetMaxAllowedSseq(pMk2sfStruct.AllowedSequences), TwoSFDestinationPath); // Move unallowed Sequences string unallowedFileName; string unallowedFilePath; foreach (int unallowedSequenceNumber in pMk2sfStruct.UnAllowedSequences) { unallowedFileName = String.Format("{0}-{1}.mini2sf", sdatPrefix, unallowedSequenceNumber.ToString("x4")); unallowedFilePath = Path.Combine(TwoSFDestinationPath, unallowedFileName); if (!Directory.Exists(unallowedDestinationPath)) { Directory.CreateDirectory(unallowedDestinationPath); } if (File.Exists(unallowedFilePath)) { File.Copy(unallowedFilePath, Path.Combine(unallowedDestinationPath, unallowedFileName), true); File.Delete(unallowedFilePath); } } // Add Tags this.progressStruct.Clear(); this.progressStruct.GenericMessage = "Tagging Output" + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, progressStruct); XsfBasicTaggingStruct tagStruct = new XsfBasicTaggingStruct(); tagStruct.TagArtist = pMk2sfStruct.TagArtist; tagStruct.TagCopyright = pMk2sfStruct.TagCopyright; tagStruct.TagYear = pMk2sfStruct.TagYear; tagStruct.TagGame = pMk2sfStruct.TagGame; tagStruct.TagComment = "uses Legacy of Ys: Book II driver hacked by Caitsith2"; tagStruct.TagXsfByTagName = "-2sfby"; tagStruct.TagXsfByTagValue = "VGMToolbox"; string taggingBatchPath = XsfUtil.BuildBasicTaggingBatch(TwoSFDestinationPath, tagStruct, "*.mini2sf"); XsfUtil.ExecutePsfPointBatchScript(taggingBatchPath, true); // Time 2SFs this.progressStruct.Clear(); this.progressStruct.GenericMessage = "Timing Output" + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, progressStruct); string outputTimerMessages; Time2sfStruct timerStruct = new Time2sfStruct(); timerStruct.DoSingleLoop = false; timerStruct.Mini2sfDirectory = TwoSFDestinationPath; timerStruct.SdatPath = pMk2sfStruct.SourcePath; XsfUtil.Time2sfFolder(timerStruct, out outputTimerMessages); // Delete Files this.progressStruct.Clear(); this.progressStruct.GenericMessage = "Cleaning Up" + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, progressStruct); if (File.Exists(sdatDestinationPath)) { File.Delete(sdatDestinationPath); } if (File.Exists(testpackDestinationPath)) { File.Delete(testpackDestinationPath); } }