use of net.runelite.cache.fs.Index in project runelite by runelite.
the class NpcManager method load.
public void load() throws IOException {
NpcLoader loader = new NpcLoader();
Storage storage = store.getStorage();
Index index = store.getIndex(IndexType.CONFIGS);
Archive archive = index.getArchive(ConfigType.NPC.getId());
byte[] archiveData = storage.loadArchive(archive);
ArchiveFiles files = archive.getFiles(archiveData);
for (FSFile f : files.getFiles()) {
NpcDefinition npc = loader.load(f.getFileId(), f.getContents());
npcs.add(npc);
}
}
use of net.runelite.cache.fs.Index in project runelite by runelite.
the class ArchiveRequestHandler method handleRequest.
private void handleRequest(ChannelHandlerContext ctx, int index, int archiveId) throws IOException {
logger.info("Client {} requests index {} archive {}", ctx.channel().remoteAddress(), index, archiveId);
Index i = store.findIndex(index);
assert i != null;
Archive archive = i.getArchive(archiveId);
assert archive != null;
Storage storage = store.getStorage();
// is compressed, includes length and type
byte[] packed = storage.loadArchive(archive);
if (packed == null) {
logger.warn("Missing archive {}/{}", index, archiveId);
// is it possible to notify the client of an error with this?
return;
}
byte compression = packed[0];
int compressedSize = Ints.fromBytes(packed[1], packed[2], packed[3], packed[4]);
// size the client expects the data to be
int expectedSize = // compression type
1 + // compressed size
4 + compressedSize + (compression != CompressionType.NONE ? 4 : 0);
if (packed.length != expectedSize) {
// the update server will never have it
assert packed.length - expectedSize == 2 : "packed length != expected size";
packed = Arrays.copyOf(packed, packed.length - 2);
}
ArchiveResponsePacket response = new ArchiveResponsePacket();
response.setIndex(index);
response.setArchive(archiveId);
response.setData(packed);
ctx.writeAndFlush(response);
}
use of net.runelite.cache.fs.Index in project runelite by runelite.
the class ArchiveRequestHandler method handleRequest255.
private void handleRequest255(ChannelHandlerContext ctx, int index, int archiveId) throws IOException {
logger.info("Client {} requests 255: index {}, archive {}", ctx.channel().remoteAddress(), index, archiveId);
byte[] compressed;
if (archiveId == 255) {
// index 255 data, for each index:
// 4 byte crc
// 4 byte revision
ByteBuf buffer = ctx.alloc().heapBuffer(store.getIndexes().size() * 8);
for (Index i : store.getIndexes()) {
buffer.writeInt(i.getCrc());
buffer.writeInt(i.getRevision());
}
compressed = compress(CompressionType.NONE, Arrays.copyOf(buffer.array(), buffer.readableBytes()));
buffer.release();
} else {
// Requires disk storage. Use packed index data from
// store as its crc matches
DiskStorage storage = (DiskStorage) store.getStorage();
compressed = storage.readIndex(archiveId);
}
ArchiveResponsePacket response = new ArchiveResponsePacket();
response.setIndex(index);
response.setArchive(archiveId);
response.setData(compressed);
ctx.writeAndFlush(response);
}
use of net.runelite.cache.fs.Index in project runelite by runelite.
the class CacheStorage method load.
@Override
public void load(Store store) throws IOException {
List<IndexEntry> indexes = cacheDao.findIndexesForCache(con, cacheEntry);
for (IndexEntry indexEntry : indexes) {
Index index = store.addIndex(indexEntry.getIndexId());
index.setCrc(indexEntry.getCrc());
index.setRevision(indexEntry.getRevision());
try (ResultSetIterable<ArchiveEntry> archives = cacheDao.findArchivesForIndex(con, indexEntry)) {
for (ArchiveEntry archiveEntry : archives) {
if (index.getArchive(archiveEntry.getArchiveId()) != null) {
throw new IOException("Duplicate archive " + archiveEntry + " on " + indexEntry);
}
Archive archive = index.addArchive(archiveEntry.getArchiveId());
archive.setNameHash(archiveEntry.getNameHash());
archive.setCrc(archiveEntry.getCrc());
archive.setRevision(archiveEntry.getRevision());
archive.setHash(archiveEntry.getHash());
// File data is not necessary for cache updating
}
}
}
}
use of net.runelite.cache.fs.Index in project runelite by runelite.
the class ObjectManager method load.
public void load() throws IOException {
ObjectLoader loader = new ObjectLoader();
Storage storage = store.getStorage();
Index index = store.getIndex(IndexType.CONFIGS);
Archive archive = index.getArchive(ConfigType.OBJECT.getId());
byte[] archiveData = storage.loadArchive(archive);
ArchiveFiles files = archive.getFiles(archiveData);
for (FSFile f : files.getFiles()) {
ObjectDefinition def = loader.load(f.getFileId(), f.getContents());
objects.put(f.getFileId(), def);
}
}
Aggregations