Search in sources :

Example 6 with Archive

use of net.runelite.cache.fs.Archive 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);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) NpcLoader(net.runelite.cache.definitions.loaders.NpcLoader) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) Index(net.runelite.cache.fs.Index) FSFile(net.runelite.cache.fs.FSFile)

Example 7 with Archive

use of net.runelite.cache.fs.Archive 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);
}
Also used : Archive(net.runelite.cache.fs.Archive) Storage(net.runelite.cache.fs.Storage) DiskStorage(net.runelite.cache.fs.jagex.DiskStorage) Index(net.runelite.cache.fs.Index) ArchiveResponsePacket(net.runelite.protocol.api.update.ArchiveResponsePacket)

Example 8 with Archive

use of net.runelite.cache.fs.Archive 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
            }
        }
    }
}
Also used : Archive(net.runelite.cache.fs.Archive) IndexEntry(net.runelite.cache.updater.beans.IndexEntry) Index(net.runelite.cache.fs.Index) ArchiveEntry(net.runelite.cache.updater.beans.ArchiveEntry) IOException(java.io.IOException)

Example 9 with Archive

use of net.runelite.cache.fs.Archive in project runelite by runelite.

the class CacheUpdater method update.

public void update() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException {
    int rsVersion = RuneLiteAPI.getRsVersion();
    try (Connection con = sql2o.beginTransaction()) {
        CacheDAO cacheDao = new CacheDAO();
        CacheEntry cache = cacheDao.findMostRecent(con);
        boolean created = false;
        if (cache == null) {
            created = true;
            cache = cacheDao.createCache(con, rsVersion, Instant.now());
        }
        CacheStorage storage = new CacheStorage(cache, cacheDao, con);
        Store store = new Store(storage);
        store.load();
        ExecutorService executor = Executors.newSingleThreadExecutor();
        CacheClient client = new CacheClient(store, rsVersion, (Archive archive, byte[] data) -> executor.submit(new CacheUploader(minioClient, minioBucket, archive, data)));
        client.connect();
        HandshakeResponseType result = client.handshake().join();
        if (result != HandshakeResponseType.RESPONSE_OK) {
            logger.warn("Out of date!");
            return;
        }
        List<IndexInfo> indexes = client.requestIndexes();
        List<IndexEntry> entries = cacheDao.findIndexesForCache(con, cache);
        if (!checkOutOfDate(indexes, entries)) {
            logger.info("All up to date.");
            return;
        }
        client.download();
        CacheEntry newCache = created ? cache : cacheDao.createCache(con, rsVersion, Instant.now());
        storage.setCacheEntry(newCache);
        store.save();
        // ensure objects are added to the store before they become
        // visible in the database
        executor.shutdown();
        while (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
            logger.debug("Waiting for termination of executor...");
        }
        // commit database
        con.commit();
    }
}
Also used : CacheClient(net.runelite.cache.client.CacheClient) Archive(net.runelite.cache.fs.Archive) HandshakeResponseType(net.runelite.protocol.api.login.HandshakeResponseType) Connection(org.sql2o.Connection) Store(net.runelite.cache.fs.Store) IndexEntry(net.runelite.cache.updater.beans.IndexEntry) IndexInfo(net.runelite.cache.client.IndexInfo) CacheEntry(net.runelite.cache.updater.beans.CacheEntry) ExecutorService(java.util.concurrent.ExecutorService)

Example 10 with Archive

use of net.runelite.cache.fs.Archive 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);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) Index(net.runelite.cache.fs.Index) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) FSFile(net.runelite.cache.fs.FSFile)

Aggregations

Archive (net.runelite.cache.fs.Archive)41 Index (net.runelite.cache.fs.Index)38 Storage (net.runelite.cache.fs.Storage)34 Store (net.runelite.cache.fs.Store)21 File (java.io.File)19 Test (org.junit.Test)19 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)18 FSFile (net.runelite.cache.fs.FSFile)18 IOException (java.io.IOException)6 FileData (net.runelite.cache.index.FileData)4 Container (net.runelite.cache.fs.Container)3 BufferedImage (java.awt.image.BufferedImage)2 CacheClient (net.runelite.cache.client.CacheClient)2 FramemapDefinition (net.runelite.cache.definitions.FramemapDefinition)2 InterfaceDefinition (net.runelite.cache.definitions.InterfaceDefinition)2 InventoryDefinition (net.runelite.cache.definitions.InventoryDefinition)2 ItemDefinition (net.runelite.cache.definitions.ItemDefinition)2 LocationsDefinition (net.runelite.cache.definitions.LocationsDefinition)2 MapDefinition (net.runelite.cache.definitions.MapDefinition)2 OverlayDefinition (net.runelite.cache.definitions.OverlayDefinition)2