Rest of index loading? untested

This commit is contained in:
Adam
2015-10-13 21:21:53 -04:00
parent 92faf3fa48
commit e2f90f2c95
3 changed files with 107 additions and 27 deletions

View File

@@ -2,6 +2,7 @@ package net.runelite.cache.fs;
import java.util.ArrayList;
import java.util.List;
import net.runelite.cache.fs.io.InputStream;
public class Archive
{
@@ -18,6 +19,49 @@ public class Archive
this.index = index;
this.archiveId = id;
}
public void load(InputStream stream, int numberOfFiles, int protocol)
{
int archive = 0;
for (int i = 0; i < numberOfFiles; ++i)
{
int fileId = archive += protocol >= 7 ? stream.readBigSmart() : stream.readUnsignedShort();
File file = new File(this, fileId);
this.files.add(file);
//archive1.getValidFileIds()[index21] = fileId;
}
//archive1.setFiles(new FileReference[index2 + 1]);
// for (int i = 0; i < archive1.getValidFileIds().length; ++i) {
// archive1.getFiles()[archive1.getValidFileIds()[ki]] = new FileReference();
// }
// if (this.named)
// {
// for (index = 0; index < validArchivesCount; ++index)
// {
// ArchiveReference var14 = this.archives[this.validArchiveIds[index]];
//
// for (index2 = 0; index2 < var14.getValidFileIds().length; ++index2)
// {
// var14.getFiles()[var14.getValidFileIds()[index2]].setNameHash(stream.readInt());
// }
// }
// }
}
public void loadNames(InputStream stream, int numberOfFiles)
{
for (int i = 0; i < numberOfFiles; ++i)
{
File file = this.files.get(i);
int name = stream.readInt();
file.setNameHash(name);
}
}
public int getNameHash()
{

View File

@@ -5,4 +5,30 @@ public class File
private Archive archive;
private int fileId;
private int nameHash;
public File(Archive archive, int fileId)
{
this.archive = archive;
this.fileId = fileId;
}
public Archive getArchive()
{
return archive;
}
public int getFileId()
{
return fileId;
}
public int getNameHash()
{
return nameHash;
}
public void setNameHash(int nameHash)
{
this.nameHash = nameHash;
}
}

View File

@@ -19,11 +19,14 @@ public class Index
private byte[] whirlpool;
private List<Archive> archives = new ArrayList<>();
public Index(IndexFile index, int id) throws IOException
public Index(IndexFile index, int id)
{
this.index = index;
this.id = id;
}
public void load() throws IOException
{
// read data from index255
Store store = index.getStore();
DataFile dataFile = store.getData();
@@ -89,8 +92,7 @@ public class Index
int protocol = stream.readUnsignedByte();
if (protocol >= 5 && protocol <= 7) {
if (protocol >= 6) {
not the right rev
this.revision = stream.readInt();
int revision = stream.readInt(); // what is this and why is it different from checkRevision?
}
int hash = stream.readUnsignedByte();
@@ -98,7 +100,7 @@ public class Index
this.usesWhirpool = (2 & hash) != 0;
int validArchivesCount = protocol >= 7 ? stream.readBigSmart() : stream.readUnsignedShort();
// this.validArchiveIds = new int[validArchivesCount];
// int lastArchiveId = 0;
int lastArchiveId = 0;
// int biggestArchiveId = 0;
int index;
@@ -168,32 +170,40 @@ public class Index
for (index = 0; index < validArchivesCount; ++index) {
archive = 0;
index2 = 0;
ArchiveReference archive1 = this.archives[this.validArchiveIds[index]];
Archive a = this.archives.get(index);
a.load(stream, numberOfFiles[index], protocol);
//ArchiveReference archive1 = this.archives[this.validArchiveIds[index]];
int index21;
for (index21 = 0; index21 < archive1.getValidFileIds().length; ++index21) {
int fileId = archive += protocol >= 7 ? stream.readBigSmart() : stream.readUnsignedShort();
if (fileId > index2) {
index2 = fileId;
}
archive1.getValidFileIds()[index21] = fileId;
}
archive1.setFiles(new FileReference[index2 + 1]);
for (index21 = 0; index21 < archive1.getValidFileIds().length; ++index21) {
archive1.getFiles()[archive1.getValidFileIds()[index21]] = new FileReference();
}
// int index21;
// for (index21 = 0; index21 < archive1.getValidFileIds().length; ++index21) {
// int fileId = archive += protocol >= 7 ? stream.readBigSmart() : stream.readUnsignedShort();
// if (fileId > index2) {
// index2 = fileId;
// }
//
// archive1.getValidFileIds()[index21] = fileId;
// }
//
// archive1.setFiles(new FileReference[index2 + 1]);
//
// for (index21 = 0; index21 < archive1.getValidFileIds().length; ++index21) {
// archive1.getFiles()[archive1.getValidFileIds()[index21]] = new FileReference();
// }
}
if (this.named) {
for (index = 0; index < validArchivesCount; ++index) {
ArchiveReference var14 = this.archives[this.validArchiveIds[index]];
if (this.named)
{
for (index = 0; index < validArchivesCount; ++index)
{
Archive a = this.archives.get(index);
a.loadNames(stream, numberOfFiles[index]);
//ArchiveReference var14 = this.archives[this.validArchiveIds[index]];
for (index2 = 0; index2 < var14.getValidFileIds().length; ++index2) {
var14.getFiles()[var14.getValidFileIds()[index2]].setNameHash(stream.readInt());
}
// for (index2 = 0; index2 < var14.getValidFileIds().length; ++index2)
// {
// var14.getFiles()[var14.getValidFileIds()[index2]].setNameHash(stream.readInt());
// }
}
}
}