Skip to content

Commit

Permalink
Fixed a bug where copyArchives didn't copy the file's data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Displee committed Sep 18, 2018
1 parent 95c703c commit 9dff402
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/org/displee/cache/index/IndexInformation.java
Original file line number Diff line number Diff line change
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 @@ -585,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

0 comments on commit 9dff402

Please sign in to comment.