Beispiel #1
0
        private void SerializeTo(string path)
        {
            var data = Index;

            using (var fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) {
                fs.SetLength(0);
                using (var writer = new BinaryWriter(fs, Encoding.UTF8)) {
                    writer.Write(SerializationKey);
                    writer.Write(data.Count);
                    foreach (var item in data)
                    {
                        item.Serialize(writer);
                    }
                    writer.Flush();
                    IconCache.SerializeTo(fs);
                }
            }
        }
Beispiel #2
0
        private void Deserialize(string path)
        {
            var idx = new List <ItemInfo>();

            using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var reader = new BinaryReader(fs, Encoding.UTF8)) {
                    var suuid = reader.ReadString();
                    if (suuid != SerializationKey)
                    {
                        throw new NotImplementedException();
                    }
                    var count = reader.ReadInt32();
                    for (var i = 0; i < count; i++)
                    {
                        idx.Add(ItemInfo.Deserialize(reader));
                    }
                    IconCache.Deserialize(fs);
                }
            Index = idx;
        }