Update PCKFileReader/Writer

This commit is contained in:
miku-666
2022-06-08 20:25:27 +02:00
parent 346d31560d
commit fb1bde2257
2 changed files with 4 additions and 6 deletions

View File

@@ -61,8 +61,6 @@ namespace PckStudio.Classes.IO
foreach (var file_entry in _file.file_entries)
{
int property_count = ReadInt(stream);
var properties = new PCKProperties();
for (; 0 < property_count; property_count--)
{
int index = ReadInt(stream);
@@ -70,11 +68,11 @@ namespace PckStudio.Classes.IO
throw new Exception("Value not found");
string key = GetKeyFromValue(_file.meta_data, index);
string value = ReadString(stream);
properties.Add(new Tuple<string, string>(key, value));
file_entry.properties.Add(new ValueTuple<string, string>(key, value));
ReadInt(stream); // padding ???
}
file_entry.properties = properties;
stream.Read(file_entry.data, 0, file_entry.size); // file data buffer is only allocated when FileData is constructed with `dataSize`
// file data buffer is only allocated when FileData is constructed with `dataSize`
stream.Read(file_entry.data, 0, file_entry.size);
}
}
private static T1 GetKeyFromValue<T1, T2>(Dictionary<T1, T2> dict, T2 value)

View File

@@ -36,7 +36,7 @@ namespace PckStudio.Classes.IO
byte[] buffer = BitConverter.GetBytes(value);
if (BitConverter.IsLittleEndian && !isLittleEndian)
Array.Reverse(buffer);
stream.Write(buffer, 0, buffer.Length);
stream.Write(buffer, 0, 4);
}
internal void WriteString(Stream stream, string s)