Skip to content

Commit

Permalink
修复百度云压缩包文件名乱码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Jan 18, 2018
1 parent 84dc9e9 commit 97ac51f
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/lee/study/down/io/BdyZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static BdyZipEntry getNextBdyZipEntry(FileChannel fileChannel) throws IOE
ByteBuffer fileNameBuffer = ByteBuffer.allocate((int) zipEntry.getFileNameLength());
fileChannel.read(fileNameBuffer);
fileNameBuffer.flip();
zipEntry.setFileName(Charset.forName("GBK").decode(fileNameBuffer).toString());
zipEntry.setFileName(Charset.forName("GB18030").decode(fileNameBuffer).toString());
if (zipEntry.getExtraFieldLength() > 0) {
ByteBuffer extraFieldBuffer = ByteBuffer.allocate((int) zipEntry.getExtraFieldLength());
fileChannel.read(extraFieldBuffer);
Expand Down
7 changes: 0 additions & 7 deletions common/src/main/java/lee/study/down/model/TaskInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ public void reset() {
});
}

public void refresh() {
lastTime = System.currentTimeMillis();
chunkInfoList.forEach((chunkInfo) -> {
chunkInfo.setLastTime(lastTime);
});
}

public void refresh(ChunkInfo chunkInfo) {
lastTime = System.currentTimeMillis();
chunkInfo.setLastTime(lastTime);
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.0</version>
<version>2.01</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,13 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
if (taskInfo.getStatus() == HttpDownStatus.RUNNING
&& taskInfo.getChunkInfoList().stream()
.allMatch((chunk) -> chunk.getStatus() == HttpDownStatus.DONE)) {
//记录完成时间
taskInfo.setLastTime(System.currentTimeMillis());
if (taskInfo.getTotalSize() <= 0) { //chunked编码最后更新文件大小
taskInfo.setTotalSize(taskInfo.getDownSize());
taskInfo.getChunkInfoList().get(0).setTotalSize(taskInfo.getDownSize());
}
//文件下载完成回调
taskInfo.setStatus(HttpDownStatus.DONE);
LOGGER.debug("下载完成:" + chunkInfo.getIndex() + "\t" + chunkInfo.getDownSize());
taskInfo.refresh();
if (callback != null) {
callback.onDone(bootstrap.getHttpDownInfo());
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lee.study</groupId>
<artifactId>proxyee-down</artifactId>
<version>2.0</version>
<version>2.01</version>
<packaging>pom</packaging>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion sniff/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.0</version>
<version>2.01</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.0</version>
<version>2.01</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class GithubUpdateService implements UpdateService {

private static final String UPDATE_CORE_FILE_NAME = "proxyee-down-core.jar";
private static final String HOST = "github.com";

@Override
Expand All @@ -29,7 +30,7 @@ public UpdateInfo check(float currVersion) throws Exception {
if (maxVersion > currVersion) {
updateInfo.setVersion(maxVersion);
for (Element element : releaseDiv.select(".d-block.py-2")) {
if (UPDATE_FILE_NAME.equalsIgnoreCase(element.select("strong").text())) {
if (UPDATE_CORE_FILE_NAME.equalsIgnoreCase(element.select("strong").text())) {
updateInfo.setUrl("https://" + HOST + element.select("a").attr("href"));
break;
}
Expand All @@ -53,7 +54,7 @@ public HttpDownBootstrap update(UpdateInfo updateInfo)
.getTaskInfo(requestInfo, null, HttpDownConstant.clientSslContext,
HttpDownConstant.clientLoopGroup)
.setConnections(32)
.setFileName(UPDATE_FILE_NAME + ".bak")
.setFileName(UPDATE_CORE_FILE_NAME + ".bak")
.setFilePath(HttpDownConstant.MAIN_PATH);
HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, requestInfo, null);
HttpDownBootstrap bootstrap = new HttpDownBootstrap(httpDownInfo,
Expand Down
2 changes: 0 additions & 2 deletions ui/src/main/java/lee/study/down/update/UpdateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

public interface UpdateService {

String UPDATE_FILE_NAME = "proxyee-down-core.jar";

UpdateInfo check(float currVersion) throws Exception;

HttpDownBootstrap update(UpdateInfo updateInfo) throws Exception;
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.version=2.0
app.version=2.01
spring.profiles.active=prd
#server.port= 8443
#server.ssl.key-store=classpath:server.p12
Expand Down
38 changes: 17 additions & 21 deletions ui/view/src/components/TaskList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</p>
<p>
<span>速度:</span>
<b>{{sizeFmt(speed(task), '0B')}}/s</b>
<b>{{sizeFmt(speedTask(task), '0B')}}/s</b>
</p>
<p>
<span>状态:</span>
Expand All @@ -40,7 +40,7 @@
<task-progress :text-inside="true" :stroke-width="18"
:percentage="task.totalProgress||progress(chunk)"
:status="status(chunk)"></task-progress>
<span>{{sizeFmt(speed(chunk), '0B')}}/s</span>
<span>{{sizeFmt(speedChunk(chunk), '0B')}}/s</span>
</li>
</ul>
<task-progress type="circle"
Expand Down Expand Up @@ -103,15 +103,23 @@
}
return 0;
},
speed(task) {
if (task.status == 7 || task.status == 5) {
return this.speedAvg(task);
speedTask(task) {
let sumSpeed = task.chunkInfoList.map((chunk)=>{
return this.speedChunk(chunk);
}).reduce((speed1, speed2) => {
return speed1 + speed2;
});
return sumSpeed;
},
speedChunk(chunk) {
if (chunk.status == 7 || chunk.status == 5) {
return this.speedAvg(chunk);
} else {
let speed = this.speedInterval(task);
if (task.speedCount > 5 || speed > 0) {
let speed = this.speedInterval(chunk);
if (chunk.speedCount > 5 || speed > 0) {
return speed;
} else {
return this.speedAvg(task);
return this.speedAvg(chunk);
}
}
},
Expand All @@ -138,7 +146,7 @@
if (task.status == 5) {
return '暂停中';
}
let speed = this.speed(task);
let speed = this.speedTask(task);
if (speed) {
return Util.timeFmt((task.totalSize - task.downSize) / speed);
} else {
Expand Down Expand Up @@ -227,18 +235,6 @@
this.tasks = msg.map((task1) => {
this.tasks.forEach((task2) => {
if (task2.id == task1.id) {
task1.intervalTime = task1.lastTime - task2.lastTime;
task1.intervalDownSize = task1.downSize - task2.downSize;
task1.speedCount = task2.speedCount;
if (task1.intervalDownSize == 0) {
if (!task1.speedCount) {
task1.speedCount = 1;
} else {
task1.speedCount++;
}
} else {
task1.speedCount = 1;
}
task1.chunkInfoList.forEach((chunk, index) => {
chunk.intervalTime = chunk.lastTime - task2.chunkInfoList[index].lastTime;
chunk.intervalDownSize = chunk.downSize - task2.chunkInfoList[index].downSize;
Expand Down
2 changes: 1 addition & 1 deletion update/update.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="common" />
<orderEntry type="library" name="Maven: lee.study:proxyee-down-common:2.0" level="project" />
</component>
</module>

0 comments on commit 97ac51f

Please sign in to comment.