コード例 #1
0
        private void time2sfs(Time2sfStruct pTime2sfStruct, DoWorkEventArgs e)
        {
            if (!CancellationPending)
            {
                string outputMessages;

                Time2sfStruct t = new Time2sfStruct();
                t.Mini2sfDirectory = pTime2sfStruct.Mini2sfDirectory;
                t.SdatPath         = pTime2sfStruct.SdatPath;
                t.DoSingleLoop     = pTime2sfStruct.DoSingleLoop;

                try
                {
                    XsfUtil.Time2sfFolder(t, out outputMessages);

                    this.progressStruct.Clear();

                    if (!String.IsNullOrEmpty(outputMessages))
                    {
                        this.progressStruct.ErrorMessage = String.Format("ERROR: {0}",
                                                                         outputMessages) + Environment.NewLine;
                    }

                    ReportProgress(100, this.progressStruct);
                }
                catch (Exception _e)
                {
                    this.progressStruct.Clear();
                    this.progressStruct.ErrorMessage = String.Format("ERROR: {0}",
                                                                     _e.Message) + Environment.NewLine;
                    ReportProgress(0, this.progressStruct);
                }
            }
            else
            {
                e.Cancel = true;
                return;
            }
        }
コード例 #2
0
        private void Make2sfFiles(Mk2sfStruct pMk2sfStruct)
        {
            string sdatDestinationPath;
            string TwoSFDestinationPath;
            string sdatPrefix;
            string testpackDestinationPath;
            string unallowedDestinationPath;
            string strmDestinationPath;
            Sdat   sdat;

            // Build Paths
            if (String.IsNullOrEmpty(pMk2sfStruct.GameSerial))
            {
                sdatDestinationPath =
                    Path.Combine(pMk2sfStruct.DestinationFolder, Path.GetFileName(pMk2sfStruct.SourcePath));
            }
            else
            {
                sdatDestinationPath =
                    Path.Combine(pMk2sfStruct.DestinationFolder, pMk2sfStruct.GameSerial + Path.GetExtension(pMk2sfStruct.SourcePath));
            }
            TwoSFDestinationPath =
                Path.Combine(pMk2sfStruct.DestinationFolder, Path.GetFileNameWithoutExtension(sdatDestinationPath));
            sdatPrefix = Path.GetFileNameWithoutExtension(sdatDestinationPath);
            testpackDestinationPath = Path.Combine(pMk2sfStruct.DestinationFolder,
                                                   Path.GetFileName(TESTPACK_FULL_PATH));
            unallowedDestinationPath = Path.Combine(TwoSFDestinationPath, "UnAllowed Sequences");
            strmDestinationPath      = TwoSFDestinationPath;

            // Copy SDAT to destination folder
            try
            {
                File.Copy(pMk2sfStruct.SourcePath, sdatDestinationPath, false);
            }
            catch (Exception sdatException)
            {
                throw new IOException(String.Format("Error: Cannot copy SDAT <{0}> to destination directory: {1}.", sdatDestinationPath, sdatException.Message));
            }

            // Copy STRMs
            this.progressStruct.Clear();
            this.progressStruct.GenericMessage = "Copying STRM files" + Environment.NewLine;
            ReportProgress(Constants.ProgressMessageOnly, progressStruct);

            using (FileStream sdatStream = File.OpenRead(sdatDestinationPath))
            {
                sdat = new Sdat();
                sdat.Initialize(sdatStream, sdatDestinationPath);
                sdat.ExtractStrms(sdatStream, strmDestinationPath);
            }

            // Update Volume
            for (int i = 0; i < pMk2sfStruct.VolumeChangeList.Length; i++)
            {
                if (pMk2sfStruct.VolumeChangeList[i].newValue != pMk2sfStruct.VolumeChangeList[i].oldValue)
                {
                    sdat.UpdateSseqVolume(i, pMk2sfStruct.VolumeChangeList[i].newValue);
                }
            }


            // Optimize SDAT
            this.progressStruct.Clear();
            this.progressStruct.GenericMessage = "Optimizing SDAT" + Environment.NewLine;
            ReportProgress(Constants.ProgressMessageOnly, progressStruct);

            using (FileStream sdatStream = File.OpenRead(sdatDestinationPath))
            {
                sdat = new Sdat();
                sdat.Initialize(sdatStream, sdatDestinationPath);
            }
            sdat.OptimizeForZlib(pMk2sfStruct.AllowedSequences);

            // Copy testpack.nds
            File.Copy(TESTPACK_FULL_PATH, testpackDestinationPath, true);

            // Create 2SF output path
            if (!Directory.Exists(TwoSFDestinationPath))
            {
                Directory.CreateDirectory(TwoSFDestinationPath);
            }

            // Build 2SFs
            this.progressStruct.Clear();
            this.progressStruct.GenericMessage = "Build 2SFs" + Environment.NewLine;
            ReportProgress(Constants.ProgressMessageOnly, progressStruct);

            XsfUtil.Make2sfSet(testpackDestinationPath, sdatDestinationPath,
                               GetMinAllowedSseq(pMk2sfStruct.AllowedSequences),
                               GetMaxAllowedSseq(pMk2sfStruct.AllowedSequences), TwoSFDestinationPath);

            // Move unallowed Sequences
            string unallowedFileName;
            string unallowedFilePath;

            foreach (int unallowedSequenceNumber in pMk2sfStruct.UnAllowedSequences)
            {
                unallowedFileName = String.Format("{0}-{1}.mini2sf", sdatPrefix, unallowedSequenceNumber.ToString("x4"));
                unallowedFilePath = Path.Combine(TwoSFDestinationPath, unallowedFileName);

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

                if (File.Exists(unallowedFilePath))
                {
                    File.Copy(unallowedFilePath, Path.Combine(unallowedDestinationPath, unallowedFileName), true);
                    File.Delete(unallowedFilePath);
                }
            }

            // Add Tags
            this.progressStruct.Clear();
            this.progressStruct.GenericMessage = "Tagging Output" + Environment.NewLine;
            ReportProgress(Constants.ProgressMessageOnly, progressStruct);

            XsfBasicTaggingStruct tagStruct = new XsfBasicTaggingStruct();

            tagStruct.TagArtist        = pMk2sfStruct.TagArtist;
            tagStruct.TagCopyright     = pMk2sfStruct.TagCopyright;
            tagStruct.TagYear          = pMk2sfStruct.TagYear;
            tagStruct.TagGame          = pMk2sfStruct.TagGame;
            tagStruct.TagComment       = "uses Legacy of Ys: Book II driver hacked by Caitsith2";
            tagStruct.TagXsfByTagName  = "-2sfby";
            tagStruct.TagXsfByTagValue = "VGMToolbox";

            string taggingBatchPath = XsfUtil.BuildBasicTaggingBatch(TwoSFDestinationPath, tagStruct, "*.mini2sf");

            XsfUtil.ExecutePsfPointBatchScript(taggingBatchPath, true);

            // Time 2SFs
            this.progressStruct.Clear();
            this.progressStruct.GenericMessage = "Timing Output" + Environment.NewLine;
            ReportProgress(Constants.ProgressMessageOnly, progressStruct);

            string outputTimerMessages;

            Time2sfStruct timerStruct = new Time2sfStruct();

            timerStruct.DoSingleLoop     = false;
            timerStruct.Mini2sfDirectory = TwoSFDestinationPath;
            timerStruct.SdatPath         = pMk2sfStruct.SourcePath;

            XsfUtil.Time2sfFolder(timerStruct, out outputTimerMessages);

            // Delete Files
            this.progressStruct.Clear();
            this.progressStruct.GenericMessage = "Cleaning Up" + Environment.NewLine;
            ReportProgress(Constants.ProgressMessageOnly, progressStruct);

            if (File.Exists(sdatDestinationPath))
            {
                File.Delete(sdatDestinationPath);
            }
            if (File.Exists(testpackDestinationPath))
            {
                File.Delete(testpackDestinationPath);
            }
        }