예제 #1
0
        public void Load(BinaryReader reader, Action <int, int> progressCallback)
        {
            var stream = reader.BaseStream;

            if (!stream.CanRead || !stream.CanSeek)
            {
                throw new ArgumentException("BaseStream must be readable and seekable", "reader");
            }

            string signature = Encoding.ASCII.GetString(reader.ReadBytes(properSignature.Length));

            if (signature != properSignature)
            {
                throw new InvalidDataException("File does not have a proper TLK V3.0 signature");
            }

            LanguageID = (TlkLanguageID)reader.ReadInt32();

            int entriesCount  = reader.ReadInt32();
            int entriesOffset = reader.ReadInt32();

            isLoading = true;
            try
            {
                Entries.Clear();
                for (int i = 0; i < entriesCount; ++i)
                {
                    var entry = new TlkEntry {
                        StrRef = i
                    };

                    int flags = reader.ReadInt32();

                    byte[] soundResRef = reader.ReadBytes(16);
                    if ((flags & 0x2) != 0)
                    {
                        entry.SoundResRef = Encoding.ASCII.GetString(soundResRef).TrimEnd('\0');
                    }

                    entry.VolumeVariance = reader.ReadInt32();
                    entry.PitchVariance  = reader.ReadInt32();

                    int offset = reader.ReadInt32();
                    int length = reader.ReadInt32();

                    float soundLength = reader.ReadSingle();
                    if ((flags & 0x4) != 0)
                    {
                        entry.SoundLength = soundLength;
                    }

                    if ((flags & 0x1) != 0)
                    {
                        long bookmark = stream.Position;

                        stream.Position = entriesOffset + offset;
                        entry.Text      = latin1.GetString(reader.ReadBytes(length));

                        stream.Position = bookmark;
                    }

                    Entries.Add(entry);

                    if (progressCallback != null)
                    {
                        progressCallback(i + 1, entriesCount);
                    }
                }

                IsModified = false;
            }
            finally
            {
                isLoading = false;
            }

            undoStack.Clear();
            redoStack.Clear();

            OnPropertyChanged(new PropertyChangedEventArgs("CanUndo"));
            OnPropertyChanged(new PropertyChangedEventArgs("CanRedo"));
        }
예제 #2
0
 public EntryRemovedChange(int entryIndex, TlkEntry entry)
 {
     this.entryIndex = entryIndex;
     this.entry      = entry;
 }