コード例 #1
0
        public static string ExtractGenhFile(string pSourcePath, bool extractHeaderToFile, bool outputExtractionLog, bool outputExtractionFile)
        {
            string outputFileName       = null;
            string headerOutputFileName = null;

            if (IsGenhFile(pSourcePath))
            {
                using (FileStream fs = File.Open(pSourcePath, FileMode.Open, FileAccess.Read))
                {
                    Genh genhFile = new Genh();
                    genhFile.Initialize(fs, pSourcePath);
                    Int32  headerLength     = BitConverter.ToInt32(genhFile.HeaderLength, 0);
                    Int32  originalFileSize = BitConverter.ToInt32(genhFile.OriginalFileSize, 0);
                    string originalFileName = System.Text.Encoding.ASCII.GetString(genhFile.OriginalFileName);

                    outputFileName = Path.Combine(Path.GetDirectoryName(pSourcePath), originalFileName).Trim();
                    ParseFile.ExtractChunkToFile(fs, headerLength, originalFileSize, outputFileName, outputExtractionLog, outputExtractionFile);

                    if (extractHeaderToFile)
                    {
                        headerOutputFileName = Path.Combine(Path.GetDirectoryName(pSourcePath), String.Format("{0}{1}", originalFileName.Trim(), Genh.FILE_EXTENSION_HEADER)).Trim();
                        ParseFile.ExtractChunkToFile(fs, 0, headerLength, headerOutputFileName, outputExtractionLog, outputExtractionFile);
                    }

                    FileInfo fi = new FileInfo(outputFileName);
                    if (fi.Length != (long)originalFileSize)
                    {
                        throw new IOException(String.Format("Extracted file <{0}> size did not match size in header of <{1}>: 0x{2}{3}", outputFileName,
                                                            pSourcePath, originalFileSize.ToString("X8"), Environment.NewLine));
                    }
                }
            }

            return(outputFileName);
        }
コード例 #2
0
        private void loadGenhFileForEditing()
        {
            ListBoxFileInfoObject listBoxFile;

            if (lbFiles.SelectedIndices.Count == 1)
            {
                listBoxFile = (ListBoxFileInfoObject)this.lbFiles.SelectedItem;
                string editPath = listBoxFile.FilePath;

                if (GenhUtil.IsGenhFile(editPath))
                {
                    using (FileStream fs = File.OpenRead(editPath))
                    {
                        Genh itemToEdit = new Genh();
                        itemToEdit.Initialize(fs, editPath);

                        // Set initial values
                        GenhCreationStruct gcStruct = GenhUtil.GetGenhCreationStruct(itemToEdit);
                        this.setGenhParameters(gcStruct);

                        // set loop radio button
                        if ((String.IsNullOrEmpty(gcStruct.LoopStart)) ||
                            (gcStruct.LoopStart.Equals(Genh.EMPTY_SAMPLE_COUNT)))
                        {
                            if (this.cbNoLoops.Checked == true)
                            {
                                this.cbNoLoops.Checked = false; // do this to trigger event if already checked.
                            }

                            this.cbNoLoops.Checked = true;


                            // for some formats (MPEG, XMA, FFMPEG) I cannot calculate the exact number of samples,
                            //    so copy current loop end to total samples.  However, do not overwrite if it exists.
                            if (String.IsNullOrWhiteSpace(this.tbTotalSamples.Text) ||
                                ByteConversion.GetLongValueFromString(this.tbTotalSamples.Text) == 0)
                            {
                                this.tbTotalSamples.Text = ByteConversion.GetLongValueFromString(gcStruct.LoopEnd) > 0 ? gcStruct.LoopEnd : "0";
                            }
                        }
                        else
                        {
                            this.cbManualEntry.Checked = true;
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static GenhCreationStruct GetGenhCreationStruct(Genh genhItem)
        {
            GenhCreationStruct gcStruct = new GenhCreationStruct();

            int formatValue = BitConverter.ToInt32(genhItem.Identifier, 0);

            gcStruct.Format       = formatValue.ToString();
            gcStruct.HeaderSkip   = "0x" + ((BitConverter.ToInt32(genhItem.AudioStart, 0) - BitConverter.ToInt32(genhItem.HeaderLength, 0))).ToString("X4");
            gcStruct.Interleave   = "0x" + BitConverter.ToInt32(genhItem.Interleave, 0).ToString("X4");
            gcStruct.Channels     = BitConverter.ToInt32(genhItem.Channels, 0).ToString();
            gcStruct.Frequency    = BitConverter.ToInt32(genhItem.Frequency, 0).ToString();
            gcStruct.TotalSamples = BitConverter.ToInt32(genhItem.TotalSamples, 0).ToString();

            gcStruct.SkipSamplesMode = genhItem.SkipSamplesMode;
            gcStruct.SkipSamples     = BitConverter.ToInt32(genhItem.SkipSamples, 0).ToString();

            gcStruct.Atrac3StereoMode = genhItem.Atrac3StereoMode;
            gcStruct.XmaStreamMode    = genhItem.XmaStreamMode;
            gcStruct.RawDataSize      = BitConverter.ToInt32(genhItem.RawStreamSize, 0).ToString();

            int loopStartValue = BitConverter.ToInt32(genhItem.LoopStart, 0);

            if (loopStartValue > -1)
            {
                gcStruct.LoopStart = loopStartValue.ToString();
            }
            else
            {
                gcStruct.LoopStart = String.Empty;
            }

            int loopEndValue = BitConverter.ToInt32(genhItem.LoopEnd, 0);

            if (loopEndValue > 0)
            {
                gcStruct.LoopEnd          = loopEndValue.ToString();
                gcStruct.UseLoopEndOffset = true;
            }
            else
            {
                gcStruct.LoopEnd          = String.Empty;
                gcStruct.UseLoopEndOffset = false;
            }

            if (formatValue == 12)
            {
                gcStruct.CoefficientType = genhItem.CoefficientType[0];

                if (gcStruct.CoefficientType == 1 || gcStruct.CoefficientType == 3) // Split Coefficients (aka Capcom Hack)
                {
                    gcStruct.CoefRightChannel = "0x" + (BitConverter.ToUInt32(genhItem.RightCoef, 0) - Genh.GENH_HEADER_SIZE - 0x10).ToString("X4");
                    gcStruct.CoefLeftChannel  = "0x" + (BitConverter.ToUInt32(genhItem.LeftCoef, 0) - Genh.GENH_HEADER_SIZE - 0x10).ToString("X4");
                }
                else
                {
                    gcStruct.CoefRightChannel = "0x" + (BitConverter.ToUInt32(genhItem.RightCoef, 0) - Genh.GENH_HEADER_SIZE).ToString("X4");
                    gcStruct.CoefLeftChannel  = "0x" + (BitConverter.ToUInt32(genhItem.LeftCoef, 0) - Genh.GENH_HEADER_SIZE).ToString("X4");
                }
            }

            return(gcStruct);
        }