public void Close(DbCachedDataId dbRecordIndex) { Boolean result; lock (_byId) { if (_byId.TryGetValue(dbRecordIndex, out DbCachedData data)) { _byId.Remove(dbRecordIndex); data.Dispose(); result = true; } else { result = false; } } if (!result) { throw new FileNotFoundException($"Cannot close not loaded resource {dbRecordIndex}."); } Log.Message($"Unloaded resource {dbRecordIndex}."); }
private DbCachedData GetCachedData(DbCachedDataId dbRecordIndex) { lock (_byId) { if (_byId.TryGetValue(dbRecordIndex, out var data)) { return(data); } } if (dbRecordIndex.Value < _currentIndex) { throw new ObjectDisposedException($"The resource {dbRecordIndex} is already closed."); } throw new FileNotFoundException($"The resource {dbRecordIndex} isn't opened yet."); }
public DbCachedDataId Open(DbRecordId dbRecordId) { if (!_indices.TryGetResourcePath(dbRecordId, out var resourcePath)) { throw new FileNotFoundException($"Cannot load unknown resource: {dbRecordId}"); } DbCachedDataId dbRecordIndex; Byte[] fileContent = NativeFormatProvider.ReadAllBytes(resourcePath); lock (_byId) { dbRecordIndex = new DbCachedDataId(_currentIndex++); DbCachedData data = new DbCachedData(dbRecordId, resourcePath, fileContent); _byId[dbRecordIndex] = data; } Log.Message($"Loaded resource {dbRecordIndex}: [0x{dbRecordId}, {resourcePath}]."); return(dbRecordIndex); }
public unsafe Int32 Read(DbCachedDataId dbRecordIndex, Byte *output, Int32 outputSize) { DbCachedData data = GetCachedData(dbRecordIndex); return(data.Read(output, outputSize)); }
public void Seek(DbCachedDataId dbRecordIndex, Int32 offset) { DbCachedData data = GetCachedData(dbRecordIndex); data.Seek(offset); }
public Int32 GetDecompressedSize(DbCachedDataId dbRecordIndex) { DbCachedData data = GetCachedData(dbRecordIndex); return(data.Size); }