Exemplo n.º 1
0
        public void Save(Stream stream)
        {
            if (HasTableOfContents)
            {
                var header = new LfdHeader
                {
                    Type   = "RMAP",
                    Name   = "resource",
                    Length = Entries.Count * 16
                };
                header.Write(stream);

                foreach (var entry in Entries)
                {
                    entry.Header.Write(stream);
                }
            }
            foreach (var entry in Entries)
            {
                entry.Header.Write(stream);
                stream.Write(entry.Data, 0, entry.Data.Length);
            }
            IsChanged = false;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsChanged)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CanBeSaved)));
        }
Exemplo n.º 2
0
        public void Load(Stream stream)
        {
            var header = LfdHeader.Read(stream);

            HasTableOfContents = (header.Type == "RMAP");

            Entries.Clear();

            ResourceEntry entry = new ResourceEntry();

            if (HasTableOfContents)
            {
                var count   = header.Length / 16;
                var headers = new List <LfdHeader>(count);
                for (var i = 0; i < count; i++)
                {
                    headers.Add(LfdHeader.Read(stream));
                }
                entry = ResourceEntry.Load(stream);
            }
            else
            {
                entry.Header = header;
                entry.LoadData(stream);
            }

            while (entry.IsValid)
            {
                Entries.Add(entry);
                entry = ResourceEntry.Load(stream);
            }
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Entries)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HasTableOfContents)));
        }