Ejemplo n.º 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);
        }
Ejemplo n.º 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;
                        }
                    }
                }
            }
        }