@Override public void init(Store store) throws IOException { for (int i = 0; i < index255.getIndexCount(); ++i) { store.addIndex(i); getIndex(i); } assert store.getIndexes().size() == indexFiles.size(); }
@Test public void extract() throws IOException { File base = StoreLocation.LOCATION, outFile = folder.newFolder(); try (Store store = new Store(base)) { store.load(); Storage storage = store.getStorage(); Index index = store.getIndex(IndexType.BINARY); Archive archive = index.findArchiveByName("title.jpg"); byte[] contents = archive.decompress(storage.loadArchive(archive)); Files.write(outFile.toPath(), contents); } logger.info("Dumped to {}", outFile); } }
public Index getIndex(IndexType type) { return findIndex(type.getNumber()); }
@Test public void testSave() throws IOException try (Store store = new Store(StoreLocation.LOCATION)) store.load(); try (Store testStore = new Store(testStoreFile)) testStore.load(); Assert.assertTrue(store.equals(testStore)); testStore.save(); try (Store testStore = new Store(testStoreFile)) testStore.load(); Assert.assertTrue(store.equals(testStore));
@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); } } }
public void load() throws IOException { Storage storage = store.getStorage(); Index index = store.getIndex(IndexType.SPRITES); for (Archive a : index.getArchives()) { byte[] contents = a.decompress(storage.loadArchive(a)); SpriteLoader loader = new SpriteLoader(); SpriteDefinition[] defs = loader.load(a.getArchiveId(), contents); for (SpriteDefinition sprite : defs) { sprites.put(sprite.getId(), sprite); } } }
int revision = indexInfo.getRevision(); Index index = store.findIndex(i); index = store.addIndex(i); Storage storage = store.getStorage(); storage.saveArchive(archive, data);
@Override public void save(Store store) throws IOException store.getIndexes().sort(Comparator.comparing(Index::getId)); for (Index idx : store.getIndexes()) byte[] contents = store.getStorage().loadArchive(archive); if (contents != null)
@Override public void init(Store store) throws IOException { String[] idxs = listFlatcacheFiles(); for (String idx : idxs) { int id = Integer.parseInt(idx.substring(0, idx.length() - EXTENSION.length())); store.addIndex(id); } }
@Override public void save(Store store) throws IOException { logger.debug("Saving store"); for (Index i : store.getIndexes()) { saveIndex(i); } }
int y = i & 0xFF; Storage storage = store.getStorage(); Archive map = index.findArchiveByName("m" + x + "_" + y); Archive land = index.findArchiveByName("l" + x + "_" + y);
public RegionLoader(Store store) { this.store = store; index = store.getIndex(IndexType.MAPS); keyManager = new XteaKeyManager(); keyManager.loadKeys(); }
@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); } } }
public void load() throws IOException { Storage storage = store.getStorage(); Index index = store.getIndex(IndexType.TEXTURES); Archive archive = index.getArchive(0); byte[] archiveData = storage.loadArchive(archive); ArchiveFiles files = archive.getFiles(archiveData); TextureLoader loader = new TextureLoader(); for (FSFile file : files.getFiles()) { TextureDefinition texture = loader.load(file.getFileId(), file.getContents()); textures.add(texture); } }
@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 } } } }
@Override public void load(Store store) throws IOException { for (Index index : store.getIndexes()) { loadIndex(index); } }
@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); } }