Skip to content

Commit

Permalink
更新至2.54
Browse files Browse the repository at this point in the history
1.调整文件写入方式,修复写入文件占用系统内存和写入移动硬盘卡死问题。
2.不再区分32位和64位系统
3.修复手动创建任务时正确识别端口号的问题
4.修复手动创建任务时,重定向带cookie丢失问题
5.修复第一次启动时,证书安装引导界面可能被遮盖的问题
  • Loading branch information
monkeyWie committed May 16, 2018
1 parent 6acd9c6 commit 44bd329
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 206 deletions.
31 changes: 18 additions & 13 deletions .guide/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,45 @@
**先尝试重启软件和浏览器,若还是不显示可以[安装switchy插件](https://github.com/monkeyWie/proxyee-down/blob/master/.guide/common/switchy/read.md)进行下载**
</details>
<details>
<summary>运行时提示证书安装失败?</summary>
<summary>下载百度云出现pcs server refuse?</summary>

**请按照教程里的[手动安装证书](https://github.com/monkeyWie/proxyee-down/blob/master/.guide/common/ca/read.md)步骤进行安装**
**由于百度云服务器对批量下载限制了并发连接数,在有百度云批量下载任务时,再去创建批量下载的任务百度云就会检查到,若要下载可以暂停下载器正在下载的任务然后再创建。**
</details>
<details>
<summary>下载百度云出现file not exist?</summary>

**若是下载文件夹,文件夹或父级文件夹名称中不能含有+号,有+号的话请修改名称后再下载。**
**其他情况请尝试登录百度云再下载或在自己网盘新建一个文件夹再转存进来重新分享新文件夹再下载。**
</details>
<details>
<summary>下载百度云出现sock connect error?</summary>

**把浏览器地址栏的地址域名替换成yqall02.baidupcs.com或者d11.baidupcs.com再访问。**
</details>
<details>
<summary>百度云下载速度太慢?</summary>

**新建任务时调高分段数,若还是下载慢可能单文件下载被百度云限速了,请尝试批量下载(选中文件夹或多个文件一起下载)。**
**新建任务时调高分段数,若还是下载慢可以尝试将资源分享,然后退出帐号或者开启隐私窗口访问下载(避免帐号被限速),**最好是单文件下载,批量下载现在可能会被限速而且可能会卡住下不动****
</details>
<details>
<summary>百度云下载一直没有速度?</summary>

**参考[#246](https://github.com/monkeyWie/proxyee-down/issues/246#issuecomment-378516262)**
</details>
<details>
<summary>百度云下载没有弹出下载页面?</summary>
<summary>下载进度一直不动或任务状态显示失败怎么解决?</summary>

**若是下载文件夹,文件夹或父级文件夹名称中不能含有+号,有+号的话请修改名称后再下载。**
**其他情况请尝试登录百度云再下载或在自己网盘新建一个文件夹再转存进来重新分享新文件夹再下载。**
**这种情况一般都是下载链接失效了,需要刷新下载链接,具体[查看](https://github.com/monkeyWie/proxyee-down/blob/master/.guide/common/refresh/read.md)**
</details>
<details>
<summary>百度云下载的压缩文件打不开,提示文件损坏?</summary>

**使用下载器工具里的百度云解压工具进行解压。**
</details>
<details>
<summary>下载进度一直不动或任务状态显示失败怎么解决?</summary>
<summary>运行时提示证书安装失败?</summary>

**这种情况一般都是下载链接失效了,需要刷新下载链接,具体[查看](https://github.com/monkeyWie/proxyee-down/blob/master/.guide/common/refresh/read.md)**
**请按照教程里的[手动安装证书](https://github.com/monkeyWie/proxyee-down/blob/master/.guide/common/ca/read.md)步骤进行安装**
</details>
<details>
<summary>关闭软件后无法正常上网?</summary>
Expand All @@ -44,9 +54,4 @@
<summary>是否支持断点下载?</summary>

**支持。**
</details>
<details>
<summary>任务列表界面不显示下载速度?</summary>

**点击任务列表中的任务圈即可显示。**
</details>
2 changes: 1 addition & 1 deletion common/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.53</version>
<version>2.54</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
19 changes: 19 additions & 0 deletions common/src/main/java/lee/study/down/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Stack;
import java.util.UUID;
Expand Down Expand Up @@ -299,4 +304,18 @@ public static String renameIfExists(String path) {
}
return file.getName();
}

/**
* 创建指定大小的Sparse File
*/
public static void createSparseFile(String filePath, long length) throws IOException {
Path path = Paths.get(filePath);
Files.deleteIfExists(path);
try (
SeekableByteChannel channel = Files.newByteChannel(path, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE, StandardOpenOption.SPARSE)
) {
channel.position(length - 1);
channel.write(ByteBuffer.wrap(new byte[]{0}));
}
}
}
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.53</version>
<version>2.54</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.slf4j.LoggerFactory;

@Data
@AllArgsConstructor
public abstract class AbstractHttpDownBootstrap {

protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractHttpDownBootstrap.class);
Expand All @@ -54,11 +53,20 @@ public abstract class AbstractHttpDownBootstrap {
private HttpDownInfo httpDownInfo;
private int retryCount;
private SslContext clientSslContext;
private NioEventLoopGroup clientLoopGroup;
private HttpDownCallback callback;
private TimeoutCheckTask timeoutCheckTask;
private final Map<Integer, Map<String, Object>> attr = new HashMap<>();

public AbstractHttpDownBootstrap(HttpDownInfo httpDownInfo, int retryCount, SslContext clientSslContext, HttpDownCallback callback, TimeoutCheckTask timeoutCheckTask) {
this.httpDownInfo = httpDownInfo;
this.retryCount = retryCount;
this.clientSslContext = clientSslContext;
this.callback = callback;
this.timeoutCheckTask = timeoutCheckTask;
}

private NioEventLoopGroup clientLoopGroup;

public void startDown() throws Exception {
TaskInfo taskInfo = httpDownInfo.getTaskInfo();
taskInfo.buildChunkInfoList();
Expand All @@ -77,15 +85,12 @@ public void startDown() throws Exception {
throw new BootstrapException("文件名已存在,请修改文件名");
}
//创建文件
try (
RandomAccessFile randomAccessFile = new RandomAccessFile(taskInfo.buildTaskFilePath(), "rw")
) {
randomAccessFile.setLength(taskInfo.getTotalSize());
}
FileUtil.createSparseFile(taskInfo.buildTaskFilePath(), taskInfo.getTotalSize());
//文件下载开始回调
taskInfo.reset();
taskInfo.setStatus(HttpDownStatus.RUNNING);
taskInfo.setStartTime(System.currentTimeMillis());
clientLoopGroup = new NioEventLoopGroup(1);
for (int i = 0; i < taskInfo.getChunkInfoList().size(); i++) {
ChunkInfo chunkInfo = taskInfo.getChunkInfoList().get(i);
//设置状态和时间
Expand Down Expand Up @@ -236,6 +241,7 @@ public void continueDown()
taskInfo.setPauseTime(
taskInfo.getPauseTime() + (curTime - taskInfo.getLastTime()));
taskInfo.setLastTime(curTime);
clientLoopGroup = new NioEventLoopGroup(1);
for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) {
synchronized (chunkInfo) {
if (chunkInfo.getStatus() == HttpDownStatus.PAUSE
Expand Down Expand Up @@ -291,6 +297,9 @@ public void close(int status) {
}
}
}
if (clientLoopGroup != null) {
clientLoopGroup.shutdownGracefully();
}
}

public void close() {
Expand Down
41 changes: 41 additions & 0 deletions core/src/main/java/lee/study/down/boot/HttpDownBootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package lee.study.down.boot;

import io.netty.handler.ssl.SslContext;
import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import lee.study.down.dispatch.HttpDownCallback;
import lee.study.down.model.ChunkInfo;
import lee.study.down.model.HttpDownInfo;

public class HttpDownBootstrap extends AbstractHttpDownBootstrap {


public HttpDownBootstrap(HttpDownInfo httpDownInfo, int retryCount, SslContext clientSslContext, HttpDownCallback callback, TimeoutCheckTask timeoutCheckTask) {
super(httpDownInfo, retryCount, clientSslContext, callback, timeoutCheckTask);
}

@Override
public int doFileWriter(ChunkInfo chunkInfo, ByteBuffer buffer) throws IOException {
int ret = -1;
Closeable closeable = (Closeable) getAttr(chunkInfo, ATTR_FILE_CLOSEABLE);
if (closeable != null) {
ret = buffer.remaining();
SeekableByteChannel fileChannel = (SeekableByteChannel) closeable;
fileChannel.write(buffer);
}
return ret;
}

@Override
public Closeable initFileWriter(ChunkInfo chunkInfo) throws Exception {
SeekableByteChannel fileChannel = Files.newByteChannel(Paths.get(getHttpDownInfo().getTaskInfo().buildTaskFilePath()), StandardOpenOption.WRITE);
fileChannel.position(chunkInfo.getOriStartPosition() + chunkInfo.getDownSize());
setAttr(chunkInfo, ATTR_FILE_CLOSEABLE, fileChannel);
return fileChannel;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package lee.study.down.boot;

import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.handler.ssl.SslContext;
import lee.study.down.dispatch.HttpDownCallback;
import lee.study.down.model.HttpDownInfo;
import lee.study.down.util.OsUtil;

public class HttpDownBootstrapFactory {

private static volatile TimeoutCheckTask timeoutCheck;

public static AbstractHttpDownBootstrap create(HttpDownInfo httpDownInfo, int retryCount,
SslContext clientSslContext, NioEventLoopGroup clientLoopGroup, HttpDownCallback callback) {
public static AbstractHttpDownBootstrap create(HttpDownInfo httpDownInfo, int retryCount, SslContext clientSslContext, HttpDownCallback callback) {
if (timeoutCheck == null) {
synchronized (HttpDownBootstrapFactory.class) {
if (timeoutCheck == null) {
Expand All @@ -20,14 +17,7 @@ public static AbstractHttpDownBootstrap create(HttpDownInfo httpDownInfo, int re
}
}
}
AbstractHttpDownBootstrap bootstrap;
if (OsUtil.is64()) {
bootstrap = new X64HttpDownBootstrap(httpDownInfo, retryCount, clientSslContext,
clientLoopGroup, callback, timeoutCheck);
} else {
bootstrap = new X86HttpDownBootstrap(httpDownInfo, retryCount, clientSslContext,
clientLoopGroup, callback, timeoutCheck);
}
AbstractHttpDownBootstrap bootstrap = new HttpDownBootstrap(httpDownInfo, retryCount, clientSslContext, callback, timeoutCheck);
timeoutCheck.addBoot(bootstrap);
return bootstrap;
}
Expand Down
58 changes: 0 additions & 58 deletions core/src/main/java/lee/study/down/boot/X64HttpDownBootstrap.java

This file was deleted.

45 changes: 0 additions & 45 deletions core/src/main/java/lee/study/down/boot/X86HttpDownBootstrap.java

This file was deleted.

Loading

0 comments on commit 44bd329

Please sign in to comment.