コード例 #1
0
        protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPsf2SettingsUpdaterStruct,
                                              DoWorkEventArgs e)
        {
            Psf2SettingsUpdaterStruct iniStruct = (Psf2SettingsUpdaterStruct)pPsf2SettingsUpdaterStruct;
            string workingFolder = String.Empty;

            //////////////////////
            // copy existing tags
            //////////////////////
            string formatString = XsfUtil.GetXsfFormatString(pPath);
            Dictionary <string, string> tagHash;
            Xsf psf2File, newPsf2File;

            if (!String.IsNullOrEmpty(formatString) &&
                formatString.Equals(Xsf.FormatNamePsf2))
            {
                try
                {
                    using (FileStream fs = File.Open(pPath, FileMode.Open, FileAccess.Read))
                    {
                        // initialize file
                        psf2File = new Xsf();
                        psf2File.Initialize(fs, pPath);

                        // copy tags
                        tagHash = psf2File.GetTagHash();
                    }

                    ///////////////
                    // unpack Psf2
                    ///////////////
                    workingFolder = Path.Combine(Path.GetDirectoryName(pPath), Path.GetFileNameWithoutExtension(pPath));
                    string unpackFolder = Path.Combine(workingFolder, "unpack_dir");
                    XsfUtil.UnpackPsf2(pPath, unpackFolder);

                    ///////////////////
                    // parse .ini file
                    ///////////////////
                    Psf2.Psf2IniSqIrxStruct originalIni;
                    string[] originalIniFiles = Directory.GetFiles(unpackFolder, "*.ini");

                    if (originalIniFiles.Length > 0)
                    {
                        using (FileStream iniFs = File.Open(originalIniFiles[0], FileMode.Open, FileAccess.Read))
                        {
                            originalIni = Psf2.ParseClsIniFile(iniFs);
                        }

                        ////////////////////
                        // update .ini file
                        ////////////////////
                        iniStruct.IniSettings = UpdateClsIniFile(iniStruct.IniSettings, originalIni, iniStruct.RemoveEmptySettings);
                        File.Delete(originalIniFiles[0]);
                        Psf2.WriteClsIniFile(iniStruct.IniSettings, originalIniFiles[0]);

                        ///////////////
                        // repack Psf2
                        ///////////////
                        string psf2FileName = Path.GetFileName(pPath);

                        ///////////////////
                        // copy mkpsf2.exe
                        ///////////////////
                        string mkpsf2Destination = Path.Combine(workingFolder, Path.GetFileName(MKPSF2_SOURCE_PATH));
                        File.Copy(MKPSF2_SOURCE_PATH, mkpsf2Destination, true);

                        //////////////////
                        // run mkpsf2.exe
                        //////////////////
                        string  arguments       = String.Format(" \"{0}\" \"{1}\"", psf2FileName, unpackFolder);
                        Process makePsf2Process = new Process();
                        makePsf2Process.StartInfo = new ProcessStartInfo(mkpsf2Destination, arguments);
                        makePsf2Process.StartInfo.UseShellExecute  = false;
                        makePsf2Process.StartInfo.CreateNoWindow   = true;
                        makePsf2Process.StartInfo.WorkingDirectory = workingFolder;
                        bool isSuccess = makePsf2Process.Start();
                        makePsf2Process.WaitForExit();
                        makePsf2Process.Close();
                        makePsf2Process.Dispose();

                        ////////////////
                        // replace tags
                        ////////////////
                        string newPsf2FilePath = Path.Combine(workingFolder, psf2FileName);

                        using (FileStream newFs = File.Open(newPsf2FilePath, FileMode.Open, FileAccess.Read))
                        {
                            // initialize new file
                            newPsf2File = new Xsf();
                            newPsf2File.Initialize(newFs, newPsf2FilePath);
                        }

                        // update to use old tag hash
                        newPsf2File.TagHash = tagHash;
                        newPsf2File.UpdateTags();

                        /////////////////////////
                        // replace original file
                        /////////////////////////
                        File.Copy(newPsf2FilePath, pPath, true);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    // delete working folder
                    if (Directory.Exists(workingFolder))
                    {
                        Directory.Delete(workingFolder, true);
                    }
                }
            }
        }
コード例 #2
0
        protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPsf2SqExtractorStruct,
                                              DoWorkEventArgs e)
        {
            string outputSqFileName;

            string[] libPaths;
            string[] sqFiles;
            string[] iniFiles;
            Psf2.Psf2IniSqIrxStruct psf2IniStruct;

            string filePath;
            string fileDir;
            string fileName;
            string outputDir;
            string libOutputDir;

            string formatString = XsfUtil.GetXsfFormatString(pPath);

            if (!String.IsNullOrEmpty(formatString) && (formatString.Equals(Xsf.FormatNamePsf2)))
            {
                filePath = Path.GetFullPath(pPath);
                fileDir  = Path.GetDirectoryName(filePath);
                fileName = Path.GetFileNameWithoutExtension(filePath);

                outputDir = XsfUtil.UnpackPsf2(filePath);

                // parse ini
                iniFiles = Directory.GetFiles(outputDir, "PSF2.INI", SearchOption.AllDirectories);

                if (iniFiles.Length > 0)
                {
                    using (FileStream iniFs = File.Open(iniFiles[0], FileMode.Open, FileAccess.Read))
                    {
                        // parse ini file to get SQ info
                        psf2IniStruct = Psf2.ParseClsIniFile(iniFs);
                    }

                    using (FileStream fs = File.OpenRead(pPath))
                    {
                        Psf2 psf2File = new Psf2();
                        psf2File.Initialize(fs, pPath);

                        // check for libs
                        libPaths = psf2File.GetLibPathArray();
                    }
                    if ((libPaths == null) || (libPaths.Length == 0)) // PSF2
                    {
                        // copy the SQ file out (should only be one)
                        sqFiles = Directory.GetFiles(outputDir, psf2IniStruct.SqFileName, SearchOption.AllDirectories);

                        if (sqFiles.Length > 0)
                        {
                            if (!String.IsNullOrEmpty(psf2IniStruct.SequenceNumber))
                            {
                                outputSqFileName = String.Format("{0}_n={1}.SQ", outputDir, psf2IniStruct.SequenceNumber);
                            }
                            else
                            {
                                outputSqFileName = String.Format("{0}.SQ", outputDir);
                            }
                            File.Copy(sqFiles[0], outputSqFileName, true);
                        }
                    }
                    else // miniPSF2
                    {
                        // unpack each lib, looking for the needed file
                        foreach (string libPath in libPaths)
                        {
                            fileDir      = Path.GetDirectoryName(libPath);
                            fileName     = Path.GetFileNameWithoutExtension(libPath);
                            libOutputDir = Path.Combine(fileDir, fileName);

                            if (!extractedLibHash.ContainsKey(libPath))
                            {
                                libOutputDir = XsfUtil.UnpackPsf2(libPath);
                                extractedLibHash.Add(libPath, libOutputDir.ToUpper());
                            }

                            // look for the file in this lib
                            sqFiles = Directory.GetFiles(libOutputDir, psf2IniStruct.SqFileName, SearchOption.AllDirectories);

                            if (sqFiles.Length > 0)
                            {
                                if (!String.IsNullOrEmpty(psf2IniStruct.SequenceNumber))
                                {
                                    outputSqFileName = String.Format("{0}_n={1}.SQ", outputDir, psf2IniStruct.SequenceNumber);
                                }
                                else
                                {
                                    outputSqFileName = String.Format("{0}.SQ", outputDir);
                                }

                                File.Copy(sqFiles[0], outputSqFileName, true);
                                break;
                            }

                            // delete the unpkpsf2 output folder
                            if (Directory.Exists(libOutputDir))
                            {
                                Directory.Delete(libOutputDir, true);
                            }
                        } // foreach (string libPath in libPaths)
                    }
                }         // if (iniFiles.Length > 0)

                // delete the unpkpsf2 output folder
                if ((Directory.Exists(outputDir)) &&
                    (!extractedLibHash.ContainsValue(outputDir.ToUpper())))
                {
                    Directory.Delete(outputDir, true);
                }
            } // if (!String.IsNullOrEmpty(formatString) && (formatString.Equals(Xsf.FORMAT_NAME_PSF2)))
        }
コード例 #3
0
        protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPsf2DataFinderStruct, DoWorkEventArgs e)
        {
            Psf2DataFinderStruct psf2Struct = (Psf2DataFinderStruct)pPsf2DataFinderStruct;

            long offset;

            uint   sqLength;
            string sqName;
            int    sqNumber = 0;

            Psf2.ProbableItemStruct sqEntry;
            ArrayList sqFiles = new ArrayList();
            bool      sqNamingMessageDisplayed = false;

            uint   hdLength;
            string hdName;
            int    hdNumber = 0;

            HdStruct  hdObject;
            ArrayList hdArrayList = new ArrayList();

            ArrayList emptyRowList = new ArrayList();

            Psf2.ProbableItemStruct   potentialBd;
            Psf2.ProbableItemStruct[] potentialBdList;
            byte[] bdRow = new byte[0x10];

            // display file name
            this.progressStruct.Clear();
            this.progressStruct.GenericMessage = String.Format("[{0}]{1}", pPath, Environment.NewLine);
            this.ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);

            using (FileStream fs = File.OpenRead(pPath))
            {
                string destinationFolder = Path.Combine(Path.GetDirectoryName(pPath), Path.GetFileNameWithoutExtension(pPath));

                // get HD Files
                #region HD EXTRACT
                this.progressStruct.Clear();
                this.progressStruct.GenericMessage = String.Format("  Extracting HD{0}", Environment.NewLine);
                this.ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);

                offset = 0;

                while ((offset = ParseFile.GetNextOffset(fs, offset, Psf2.HD_SIGNATURE)) > -1)
                {
                    try
                    {
                        hdLength = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, offset + 0xC, 4), 0);

                        hdName = String.Format("{0}_{1}.HD", Path.GetFileNameWithoutExtension(pPath), hdNumber++.ToString("X4"));
                        ParseFile.ExtractChunkToFile(fs, offset - 0x10, (int)hdLength,
                                                     Path.Combine(destinationFolder, hdName), true, true);

                        // get info
                        hdObject                  = new HdStruct();
                        hdObject.FileName         = hdName;
                        hdObject.startingOffset   = offset - 0x10;
                        hdObject.length           = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, offset + 0xC, 4), 0);
                        hdObject.expectedBdLength = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, offset + 0x10, 4), 0);
                        hdObject.vagSectionOffset = hdObject.startingOffset + BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, offset + 0x20, 4), 0);
                        hdObject.maxVagInfoNumber = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, hdObject.vagSectionOffset + 0xC, 4), 0);

                        hdObject.vagInfoOffsetAddr    = new long[hdObject.maxVagInfoNumber + 1];
                        hdObject.vagOffset            = new long[hdObject.maxVagInfoNumber + 1];
                        hdObject.vagLengths           = new long[hdObject.maxVagInfoNumber];
                        hdObject.IsSmallSamplePresent = false;

                        for (int i = 0; i <= hdObject.maxVagInfoNumber; i++)
                        {
                            hdObject.vagInfoOffsetAddr[i] = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, hdObject.vagSectionOffset + 0x10 + (i * 4), 4), 0);
                            hdObject.vagOffset[i]         = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, hdObject.vagSectionOffset + hdObject.vagInfoOffsetAddr[i], 4), 0);

                            if (i > 0)
                            {
                                hdObject.vagLengths[i - 1] = hdObject.vagOffset[i] - hdObject.vagOffset[i - 1];

                                if (hdObject.vagLengths[i - 1] < Psf2.MIN_ADPCM_ROW_SIZE)
                                {
                                    hdObject.IsSmallSamplePresent = true;
                                }
                            }
                        }

                        // add to array
                        hdArrayList.Add(hdObject);
                    }
                    catch (Exception hdEx)
                    {
                        this.progressStruct.Clear();
                        this.progressStruct.ErrorMessage = String.Format("      Error extracting HD at offset 0x{0}: {1}{2}", offset.ToString("X8"), hdEx.Message, Environment.NewLine);
                        ReportProgress(progress, this.progressStruct);
                    }

                    // increment offset
                    offset += 1;
                }
                #endregion

                // get SQ Files
                #region SQ EXTRACT
                this.progressStruct.Clear();
                this.progressStruct.GenericMessage = String.Format("  Extracting SQ{0}", Environment.NewLine);
                this.ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);

                sqEntry = new Psf2.ProbableItemStruct();
                offset  = 0;

                // build file list
                while ((offset = ParseFile.GetNextOffset(fs, offset, Ps2SequenceData.SIGNATURE_BYTES)) > -1)
                {
                    sqLength = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(fs, offset + 0xC, 4), 0);

                    if ((!psf2Struct.UseSeqMinimumSize) || ((psf2Struct.UseSeqMinimumSize) &&
                                                            (sqLength >= psf2Struct.MinimumSize)))
                    {
                        sqEntry.offset = offset - 0x10;
                        sqEntry.length = sqLength;
                        sqFiles.Add(sqEntry);
                    }

                    offset += 1;
                }

                foreach (Psf2.ProbableItemStruct sq in sqFiles)
                {
                    if (psf2Struct.ReorderSqFiles)
                    {
                        if (hdArrayList.Count < sqFiles.Count)
                        {
                            if (!sqNamingMessageDisplayed)
                            {
                                this.progressStruct.Clear();
                                this.progressStruct.ErrorMessage = String.Format(
                                    "Warning, cannot reorder SQ files, there are less HD files than SQ files.{0}", Environment.NewLine);
                                this.ReportProgress(this.progress, this.progressStruct);
                                sqNamingMessageDisplayed = true;
                            }

                            sqName = String.Format("{0}_{1}.SQ", Path.GetFileNameWithoutExtension(pPath), sqNumber++.ToString("X4"));
                        }
                        else
                        {
                            hdObject = (HdStruct)hdArrayList[hdArrayList.Count - sqFiles.Count + sqNumber++];
                            sqName   = Path.ChangeExtension(hdObject.FileName, ".SQ");
                        }
                    }
                    else
                    {
                        sqName = String.Format("{0}_{1}.SQ", Path.GetFileNameWithoutExtension(pPath), sqNumber++.ToString("X4"));
                    }

                    ParseFile.ExtractChunkToFile(fs, sq.offset, (int)sq.length,
                                                 Path.Combine(destinationFolder, sqName), true, true);
                }


                #endregion

                // get BD files
                #region BD EXTRACT
                this.progressStruct.Clear();
                this.progressStruct.GenericMessage = String.Format("  Extracting BD...WARNING, THIS CAN TAKE A LONG TIME...{0}", Environment.NewLine);
                this.ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);

                offset = 0;

                // build list of potential adpcm start indexes
                potentialBd = new Psf2.ProbableItemStruct();

                while ((offset = ParseFile.GetNextOffset(fs, offset, Psf2.VB_START_BYTES, false)) > -1)
                {
                    //if (offset == 0x1DD3800)
                    //{
                    //    int fff = 1;
                    //}

                    if ((psf2Struct.UseZeroOffsetForBd) && (offset % 0x10 == 0) ||
                        (!psf2Struct.UseZeroOffsetForBd))
                    {
                        try
                        {
                            bdRow = ParseFile.ParseSimpleOffset(fs, offset, bdRow.Length);

                            if (Psf2.IsPotentialAdpcm(fs, offset + 0x10, Psf2.MIN_ADPCM_ROW_COUNT, false))
                            {
                                potentialBd.offset = offset;
                                emptyRowList.Add(potentialBd);
                            }
                        }
                        catch (Exception bdEx)
                        {
                            this.progressStruct.Clear();
                            this.progressStruct.ErrorMessage = String.Format(" ERROR finding BD for <{0}> at Offset 0x{1}: {2}{3}", pPath, offset.ToString("X8"), bdEx.Message, Environment.NewLine);
                            this.ReportProgress(this.progress, this.progressStruct);
                        }
                    }

                    offset += 1;
                }

                potentialBdList = (Psf2.ProbableItemStruct[])emptyRowList.ToArray(typeof(Psf2.ProbableItemStruct));

                // set probable lengths
                for (int i = 0; i < potentialBdList.Length; i++)
                {
                    if (i > 0)
                    {
                        potentialBdList[i - 1].length = (uint)(potentialBdList[i].offset - potentialBdList[i - 1].offset);
                    }
                }

                // compare HD sample sizes to potential adpcm sizes/indexes
                hdObject.startingOffset   = 0;
                hdObject.length           = 0;
                hdObject.bdStartingOffset = 0;
                hdObject.bdLength         = 0;

                string   bdName;
                string   newFileName;
                string[] dupeFileNames;

                for (int i = 0; i < hdArrayList.Count; i++)
                {
                    hdObject = (HdStruct)hdArrayList[i];
                    if (hdObject.vagLengths.Length < 1)
                    {
                        this.progressStruct.Clear();
                        this.progressStruct.ErrorMessage = String.Format(" ERROR building BD for <{0}>: {1} refers to a single VAG, cannot determine proper BD.  Skipping...{2}", pPath, hdObject.FileName, Environment.NewLine);
                        this.ReportProgress(this.progress, this.progressStruct);
                    }
                    else
                    {
                        for (int j = 0; j < potentialBdList.Length; j++)
                        {
                            // we have a potential match or are at the last item.
                            if ((hdObject.vagLengths[0] <= potentialBdList[j].length) ||
                                (potentialBdList[j].length == 0))
                            {
                                try
                                {
                                    hdObject = PopulateBdOffsetLength(fs, potentialBdList, j, hdObject);

                                    if (hdObject.bdLength > 0)
                                    {
                                        // check for other BD files that matched and rename accordingly
                                        dupeFileNames = Directory.GetFiles(destinationFolder, Path.GetFileNameWithoutExtension(hdObject.FileName) + "*.BD");

                                        if (dupeFileNames.Length >= 1)
                                        {
                                            bdName = String.Format("{0}_{1}.BD", Path.GetFileNameWithoutExtension(hdObject.FileName), (dupeFileNames.Length).ToString("X4"));

                                            if (dupeFileNames.Length == 1)
                                            {
                                                // rename existing
                                                newFileName = String.Format("{0}_{1}.BD", Path.GetFileNameWithoutExtension(hdObject.FileName), (dupeFileNames.Length - 1).ToString("X4"));
                                                File.Move(dupeFileNames[0], Path.Combine(Path.GetDirectoryName(dupeFileNames[0]), newFileName));
                                            }
                                        }
                                        else
                                        {
                                            bdName = Path.ChangeExtension(hdObject.FileName, ".BD");
                                        }


                                        ParseFile.ExtractChunkToFile(fs, hdObject.bdStartingOffset, (int)hdObject.bdLength,
                                                                     Path.Combine(destinationFolder, bdName), true, true);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    this.progressStruct.Clear();
                                    this.progressStruct.ErrorMessage = String.Format("     ERROR building BD for <{0}>: {1}{2}", pPath, ex.Message, Environment.NewLine);
                                    this.ReportProgress(this.progress, this.progressStruct);
                                }
                            }
                        }
                    }
                }
                #endregion
            }
        }
コード例 #4
0
        private bool moveNonIniFiles(string pSourceDirectory, string pDestinationDirectory)
        {
            bool   isSuccess      = true;
            Crc32  crc32Generator = new Crc32();
            string fileDestinationPath;
            string fileExtension;
            string fileName;

            Psf2.Psf2IniSqIrxStruct psf2IniStruct;

            if (!Directory.Exists(pDestinationDirectory))
            {
                Directory.CreateDirectory(pDestinationDirectory);
            }

            // get .ini and parse
            string iniPath = Path.Combine(pSourceDirectory, "psf2.ini");

            using (FileStream fs = File.OpenRead(iniPath))
            {
                psf2IniStruct = Psf2.ParseClsIniFile(fs);
                fs.Close();
            }

            foreach (string f in Directory.GetFiles(pSourceDirectory, "*.*", SearchOption.AllDirectories))
            {
                fileDestinationPath = String.Empty;

                // check if it is one of the SQ/BD/HD files
                fileName      = Path.GetFileName(f).ToUpper();
                fileExtension = Path.GetExtension(f).ToUpper();

                if (fileName.Equals(Path.GetFileName(psf2IniStruct.BdFileName)))
                {
                    psf2IniStruct.BdFileName = this.getFileNameForChecksum(f, BD_HASH_KEY) + Psf2.FILE_EXTENSION_BD;
                    fileDestinationPath      = Path.Combine(pDestinationDirectory, psf2IniStruct.BdFileName);
                }
                else if (fileName.Equals(Path.GetFileName(psf2IniStruct.HdFileName)))
                {
                    psf2IniStruct.HdFileName = this.getFileNameForChecksum(f, HD_HASH_KEY) + Psf2.FILE_EXTENSION_HD;
                    fileDestinationPath      = Path.Combine(pDestinationDirectory, psf2IniStruct.HdFileName);
                }
                else if (fileName.Equals(Path.GetFileName(psf2IniStruct.SqFileName)))
                {
                    psf2IniStruct.SqFileName = this.getFileNameForChecksum(f, SQ_HASH_KEY) + Psf2.FILE_EXTENSION_SQ;
                    fileDestinationPath      = Path.Combine(pDestinationDirectory, psf2IniStruct.SqFileName);
                }
                else if (fileExtension != ".INI")
                {
                    fileDestinationPath = Path.Combine(pDestinationDirectory, Path.GetFileName(f));
                }

                if (!String.IsNullOrEmpty(fileDestinationPath))
                {
                    try
                    {
                        File.Copy(f, fileDestinationPath, true);
                    }
                    catch (Exception _e)
                    {
                        isSuccess = false;

                        int progress = (fileCount * 100) / maxFiles;
                        this.progressStruct.Clear();
                        this.progressStruct.ErrorMessage = String.Format("Error processing <{0}>.  Error received: ", f) + _e.Message;
                        ReportProgress(progress, this.progressStruct);

                        break;
                    }

                    File.Delete(f);
                }
            }

            // rebuild .ini file
            Psf2.WriteClsIniFile(psf2IniStruct, iniPath);

            return(isSuccess);
        }
コード例 #5
0
ファイル: Psf2TimerWorker.cs プロジェクト: qyf0310/vgmtoolbox
        protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPsf2TimerStruct,
                                              DoWorkEventArgs e)
        {
            string outputSqFileName = null;

            string[] libPaths;
            string[] sqFiles;
            string[] iniFiles;
            Psf2.Psf2IniSqIrxStruct psf2IniStruct;

            string filePath;
            string fileDir;
            string fileName;
            string outputDir;
            string libOutputDir;

            Ps2SequenceData.Ps2SqTimingStruct psf2Time;
            int    minutes;
            double seconds;
            int    sequenceNumber = 0;

            StringBuilder batchFile = new StringBuilder();
            string        batchFilePath;

            string formatString = XsfUtil.GetXsfFormatString(pPath);

            if (!String.IsNullOrEmpty(formatString) && (formatString.Equals(Xsf.FormatNamePsf2)))
            {
                filePath = Path.GetFullPath(pPath);
                fileDir  = Path.GetDirectoryName(filePath);
                fileName = Path.GetFileNameWithoutExtension(filePath);

                outputDir = XsfUtil.UnpackPsf2(filePath);

                // parse ini
                iniFiles = Directory.GetFiles(outputDir, "PSF2.INI", SearchOption.AllDirectories);

                if (iniFiles.Length > 0)
                {
                    using (FileStream iniFs = File.Open(iniFiles[0], FileMode.Open, FileAccess.Read))
                    {
                        // parse ini file to get SQ info
                        psf2IniStruct = Psf2.ParseClsIniFile(iniFs);
                    }

                    using (FileStream fs = File.OpenRead(pPath))
                    {
                        Psf2 psf2File = new Psf2();
                        psf2File.Initialize(fs, pPath);

                        // check for libs
                        libPaths = psf2File.GetLibPathArray();
                    }

                    // copy the SQ file out (should only be one)
                    sqFiles = Directory.GetFiles(outputDir, psf2IniStruct.SqFileName, SearchOption.AllDirectories);

                    if (sqFiles.Length > 0)
                    {
                        if (!String.IsNullOrEmpty(psf2IniStruct.SequenceNumber))
                        {
                            sequenceNumber   = int.Parse(psf2IniStruct.SequenceNumber);
                            outputSqFileName = String.Format("{0}_n={1}.SQ", outputDir, psf2IniStruct.SequenceNumber);
                        }
                        else
                        {
                            outputSqFileName = String.Format("{0}.SQ", outputDir);
                        }
                        File.Copy(sqFiles[0], outputSqFileName, true);
                    }
                    else // miniPSF2
                    {
                        // unpack each lib, looking for the needed file
                        foreach (string libPath in libPaths)
                        {
                            fileDir      = Path.GetDirectoryName(libPath);
                            fileName     = Path.GetFileNameWithoutExtension(libPath);
                            libOutputDir = Path.Combine(fileDir, fileName);

                            if (!extractedLibHash.ContainsKey(libPath))
                            {
                                libOutputDir = XsfUtil.UnpackPsf2(libPath);
                                extractedLibHash.Add(libPath, libOutputDir.ToUpper());
                            }

                            // look for the file in this lib
                            sqFiles = Directory.GetFiles(libOutputDir, psf2IniStruct.SqFileName, SearchOption.AllDirectories);

                            if (sqFiles.Length > 0)
                            {
                                if (!String.IsNullOrEmpty(psf2IniStruct.SequenceNumber))
                                {
                                    sequenceNumber   = int.Parse(psf2IniStruct.SequenceNumber);
                                    outputSqFileName = String.Format("{0}_n={1}.SQ", outputDir, psf2IniStruct.SequenceNumber);
                                }
                                else
                                {
                                    outputSqFileName = String.Format("{0}.SQ", outputDir);
                                }

                                File.Copy(sqFiles[0], outputSqFileName, true);
                                break;
                            }

                            // delete the unpkpsf2 output folder
                            if (Directory.Exists(libOutputDir))
                            {
                                Directory.Delete(libOutputDir, true);
                            }
                        } // foreach (string libPath in libPaths)
                    }

                    // get time and add to script
                    if (!String.IsNullOrEmpty(outputSqFileName))
                    {
                        psf2Time = XsfUtil.GetTimeForPsf2File(outputSqFileName, sequenceNumber);

                        File.Delete(outputSqFileName);  // delete SQ file

                        minutes = (int)(psf2Time.TimeInSeconds / 60d);
                        seconds = (psf2Time.TimeInSeconds - (minutes * 60));
                        // seconds = Math.Ceiling(seconds);

                        // shouldn't be needed without Math.Ceiling call, but whatever
                        if (seconds >= 60)
                        {
                            minutes++;
                            seconds -= 60d;
                        }

                        batchFile.AppendFormat("psfpoint.exe -length=\"{0}:{1}\" -fade=\"{2}\" \"{3}\"",
                                               minutes.ToString(), seconds.ToString().PadLeft(2, '0'),
                                               psf2Time.FadeInSeconds.ToString(), Path.GetFileName(pPath));
                        batchFile.Append(Environment.NewLine);

                        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(psf2Time.Warnings))
                        {
                            this.progressStruct.Clear();
                            progressStruct.GenericMessage = String.Format("{0}{1}  WARNINGS{2}    {3}", pPath, Environment.NewLine, Environment.NewLine, psf2Time.Warnings);
                            ReportProgress(this.Progress, progressStruct);
                        }
                    }
                } // if (iniFiles.Length > 0)

                // delete the unpkpsf2 output folder
                if ((Directory.Exists(outputDir)) &&
                    (!extractedLibHash.ContainsValue(outputDir.ToUpper())))
                {
                    Directory.Delete(outputDir, true);
                }
            } // if (psf2File.getFormat().Equals(Xsf.FORMAT_NAME_PSF2) && (!psf2File.IsFileLibrary()))
        }