private PsxSequenceType getPsxSequenceType(string filePath) { PsxSequenceType ret = PsxSequenceType.None; if (PsxSequence.IsSeqTypeSequence(filePath)) { ret = PsxSequenceType.SeqType; } else if (PsxSequence.IsSepTypeSequence(filePath)) { ret = PsxSequenceType.SepType; } else { this.progressStruct.Clear(); this.progressStruct.FileName = filePath; this.progressStruct.ErrorMessage = String.Format("ERROR: Cannot parse <{0}> as SEQ or SEP type sequence file.{1}", filePath, Environment.NewLine); ReportProgress(this.progress, this.progressStruct); } return(ret); }
protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPsxSepToSeqExtractorStruct, DoWorkEventArgs e) { PsxSepToSeqExtractorStruct psxSepToSeqExtractorStruct = (PsxSepToSeqExtractorStruct)pPsxSepToSeqExtractorStruct; if (PsxSequence.IsSepTypeSequence(pPath)) { uint seqCount = PsxSequence.GetSeqCount(pPath); string extractedFileName; for (uint i = 0; i < seqCount; i++) { extractedFileName = PsxSequence.ExtractSeqFromSep(pPath, i); this.progressStruct.Clear(); this.progressStruct.FileName = pPath; this.progressStruct.GenericMessage = String.Format("<{0}> extracted.{1}", extractedFileName, Environment.NewLine); this.ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } }
protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPsxSeqExtractStruct, DoWorkEventArgs e) { PsxSeqExtractStruct psxSeqExtractStruct = (PsxSeqExtractStruct)pPsxSeqExtractStruct; int minutes; double seconds; int loopStartMinutes = 0; double loopStartSeconds = 0; int loopEndMinutes = 0; double loopEndSeconds = 0; StringBuilder batchFile = new StringBuilder(); string batchFilePath; string extractedSq = XsfUtil.ExtractPsxSequenceForTiming(pPath, psxSeqExtractStruct.forceSepType, psxSeqExtractStruct.SepSeqOffset, psxSeqExtractStruct.SepSeqIndexLength, -1); if (!String.IsNullOrEmpty(extractedSq)) { PsxSequence psxSeq = null; using (FileStream fs = File.OpenRead(extractedSq)) { PsxSequence.PsxSqInitStruct initStruct = new PsxSequence.PsxSqInitStruct(); initStruct.force2Loops = psxSeqExtractStruct.force2Loops; initStruct.forceOppositeFormatType = false; initStruct.forceSepType = psxSeqExtractStruct.forceSepType; initStruct.forceSeqType = psxSeqExtractStruct.forceSeqType; try { psxSeq = new PsxSequence(fs, initStruct); } catch (PsxSeqFormatException) { // sometimes the version number is wrong, (Devil Summoner 1-50b.minipsf) initStruct.forceOppositeFormatType = true; psxSeq = new PsxSequence(fs, initStruct); } } if (psxSeq != null) { double timingInfoSeconds = psxSeq.TimingInfo.TimeInSeconds; double loopStartInSeconds = psxSeq.TimingInfo.LoopStartInSeconds; double loopEndInSeconds = psxSeq.TimingInfo.LoopEndInSeconds; int timingInfoFadeInSeconds = psxSeq.TimingInfo.FadeInSeconds; // loop entire track if (psxSeqExtractStruct.loopEntireTrack) { timingInfoSeconds = 2d * psxSeq.TimingInfo.TimeInSeconds; timingInfoFadeInSeconds = 10; } // Add line to batch file. minutes = (int)(timingInfoSeconds / 60d); seconds = timingInfoSeconds - (minutes * 60); // seconds = Math.Ceiling(seconds); if (loopStartInSeconds > -1) { loopStartMinutes = (int)(loopStartInSeconds / 60d); loopStartSeconds = loopStartInSeconds - (loopStartMinutes * 60); } if (loopEndInSeconds > -1) { loopEndMinutes = (int)(loopEndInSeconds / 60d); loopEndSeconds = loopEndInSeconds - (loopEndMinutes * 60); } // shouldn't be needed without Math.Ceiling call, but whatever if (seconds >= 60) { minutes++; seconds -= 60d; } if ((loopStartInSeconds > -1) && (loopEndInSeconds > -1)) { batchFile.AppendLine( String.Format( "REM {0}: Loop Start: {1}:{2} Loop Finish: {3}:{4}", Path.GetFileName(pPath), loopStartMinutes.ToString(), loopStartSeconds.ToString().PadLeft(2, '0'), loopEndMinutes.ToString(), loopEndSeconds.ToString().PadLeft(2, '0'))); } batchFile.AppendFormat("psfpoint.exe -length=\"{0}:{1}\" -fade=\"{2}\" \"{3}\"", minutes.ToString(), seconds.ToString().PadLeft(2, '0'), timingInfoFadeInSeconds.ToString(), Path.GetFileName(pPath)); batchFile.AppendLine(); batchFile.AppendLine(); batchFilePath = Path.Combine(Path.GetDirectoryName(pPath), BATCH_FILE_NAME); if (!File.Exists(batchFilePath)) { using (FileStream cfs = File.Create(batchFilePath)) { }; } using (StreamWriter sw = new StreamWriter(File.Open(batchFilePath, FileMode.Append, FileAccess.Write))) { sw.Write(batchFile.ToString()); } // report warnings if (!String.IsNullOrEmpty(psxSeq.TimingInfo.Warnings)) { this.progressStruct.Clear(); progressStruct.GenericMessage = String.Format("{0}{1} WARNINGS{2} {3}", pPath, Environment.NewLine, Environment.NewLine, psxSeq.TimingInfo.Warnings); ReportProgress(this.Progress, progressStruct); } } File.Delete(extractedSq); } }
private void buildPsfs(string[] pUniqueSequences, string[] pVhFiles, Bin2PsfStruct pBin2PsfStruct, DoWorkEventArgs e) { string ripOutputFolder = Path.Combine(OUTPUT_FOLDER, pBin2PsfStruct.outputFolder); string bin2PsfSourcePath = Path.Combine(PROGRAMS_FOLDER, "bin2psf.exe"); string bin2PsfDestinationPath = Path.Combine(WORKING_FOLDER, "bin2psf.exe"); string vhName; string vbName; string sepPsfLibExePath; string vhVbMiniPsfLibExePath; string exePath; string psfLibName; string filePrefix; PsxSequenceType sequenceType; int trackId; string originalExe; uint seqCount = 0; uint totalSequences = 1; PsfMakerTask task; try { // create working directory Directory.CreateDirectory(WORKING_FOLDER); // copy program File.Copy(bin2PsfSourcePath, bin2PsfDestinationPath, true); } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.ErrorMessage = ex.Message; ReportProgress(0, this.progressStruct); return; } // modify minipsf .exe for VH/VB lib and make .psflib if (pBin2PsfStruct.MakePsfLib) { // vhVbMiniPsfLibExePath = setMiniPsfValues(GENERIC_MINIPSF_EXE_PATH, pBin2PsfStruct, false); this.makePsfFile( PsfMakerTask.SeqPsfLib, pBin2PsfStruct, pBin2PsfStruct.exePath, null, pVhFiles[0], Path.ChangeExtension(pVhFiles[0], ".vb"), bin2PsfDestinationPath, ripOutputFolder, null, null, Path.GetFileNameWithoutExtension(pBin2PsfStruct.psflibName), -1, -1); } #region MAIN LOOP foreach (string sequenceFile in pUniqueSequences) { if (!CancellationPending) { originalExe = pBin2PsfStruct.exePath; sequenceType = this.getPsxSequenceType(sequenceFile); // get sequence count if (pBin2PsfStruct.ForceSepTrackNo && PsxSequence.IsSepTypeSequence(sequenceFile)) { seqCount = 1; // get actual number of sequences for SEP functions totalSequences = PsxSequence.GetSeqCount(sequenceFile); } else { seqCount = PsxSequence.GetSeqCount(sequenceFile); totalSequences = seqCount; } // Try combinations if (pBin2PsfStruct.TryCombinations) #region COMBINATIONS { // loop over VH/VB files foreach (string vhFile in pVhFiles) { try { // single sequence if (seqCount == 1) { if (sequenceType == PsxSequenceType.SeqType) { task = PsfMakerTask.SeqPsf; filePrefix = String.Format( "SEQ[{0}]_VAB[{1}]", Path.GetFileNameWithoutExtension(sequenceFile), Path.GetFileNameWithoutExtension(vhFile)); trackId = 0; } else // sequenceType == PsxSequenceType.SepType { task = PsfMakerTask.SepPsf; filePrefix = String.Format( "SEP[{0}]_VAB[{1}]", Path.GetFileNameWithoutExtension(sequenceFile), Path.GetFileNameWithoutExtension(vhFile)); if (pBin2PsfStruct.ForceSepTrackNo) { trackId = pBin2PsfStruct.SepTrackNo; } else { trackId = 0; } } this.makePsfFile( task, pBin2PsfStruct, pBin2PsfStruct.exePath, sequenceFile, vhFile, Path.ChangeExtension(vhFile, ".vb"), bin2PsfDestinationPath, ripOutputFolder, null, null, filePrefix, trackId, (int)totalSequences); } else if (seqCount > 1) // SEP only { task = PsfMakerTask.SepPsf; for (int i = 0; i < seqCount; i++) { filePrefix = String.Format( "SEP[{0}_{1}]_VAB[{2}]", Path.GetFileNameWithoutExtension(sequenceFile), i.ToString("X2"), Path.GetFileNameWithoutExtension(vhFile)); this.makePsfFile( task, pBin2PsfStruct, pBin2PsfStruct.exePath, sequenceFile, vhFile, Path.ChangeExtension(vhFile, ".vb"), bin2PsfDestinationPath, ripOutputFolder, null, null, filePrefix, i, (int)totalSequences); } } } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.FileName = sequenceFile; this.progressStruct.ErrorMessage = String.Format("{0}{1}", ex.Message, Environment.NewLine); ReportProgress(this.progress, this.progressStruct); } } } #endregion else // no combinations #region NO COMBINATIONS { // single sequence if (seqCount == 1) { filePrefix = Path.GetFileNameWithoutExtension(sequenceFile); if (sequenceType == PsxSequenceType.SeqType) { task = PsfMakerTask.SeqPsf; trackId = 0; } else // sequenceType == PsxSequenceType.SepType { task = PsfMakerTask.SepPsf; if (pBin2PsfStruct.ForceSepTrackNo) { trackId = pBin2PsfStruct.SepTrackNo; } else { trackId = 0; } } if (pBin2PsfStruct.MakePsfLib) { vhName = null; vbName = null; if (sequenceType == PsxSequenceType.SeqType) { task = PsfMakerTask.SeqMiniPsf; vhVbMiniPsfLibExePath = setMiniPsfValues(GENERIC_MINIPSF_EXE_PATH, pBin2PsfStruct, false); } else // sequenceType == PsxSequenceType.SepType { task = PsfMakerTask.SepPsfWithVhVbLib; vhVbMiniPsfLibExePath = setMiniPsfValues(GENERIC_MINIPSF_EXE_PATH, pBin2PsfStruct, true); } exePath = vhVbMiniPsfLibExePath; } else { vhName = Path.ChangeExtension(sequenceFile, ".vh"); vbName = Path.ChangeExtension(sequenceFile, ".vb"); exePath = pBin2PsfStruct.exePath; if (sequenceType == PsxSequenceType.SeqType) { task = PsfMakerTask.SeqPsf; } else // sequenceType == PsxSequenceType.SepType { task = PsfMakerTask.SepPsf; } } try { this.makePsfFile( task, pBin2PsfStruct, exePath, sequenceFile, vhName, vbName, bin2PsfDestinationPath, ripOutputFolder, pBin2PsfStruct.psflibName, null, filePrefix, trackId, (int)totalSequences); } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.FileName = sequenceFile; this.progressStruct.ErrorMessage = String.Format("{0}{1}", ex.Message, Environment.NewLine); ReportProgress(this.progress, this.progressStruct); } } else if (seqCount > 1) // SEP only { // make SEP psflib psfLibName = Path.GetFileName(Path.ChangeExtension(sequenceFile, PSFLIB_FILE_EXTENSION)); if (pBin2PsfStruct.MakePsfLib) { vhName = null; vbName = null; task = PsfMakerTask.SepMiniPsfWithVhVbLib; // sepPsfLibExePath = setMiniPsfValues(GENERIC_MINIPSF_EXE_PATH, pBin2PsfStruct, true); sepPsfLibExePath = setMiniPsfValues(GENERIC_MINIPSF_EXE_PATH, pBin2PsfStruct, false); } else { vhName = Path.ChangeExtension(sequenceFile, ".vh"); vbName = Path.ChangeExtension(sequenceFile, ".vb"); task = PsfMakerTask.SepMiniPsf; sepPsfLibExePath = pBin2PsfStruct.exePath; } this.makePsfFile( PsfMakerTask.SepPsfLib, pBin2PsfStruct, sepPsfLibExePath, sequenceFile, vhName, vbName, bin2PsfDestinationPath, ripOutputFolder, null, null, Path.GetFileNameWithoutExtension(psfLibName), -1, -1); // create minipsfs sepPsfLibExePath = setMiniPsfValues(GENERIC_MINIPSF_EXE_PATH, pBin2PsfStruct, true); for (int i = 0; i < seqCount; i++) { if (!CancellationPending) { filePrefix = String.Format( "{0}_{1}", Path.GetFileNameWithoutExtension(sequenceFile), i.ToString("X2")); this.makePsfFile( task, pBin2PsfStruct, sepPsfLibExePath, null, null, null, bin2PsfDestinationPath, ripOutputFolder, pBin2PsfStruct.psflibName, psfLibName, filePrefix, i, (int)totalSequences); } else { e.Cancel = true; return; } // if (!CancellationPending) } } } #endregion } else { e.Cancel = true; return; } } #endregion // delete working folder try { Directory.Delete(WORKING_FOLDER, true); } catch (Exception ex2) { this.progressStruct.Clear(); this.progressStruct.ErrorMessage = ex2.Message; ReportProgress(100, this.progressStruct); } }
private void makePsfs(Bin2PsfStruct pBin2PsfStruct, DoWorkEventArgs e) { string[] sqFiles; string[] vhFiles; string[] sepFiles; string[] uniqueSequences; uint seqCount; if (!CancellationPending) { // get list of unique files sqFiles = this.getUniqueFileNames(pBin2PsfStruct.sourcePath, "*.SEQ"); vhFiles = this.getUniqueFileNames(pBin2PsfStruct.sourcePath, "*.VH"); sepFiles = this.getUniqueFileNames(pBin2PsfStruct.sourcePath, "*.SEP"); uniqueSequences = new string[sqFiles.Length + sepFiles.Length]; Array.ConstrainedCopy(sqFiles, 0, uniqueSequences, 0, sqFiles.Length); Array.ConstrainedCopy(sepFiles, 0, uniqueSequences, sqFiles.Length, sepFiles.Length); if (uniqueSequences != null) { // calculate max file if (pBin2PsfStruct.TryCombinations) { foreach (string sequence in uniqueSequences) { if (pBin2PsfStruct.ForceSepTrackNo && PsxSequence.IsSepTypeSequence(sequence)) { seqCount = 1; } else { seqCount = PsxSequence.GetSeqCount(sequence); } this.maxFiles += (int)seqCount * vhFiles.Length; } } else { foreach (string sequence in uniqueSequences) { if (pBin2PsfStruct.ForceSepTrackNo && PsxSequence.IsSepTypeSequence(sequence)) { seqCount = 1; } else { seqCount = PsxSequence.GetSeqCount(sequence); } if (seqCount > 1) { this.maxFiles += (int)seqCount + 1; } else { this.maxFiles += (int)seqCount; } } } // check psflib counts if (pBin2PsfStruct.MakePsfLib) { this.maxFiles++; if (vhFiles.Length > 1) { this.progressStruct.Clear(); this.progressStruct.ErrorMessage = String.Format("ERROR: More than 1 VH/VB pair detected, please only include 1 VH/VB pair when making .psflib files{0}", Environment.NewLine); ReportProgress(this.progress, this.progressStruct); return; } } } // build PSFs this.buildPsfs(uniqueSequences, vhFiles, pBin2PsfStruct, e); } else { e.Cancel = true; return; } return; }