CSPspEmu.Hle.Formats.Psf.Load C# (CSharp) Method

Load() public method

public Load ( Stream Stream ) : Psf
Stream Stream
return Psf
        public Psf Load(Stream Stream)
        {
            EntryDictionary = new Dictionary<string, object>();
            Header = Stream.ReadStruct<HeaderStruct>();
            Entries = Stream.ReadStructVector<EntryStruct>(Header.NumberOfPairs);
            KeysStream = Stream.SliceWithLength(Header.KeyTable);
            ValuesStream = Stream.SliceWithLength(Header.ValueTable);
            foreach (var Entry in Entries)
            {
                var Key = KeysStream.ReadStringzAt(Entry.KeyOffset);
                var ValueStream = ValuesStream.SliceWithLength(Entry.ValueOffset, Entry.ValueSize);;
                switch (Entry.DataType)
                {
                    case DataType.Binary: EntryDictionary[Key] = ValueStream.ReadAll(); break;
                    case DataType.Int: EntryDictionary[Key] = ValueStream.ReadStruct<int>(); break;
                    case DataType.Text: EntryDictionary[Key] = ValueStream.ReadStringz(-1, Encoding.UTF8); break;
                    default: throw(new NotImplementedException());
                }
            }
            return this;
        }

Usage Example

Example #1
0
        public void LoadTest()
        {
            var Psf = new Psf();
            Psf.Load(File.OpenRead("../../../TestInput/PARAM.SFO"));
            foreach (var Pair in Psf.EntryDictionary)
            {
                Console.WriteLine("{0}:{1}", Pair.Key, Pair.Value);
            }

            Assert.AreEqual(Psf.EntryDictionary["BOOTABLE"], 1);
            Assert.AreEqual(Psf.EntryDictionary["CATEGORY"], "UG");
            Assert.AreEqual(Psf.EntryDictionary["DISC_ID"], "TEST99999");
            Assert.AreEqual(Psf.EntryDictionary["DISC_NUMBER"], 1);
            Assert.AreEqual(Psf.EntryDictionary["DISC_TOTAL"], 1);
            Assert.AreEqual(Psf.EntryDictionary["DISC_VERSION"], "9.99");
            Assert.AreEqual(Psf.EntryDictionary["PARENTAL_LEVEL"], 5);
            Assert.AreEqual(Psf.EntryDictionary["PSP_SYSTEM_VER"], "3.33");
            Assert.AreEqual(Psf.EntryDictionary["REGION"], 32768);
            Assert.AreEqual(Psf.EntryDictionary["TITLE"], "GAME TITLE TITLE");
        }