public Archive findArchiveByName(String name) { int hash = Djb2.hash(name); for (Archive a : archives) { if (a.getNameHash() == hash) { return a; } } return null; }
br.printf("namehash=%d\n", archive.getNameHash()); br.printf("revision=%d\n", archive.getRevision()); br.printf("crc=%d\n", archive.getCrc());
private void dumpTrackArchive(File dumpDir, Storage storage, Archive archive) throws IOException { byte[] contents = archive.decompress(storage.loadArchive(archive)); if (contents == null) { return; } TrackLoader loader = new TrackLoader(); TrackDefinition def = loader.load(contents); String name; if (archive.getNameHash() != 0) { name = djb2.getName(archive.getNameHash()); if (name == null) { name = "name-" + archive.getNameHash(); } } else { name = "archive-" + archive.getArchiveId(); } File dest = new File(dumpDir, name + ".midi"); assert !dest.exists(); Files.write(def.midi, dest); }
private void loadSprites() throws IOException { Storage storage = store.getStorage(); Index index = store.getIndex(IndexType.SPRITES); final int mapsceneHash = Djb2.hash("mapscene"); for (Archive a : index.getArchives()) { byte[] contents = a.decompress(storage.loadArchive(a)); SpriteLoader loader = new SpriteLoader(); SpriteDefinition[] sprites = loader.load(a.getArchiveId(), contents); for (SpriteDefinition sprite : sprites) { if (sprite.getHeight() <= 0 || sprite.getWidth() <= 0) { continue; } if (a.getNameHash() == mapsceneHash) { BufferedImage spriteImage = new BufferedImage(sprite.getWidth(), sprite.getHeight(), BufferedImage.TYPE_INT_ARGB); spriteImage.setRGB(0, 0, sprite.getWidth(), sprite.getHeight(), sprite.getPixels(), 0, sprite.getWidth()); // scale image down so it fits Image scaledImage = spriteImage.getScaledInstance(MAPICON_MAX_WIDTH, MAPICON_MAX_HEIGHT, 0); assert scaledMapIcons.containsKey(sprite.getFrame()) == false; scaledMapIcons.put(sprite.getFrame(), scaledImage); } } } }
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; } }
@Override public void save(Store store) throws IOException { for (Index index : store.getIndexes()) { IndexEntry entry = cacheDao.createIndex(con, cacheEntry, index.getId(), index.getCrc(), index.getRevision()); for (Archive archive : index.getArchives()) { ArchiveEntry archiveEntry = cacheDao.findArchive(con, entry, archive.getArchiveId(), archive.getNameHash(), archive.getCrc(), archive.getRevision()); if (archiveEntry == null) { byte[] hash = archive.getHash(); archiveEntry = cacheDao.createArchive(con, entry, archive.getArchiveId(), archive.getNameHash(), archive.getCrc(), archive.getRevision(), hash); for (FileData file : archive.getFileData()) { cacheDao.associateFileToArchive(con, archiveEntry, file.getId(), file.getNameHash()); } } cacheDao.associateArchiveToIndex(con, archiveEntry, entry); } } }
&& existing.getNameHash() == ad.getNameHash()) existing.getRevision(), ad.getRevision(), existing.getCrc(), ad.getCrc(), existing.getNameHash(), ad.getNameHash());