public static ParamSfo ReadFrom(Stream stream)
        {
            if (!stream.CanSeek)
            {
                throw new ArgumentException("Stream must be seekable", nameof(stream));
            }

            stream.Seek(0, SeekOrigin.Begin);
            var result = new ParamSfo();

            using (var reader = new BinaryReader(stream, new UTF8Encoding(false), true))
            {
                result.Magic = new string(reader.ReadChars(4));
                if (result.Magic != "\0PSF")
                {
                    throw new FormatException("Not a valid SFO file");
                }

                result.MajorVersion = reader.ReadByte();
                result.MinorVersion = reader.ReadByte();
                result.Reserved1    = reader.ReadInt16();
                result.KeysOffset   = reader.ReadInt32();
                result.ValuesOffset = reader.ReadInt32();
                result.ItemCount    = reader.ReadInt32();
                result.Items        = new List <ParamSfoEntry>(result.ItemCount);

                for (var i = 0; i < result.ItemCount; i++)
                {
                    result.Items.Add(ParamSfoEntry.Read(reader, result, i));
                }
            }

            return(result);
        }
Exemple #2
0
        private void reloadButton_Click(object sender, EventArgs e)
        {
            saveButton.Enabled    = false;
            titleBox.TextChanged -= titleBox_TextChanged;

            if (string.IsNullOrEmpty(filenameBox.Text))
            {
                return;
            }

            if (!File.Exists(filenameBox.Text))
            {
                MessageBox.Show("Please check the path to param.sfo", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (var stream = File.Open(filenameBox.Text, FileMode.Open, FileAccess.Read, FileShare.Read))
                paramSfo = ParamSfo.ReadFrom(stream);
            titleEntry = paramSfo.Items.FirstOrDefault(i => i.Key == "TITLE");
            if (titleEntry == null)
            {
                paramSfo = null;
                MessageBox.Show("Title entry not found", "Unsupported param.sfo file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            titleBox.Text = titleEntry.StringValue;
            titleBox.Focus();

            titleBox.TextChanged += titleBox_TextChanged;
        }
        public static ParamSfoEntry Read(BinaryReader reader, ParamSfo paramSfo, int itemNumber)
        {
            const int indexOffset      = 0x14;
            const int indexEntryLength = 0x10;

            reader.BaseStream.Seek(indexOffset + indexEntryLength * itemNumber, SeekOrigin.Begin);
            var result = new ParamSfoEntry();

            result.KeyOffset      = reader.ReadUInt16();
            result.ValueFormat    = (EntryFormat)reader.ReadUInt16();
            result.ValueLength    = reader.ReadInt32();
            result.ValueMaxLength = reader.ReadInt32();
            result.ValueOffset    = reader.ReadInt32();

            reader.BaseStream.Seek(paramSfo.KeysOffset + result.KeyOffset, SeekOrigin.Begin);
            byte tmp;
            var  sb = new StringBuilder(32);

            while ((tmp = reader.ReadByte()) != 0)
            {
                sb.Append((char)tmp);
            }
            result.Key = sb.ToString();

            reader.BaseStream.Seek(paramSfo.ValuesOffset + result.ValueOffset, SeekOrigin.Begin);
            result.BinaryValue = reader.ReadBytes(result.ValueMaxLength);

            return(result);
        }
Exemple #4
0
 private void filenameBox_TextChanged(object sender, EventArgs e)
 {
     saveButton.Enabled = false;
     paramSfo           = null;
     titleEntry         = null;
 }