public Index(PackIdentifier packId, string path) { PackId = packId; using (var file = IOFile.OpenRead(path)) { using (var reader = new BinaryReader(file)) Build(reader); } }
public Index2(PackIdentifier packId, string path) { this.PackId = packId; using (FileStream file = IOFile.OpenRead(path)) { using (BinaryReader reader = new BinaryReader(file)) Build(reader); } }
public Stream GetDataStream(byte datFile = 0) { var thread = Thread.CurrentThread; var key = Tuple.Create(thread, datFile); WeakReference <Stream> streamRef; Stream stream; lock (_DataStreams) _DataStreams.TryGetValue(key, out streamRef); if (streamRef == null || !streamRef.TryGetTarget(out stream)) { stream = null; } if (stream != null) { return(stream); } var baseName = String.Format(DatFileFormat, Id.TypeKey, Id.ExpansionKey, Id.Number, datFile); var fullPath = Path.Combine(DataDirectory.FullName, Id.Expansion, baseName); if (KeepInMemory) { if (!_Buffers.ContainsKey(datFile)) { _Buffers.Add(datFile, IOFile.ReadAllBytes(fullPath)); } stream = new MemoryStream(_Buffers[datFile], false); } else { stream = IOFile.OpenRead(fullPath); } lock (_DataStreams) { if (_DataStreams.ContainsKey(key)) { _DataStreams[key].SetTarget(stream); } else { _DataStreams.Add(key, new WeakReference <Stream>(stream)); } } return(stream); }