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); }
private void LoadComboBox(string pSourcePath) { Smap.SmapSeqStruct s; this.dataGridSseq.Rows.Clear(); if (Sdat.IsSdat(pSourcePath)) { Smap smap = SdatUtil.GetSmapFromSdat(pSourcePath); DataGridViewRow row = new DataGridViewRow(); if ((smap.SseqSection != null) && (smap.SseqSection.Length > 0)) { // get duplicates list ArrayList duplicatesList = SdatUtil.GetDuplicateSseqsList(pSourcePath); // setup volume tracking struct this.sseqVolumeList = new Mk2sfWorker.VolumeChangeStruct[smap.SseqSection.Length]; // foreach (Smap.SmapSeqStruct s in smap.SseqSection) for (int i = 0; i < smap.SseqSection.Length; i++) { s = smap.SseqSection[i]; row = new DataGridViewRow(); row.CreateCells(this.dataGridSseq); row.Cells[1].Value = s.number.ToString("x4"); if (!String.IsNullOrEmpty(s.name)) { row.Cells[0].Value = true; row.Cells[2].Value = s.fileID.ToString(); row.Cells[3].Value = s.size.ToString().PadLeft(6, '0'); row.Cells[4].Value = s.name.ToString(); row.Cells[5].Value = s.bnk.ToString(); row.Cells[6].Value = s.vol.ToString(); row.Cells[7].Value = s.cpr.ToString(); row.Cells[8].Value = s.ppr.ToString(); row.Cells[9].Value = s.ply.ToString(); // add volume tracking this.sseqVolumeList[i].oldValue = s.vol; this.sseqVolumeList[i].newValue = s.vol; // check for duplicate if (duplicatesList.Contains(i)) { row.Cells[0].Value = false; row.DefaultCellStyle.BackColor = Color.Crimson; } } else { row.Cells[0].Value = false; } this.dataGridSseq.Rows.Add(row); } } } }
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); }