Search in sources :

Example 6 with Store

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

the class CacheServerTest method testDownload.

@Test
@Ignore
public void testDownload() throws Exception {
    try (Store store = new Store(StoreLocation.LOCATION);
        CacheServer server = new CacheServer(store, REVISION)) {
        store.load();
        server.start();
        try (CacheClient client = new CacheClient(new Store(folder.newFolder()), HOST, REVISION)) {
            client.connect();
            client.handshake().get();
            client.download();
        }
    }
}
Also used : CacheClient(net.runelite.cache.client.CacheClient) Store(net.runelite.cache.fs.Store) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with Store

use of net.runelite.cache.fs.Store 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 8 with Store

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

the class SoundEffectsDumperTest method test.

@Test
public void test() throws IOException {
    File dumpDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(StoreLocation.LOCATION)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.SOUNDEFFECTS);
        for (Archive archive : index.getArchives()) {
            byte[] contents = archive.decompress(storage.loadArchive(archive));
            SoundEffectLoader soundEffectLoader = new SoundEffectLoader();
            SoundEffectDefinition soundEffect = soundEffectLoader.load(contents);
            Files.write(gson.toJson(soundEffect), new File(dumpDir, archive.getArchiveId() + ".json"), Charset.defaultCharset());
            ++count;
        }
    }
    logger.info("Dumped {} sound effects to {}", count, dumpDir);
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) SoundEffectLoader(net.runelite.cache.definitions.loaders.sound.SoundEffectLoader) SoundEffectDefinition(net.runelite.cache.definitions.sound.SoundEffectDefinition) File(java.io.File) Test(org.junit.Test)

Example 9 with Store

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

the class ItemManagerTest method test.

@Test
public void test() throws IOException {
    File dumpDir = folder.newFolder(), javaDir = folder.newFolder();
    Store store = new Store(StoreLocation.LOCATION);
    store.load();
    ItemManager dumper = new ItemManager(store);
    dumper.load();
    dumper.export(dumpDir);
    dumper.java(javaDir);
    logger.info("Dumped to {}, java {}", dumpDir, javaDir);
}
Also used : Store(net.runelite.cache.fs.Store) File(java.io.File) Test(org.junit.Test)

Example 10 with Store

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

the class MapDumperTest method dumpRaw.

@Test
@Ignore
public void dumpRaw() throws IOException {
    File base = StoreLocation.LOCATION, outDir = folder.newFolder();
    XteaKeyManager keyManager = new XteaKeyManager();
    keyManager.loadKeys();
    try (Store store = new Store(base)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.MAPS);
        for (int i = 0; i < MAX_REGIONS; i++) {
            int[] keys = keyManager.getKeys(i);
            int x = i >> 8;
            int y = i & 0xFF;
            Archive map = index.findArchiveByName("m" + x + "_" + y);
            Archive land = index.findArchiveByName("l" + x + "_" + y);
            assert (map == null) == (land == null);
            if (map == null || land == null) {
                continue;
            }
            byte[] data = map.decompress(storage.loadArchive(map));
            Files.write(data, new File(outDir, "m" + x + "_" + y + ".dat"));
            if (keys != null) {
                try {
                    data = land.decompress(storage.loadArchive(land), keys);
                } catch (IOException ex) {
                    logger.info("Unable to decompress and load land " + x + "," + y + " (bad keys?)", ex);
                    continue;
                }
                logger.info("Decrypted region {} coords {},{}", i, x, y);
                Files.write(data, new File(outDir, "l" + x + "_" + y + ".dat"));
            }
        }
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) XteaKeyManager(net.runelite.cache.util.XteaKeyManager) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) IOException(java.io.IOException) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Store (net.runelite.cache.fs.Store)38 File (java.io.File)34 Test (org.junit.Test)32 Archive (net.runelite.cache.fs.Archive)21 Index (net.runelite.cache.fs.Index)20 Storage (net.runelite.cache.fs.Storage)18 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)9 FSFile (net.runelite.cache.fs.FSFile)9 Ignore (org.junit.Ignore)7 BufferedImage (java.awt.image.BufferedImage)4 IOException (java.io.IOException)3 CacheClient (net.runelite.cache.client.CacheClient)3 ModelLoader (net.runelite.cache.definitions.loaders.ModelLoader)3 TextureManager (net.runelite.cache.TextureManager)2 FramemapDefinition (net.runelite.cache.definitions.FramemapDefinition)2 ModelDefinition (net.runelite.cache.definitions.ModelDefinition)2 FramemapLoader (net.runelite.cache.definitions.loaders.FramemapLoader)2 FileData (net.runelite.cache.index.FileData)2 HandshakeResponseType (net.runelite.protocol.api.login.HandshakeResponseType)2 RemoteCache (com.ostracker.cache.RemoteCache)1