Search in sources :

Example 1 with FileData

use of net.runelite.cache.index.FileData in project runelite by runelite.

the class StoreTest method testMultipleArchives.

@Test
public void testMultipleArchives() throws IOException {
    Random random = new Random(43L);
    File root = folder.newFolder();
    try (Store store = new Store(root)) {
        Index index = store.addIndex(0);
        Index index2 = store.addIndex(1);
        Archive archive = index.addArchive(0);
        archive.setNameHash(random.nextInt(Integer.MAX_VALUE));
        archive.setFileData(new FileData[NUMBER_OF_FILES]);
        Archive archive2 = index.addArchive(1);
        archive2.setFileData(new FileData[NUMBER_OF_FILES]);
        Archive archive3 = index2.addArchive(0);
        archive3.setFileData(new FileData[NUMBER_OF_FILES]);
        for (int i = 0; i < NUMBER_OF_FILES; ++i) {
            FileData[] fileData = archive.getFileData();
            FileData file = fileData[i] = new FileData();
            file.setNameHash(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < NUMBER_OF_FILES; ++i) {
            FileData[] fileData = archive2.getFileData();
            FileData file = fileData[i] = new FileData();
            file.setNameHash(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < NUMBER_OF_FILES; ++i) {
            FileData[] fileData = archive3.getFileData();
            FileData file = fileData[i] = new FileData();
            file.setNameHash(random.nextInt(Integer.MAX_VALUE));
        }
        store.save();
        try (Store store2 = new Store(root)) {
            store2.load();
            Assert.assertEquals(store, store2);
        }
    }
}
Also used : Random(java.util.Random) File(java.io.File) FileData(net.runelite.cache.index.FileData) Test(org.junit.Test)

Example 2 with FileData

use of net.runelite.cache.index.FileData in project runelite by runelite.

the class StoreTest method testOneFile.

@Test
public void testOneFile() throws IOException {
    try (Store store = new Store(folder.getRoot())) {
        Index index = store.addIndex(0);
        Archive archive = index.addArchive(0);
        archive.setFileData(new FileData[1]);
        FileData fileData = archive.getFileData()[0] = new FileData();
        fileData.setId(42);
        fileData.setNameHash(7);
        store.save();
        try (Store store2 = new Store(folder.getRoot())) {
            store2.load();
            Assert.assertEquals(store, store2);
        }
    }
}
Also used : FileData(net.runelite.cache.index.FileData) Test(org.junit.Test)

Example 3 with FileData

use of net.runelite.cache.index.FileData in project runelite by runelite.

the class Archive method getFiles.

public ArchiveFiles getFiles(byte[] data, int[] keys) throws IOException {
    byte[] decompressedData = decompress(data, keys);
    ArchiveFiles files = new ArchiveFiles();
    for (FileData fileEntry : fileData) {
        FSFile file = new FSFile(fileEntry.getId());
        file.setNameHash(fileEntry.getNameHash());
        files.addFile(file);
    }
    files.loadContents(decompressedData);
    return files;
}
Also used : FileData(net.runelite.cache.index.FileData)

Example 4 with FileData

use of net.runelite.cache.index.FileData in project runelite by runelite.

the class Index method toIndexData.

public IndexData toIndexData() {
    IndexData data = new IndexData();
    data.setProtocol(protocol);
    data.setRevision(revision);
    data.setNamed(named);
    ArchiveData[] archiveDatas = new ArchiveData[archives.size()];
    data.setArchives(archiveDatas);
    int idx = 0;
    for (Archive archive : archives) {
        ArchiveData ad = archiveDatas[idx++] = new ArchiveData();
        ad.setId(archive.getArchiveId());
        ad.setNameHash(archive.getNameHash());
        ad.setCrc(archive.getCrc());
        ad.setRevision(archive.getRevision());
        FileData[] files = archive.getFileData();
        ad.setFiles(files);
    }
    return data;
}
Also used : IndexData(net.runelite.cache.index.IndexData) ArchiveData(net.runelite.cache.index.ArchiveData) FileData(net.runelite.cache.index.FileData)

Example 5 with FileData

use of net.runelite.cache.index.FileData in project runelite by runelite.

the class StoreTest method testManyFiles.

@Test
public void testManyFiles() throws IOException {
    Random random = new Random(42L);
    File root = folder.newFolder();
    try (Store store = new Store(root)) {
        Index index = store.addIndex(0);
        Archive archive = index.addArchive(0);
        archive.setNameHash(random.nextInt());
        archive.setFileData(new FileData[NUMBER_OF_FILES]);
        for (int i = 0; i < NUMBER_OF_FILES; ++i) {
            FileData[] fileData = archive.getFileData();
            FileData file = fileData[i] = new FileData();
            file.setId(i);
            file.setNameHash(random.nextInt());
        }
        store.save();
        try (Store store2 = new Store(root)) {
            store2.load();
            Assert.assertEquals(store, store2);
        }
    }
}
Also used : Random(java.util.Random) File(java.io.File) FileData(net.runelite.cache.index.FileData) Test(org.junit.Test)

Aggregations

FileData (net.runelite.cache.index.FileData)9 Test (org.junit.Test)5 Archive (net.runelite.cache.fs.Archive)4 Index (net.runelite.cache.fs.Index)4 File (java.io.File)3 Random (java.util.Random)2 Container (net.runelite.cache.fs.Container)2 Storage (net.runelite.cache.fs.Storage)2 Store (net.runelite.cache.fs.Store)2 CacheClient (net.runelite.cache.client.CacheClient)1 ArchiveData (net.runelite.cache.index.ArchiveData)1 IndexData (net.runelite.cache.index.IndexData)1 ArchiveEntry (net.runelite.cache.updater.beans.ArchiveEntry)1 IndexEntry (net.runelite.cache.updater.beans.IndexEntry)1