Skip to content

Commit

Permalink
Merge pull request #7 from Displee/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Displee authored Sep 18, 2018
2 parents 4ba2290 + 9dff402 commit 77fb67f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/org/displee/cache/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ public boolean update(ProgressListener listener, Map<Integer, int[]> map) {
listener.notify(85, "Updating checksum table...");
}
if (updateChecksumTable || super.needUpdate) {
final byte[] indexData = Compression.compress(write(new OutputStream()), type, null, -1);
byte[] clonedIndexData = indexData.clone();
crc = HashGenerator.getCRCHash(clonedIndexData);
whirlpool = Whirlpool.getHash(clonedIndexData, 0, clonedIndexData.length);
super.revision++;
super.origin.getChecksumTable().writeArchiveInformation(super.id, Compression.compress(super.write(new OutputStream()), type, null, -1));
final byte[] indexData = Compression.compress(super.write(new OutputStream()), type, null, -1);
byte[] clonedData = indexData.clone();
crc = HashGenerator.getCRCHash(clonedData);
whirlpool = Whirlpool.getHash(clonedData, 0, clonedData.length);
super.origin.getChecksumTable().writeArchiveInformation(super.id, indexData);
}
if (listener != null) {
listener.notify(100, "Successfully updated index " + id + ".");
Expand Down
18 changes: 16 additions & 2 deletions src/org/displee/cache/index/IndexInformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public IndexInformation(CacheLibrary origin, int id) throws IllegalAccessError {
public boolean read(InputStream inputStream) {
version = inputStream.readByte() & 0xFF;
if (version < 5 || version > 7) {
throw new RuntimeException("Unknown index information version=" + version);
throw new RuntimeException("Unknown version=" + version);
}
revision = version >= 6 ? inputStream.readInt() : 0;
final int flag = inputStream.readByte();
Expand Down Expand Up @@ -307,6 +307,17 @@ public Archive[] copyArchives() {
return archives;
}

/**
* Add multiple archives to this index.
* @param archives An array of archives.
* @param resetFiles If we need to reset all the files in the archives.
*/
public void addArchives(Archive[] archives, boolean resetFiles) {
for (Archive archive : archives) {
addArchive(archive, resetFiles);
}
}

/**
* Add multiple archives to this index.
* @param archives An array of archives.
Expand Down Expand Up @@ -494,7 +505,6 @@ public void removeArchive(int id) {
*/
public void flag() {
sort();
revision++;
needUpdate = true;
}

Expand Down Expand Up @@ -586,6 +596,10 @@ public Archive getArchive(int id, int[] xtea, boolean direct) {
return archive;
}
archive.read(new InputStream(Compression.decompress(archiveInformation, xtea)));
if (this.id == 5 && !archive.containsData()) {//reset map data if archive has no data
archive.setIsRead(false);
return archive;
}
final InputStream inputStream = new InputStream(archiveInformation.getData());
inputStream.setOffset(1);
final int remaining = inputStream.getBytes().length - ((inputStream.readInt() & 0xFFFFFF) + inputStream.getOffset());
Expand Down
21 changes: 20 additions & 1 deletion src/org/displee/cache/index/archive/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ public byte[] write(OutputStream outputStream) {
return outputStream.flip();
}

/**
* Check if this archive contains data.
* @return If this archive contains data.
*/
public boolean containsData() {
if (files == null) {
return false;
}
for(File file : files) {
if (file != null && file.getData() != null) {
return true;
}
}
return false;
}

/**
* Add multiple files.
* @param files The array of the files to add.
Expand Down Expand Up @@ -329,7 +345,10 @@ public void restore() {
public Archive copy() {
final Archive archive = new Archive(id, name);
archive.fileIds = Arrays.copyOf(fileIds, fileIds.length);
archive.files = Arrays.copyOf(files, files.length);
archive.files = new File[files.length];
for(int i = 0; i < files.length; i++) {
archive.files[i] = files[i].copy();
}
archive.revision = revision;
archive.crc = crc;
archive.whirlpool = Arrays.copyOf(whirlpool, whirlpool.length);
Expand Down
2 changes: 1 addition & 1 deletion src/org/displee/cache/index/archive/file/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public File(int id, byte[] data, int name) {
* @return The new file.
*/
public File copy() {
return new File(id, data, name);
return new File(id, data.clone(), name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/org/displee/io/impl/InputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public int readSmart2() {
public int readUnsignedSmart() {
final int i = buffer[offset] & 0xFF;
if (i < 128) {
return (readByte() & 0xFF) - 64;
return readUnsignedByte() - 64;
}
return (readShort() & 0xFFFF) - 49152;
return readUnsignedShort() - 49152;
}

/**
Expand Down

0 comments on commit 77fb67f

Please sign in to comment.