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); } } }
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; }