Skip to content

Commit

Permalink
百度云解压bug,文件头判断错误
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Mar 6, 2018
1 parent f461b68 commit 85747f9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
Binary file added .guide/common/ca/windows/imgs/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .guide/common/ca/windows/imgs/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .guide/common/ca/windows/imgs/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .guide/common/ca/windows/imgs/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions .guide/common/ca/windows/read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 下载证书
1. 右击软件托盘,点证书目录会跳转到对应目录
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/ca/windows/imgs/1.png)
2. 双击证书,安装下图步骤进行安装
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/ca/windows/imgs/2.png)
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/ca/windows/imgs/3.png)
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/ca/windows/imgs/4.png)


41 changes: 31 additions & 10 deletions common/src/main/java/lee/study/down/io/BdyZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public static BdyZipEntry getNextFixedBdyZipEntry(FileChannel fileChannel, List<
BdyUnzipCallback callback)
throws IOException {
BdyZipEntry zipEntry = getNextBdyZipEntry(fileChannel);
if (!zipEntry.isDir()) {
int index = zipEntry.getFileName().lastIndexOf("/");
if (index != -1) {
addDirIfNotExists(dirList, zipEntry.getFileName().substring(0, index + 1));
}
}
boolean fixFlag = false;
if (ByteUtil
.matchToken(fileChannel,
Expand All @@ -114,6 +120,9 @@ public static BdyZipEntry getNextFixedBdyZipEntry(FileChannel fileChannel, List<
zipEntry.getFileStartPosition() + zipEntry.getCompressedSize(),
ZIP_ENTRY_FILE_HEARD)) {
long fixedSize = fixedEntrySize(fileChannel, zipEntry, _4G, dirList, callback);
if (fixedSize == -1) {
throw new RuntimeException("修复失败,文件损坏请重新下载");
}
zipEntry.setUnCompressedSize(fixedSize);
zipEntry.setCompressedSize(fixedSize);
if (ByteUtil
Expand Down Expand Up @@ -146,7 +155,7 @@ private static long fixedEntrySize(FileChannel fileChannel, BdyZipEntry zipEntry
BdyZipEntry nextEntry = getNextBdyZipEntry(fileChannel,
zipEntry.getFileStartPosition() + fixedSize);
//修复长度后下个文件目录没对上
if (!Arrays.equals(nextEntry.getHeader(), ZIP_ENTRY_DIR_HEARD)
if (!Arrays.equals(nextEntry.getHeader(), Arrays.copyOfRange(ZIP_ENTRY_DIR_HEARD, 0, 4))
&& !isRight(dirList, nextEntry)) {
return fixedEntrySize(fileChannel, zipEntry, fixedSize + ZIP_ENTRY_FILE_HEARD.length,
dirList, callback);
Expand All @@ -164,22 +173,34 @@ public static List<BdyZipEntry> getFixedEntryList(FileChannel fileChannel,
BdyZipEntry entry = getNextFixedBdyZipEntry(fileChannel, dirList, callback);
list.add(entry);
if (entry.isEnd()) {
callback.onFixDone(list);
if (callback != null) {
callback.onFixDone(list);
}
return list;
} else if (entry.isDir()) {
dirList.add(entry.getFileName());
addDirIfNotExists(dirList, entry.getFileName());
}
}
}

private static void addDirIfNotExists(List<String> dirList, String dir) {
if (!inDirList(dirList, dir)) {
dirList.add(dir);
}
}

private static boolean inDirList(List<String> dirList, String dir) {
for (String temp : dirList) {
if (dir.matches("^" + temp + "[^/]*$")) {
return true;
}
}
return false;
}

private static boolean isRight(List<String> dirList, BdyZipEntry nextEntry) {
if (nextEntry.isDir()) {
for (String dir : dirList) {
if (nextEntry.getFileName().matches("^" + dir + "[^/]*$")) {
return true;
}
}
return false;
return inDirList(dirList, nextEntry.getFileName());
} else {
return nextEntry.getFileName().matches("^" + dirList.get(dirList.size() - 1) + "[^/]*$");
}
Expand Down Expand Up @@ -247,7 +268,7 @@ public static void unzip(String path, String toPath)
}

public static void main(String[] args) throws IOException {
unzip("f:/down/pack13.zip", "f:/down/pack13", new TestUnzipCallback());
unzip("f:/down/test2测试.zip", "f:/down/test2测试", new TestUnzipCallback());
}

/**
Expand Down

0 comments on commit 85747f9

Please sign in to comment.