Beispiel #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);
                    }
                }
            }
        }
Beispiel #2
0
 protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pUnpkPsf2Struct,
                                       DoWorkEventArgs e)
 {
     XsfUtil.UnpackPsf2(pPath);
 }
        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)))
        }
Beispiel #4
0
        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()))
        }