Skip to content

Commit

Permalink
1.支持32位和64位操作系统
Browse files Browse the repository at this point in the history
2.百度云解压工具添加文件头校验
3.托盘功能新增全局代理配置和证书安装引导
4.相关UI调整
5.linux和mac无法运行问题修复
6.教程文档更新
  • Loading branch information
monkeyWie committed Jan 23, 2018
1 parent d71a17e commit dfbd79f
Show file tree
Hide file tree
Showing 38 changed files with 410 additions and 196 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
2. 百度云合并下载解压工具(可解压4G大文件)
## 使用教程
### 下载
[地址](https://github.com/monkeyWie/proxyee-down/releases)
*注:从1.6版本开始下载器仅支持64位操作系统,若是32位操作系统请下载1.5版本*
[前往](https://github.com/monkeyWie/proxyee-down/releases)
#### windows
根据操作系统的位数选择对应proxyee-down-x.xx-windows-xxx.zip文件进行下载。
#### 非windows
1. 根据操作系统[下载](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)对应JRE进行安装。
2. 下载proxyee-down-x.xx-jar.zip文件
### 安装
1. [Windows安装教程](https://github.com/monkeyWie/proxyee-down/blob/master/view/guide/windows/read.md)
2. [MAC安装教程](https://github.com/monkeyWie/proxyee-down/blob/master/view/guide/mac/read.md)
3. [Linux安装教程](https://github.com/monkeyWie/proxyee-down/blob/master/view/guide/linux/read.md)
### 百度云破解
在2.02+版本中,下载器配置正确之后,打开百度云页面会有如下提示
![百度云破解](https://github.com/monkeyWie/proxyee-down/raw/master/view/bdy-hook.png)
### 安装成功
在安装成功之后,浏览器下载资源时会跳转到创建任务页面,然后选择保存的路径和分段数进行创建下载任务。
![新建任务](https://github.com/monkeyWie/proxyee-down/raw/master/view/new-task.png)
### 常见问题
1. **证书页面无法访问?**
*先确认软件是否运行,运行还是无法访问可能是端口号被占用,打开软件设置页面修改代理端口号,保存后再访问http://127.0.0.1:修改后的端口号。*
Expand All @@ -36,7 +43,7 @@
10. **切换了下载的代理服务器导致网页浏览过慢?**
*下载代理服务器只是用与嗅探下载请求的,若没有新的下载任务可以不使用*
11. **百度云下载没有弹出下载页面?**
*浏览器里按F12,看下Console里是否有请求为403,如果是403请尝试登录再下载或重新分享文件再下载*
*浏览器里按F12,看下Console里是否有请求为403或404,如果是403请尝试登录再下载或重新分享文件再下载,404的话请尝试修改文件或文件夹名称再重新下载*
12. **任务列表界面不显示下载速度?**
*点击任务列表中的任务圈即可显示下载详情*

Expand Down
91 changes: 56 additions & 35 deletions common/src/main/java/lee/study/down/io/BdyZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.Arrays;
import lee.study.down.util.ByteUtil;
import lee.study.down.util.FileUtil;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -87,48 +88,68 @@ public static BdyZipEntry getNextBdyZipEntry(FileChannel fileChannel) throws IOE
public static void unzip(String path, String toPath) throws IOException {
File zipFile = new File(path);
File toDir = FileUtil.createDirSmart(toPath);
FileChannel fileChannel = new RandomAccessFile(zipFile, "rw").getChannel();
boolean isEnd = false;
while (!isEnd) {
BdyZipEntry bdyZipEntry = getNextBdyZipEntry(fileChannel);
long fileSize = bdyZipEntry.getCompressedSize();
if (ByteUtil
.matchToken(fileChannel, fileChannel.position() + fileSize, ZIP_ENTRY_DIR_HEARD)) {
isEnd = true;
} else if (!ByteUtil.matchToken(fileChannel, fileChannel.position() + fileSize,
ZIP_ENTRY_FILE_HEARD)) {
//找到真实文件长度 大于4G找4G之后的标识
fileSize = ByteUtil
.getNextTokenSize(fileChannel, fileChannel.position() + _4G,
ZIP_ENTRY_FILE_HEARD, ZIP_ENTRY_DIR_HEARD);
System.out.println(fileSize);
try (
FileChannel fileChannel = new RandomAccessFile(zipFile, "rw").getChannel()
) {
boolean isEnd = false;
while (!isEnd) {
BdyZipEntry bdyZipEntry = getNextBdyZipEntry(fileChannel);
long fileSize = bdyZipEntry.getCompressedSize();
if (ByteUtil
.matchToken(fileChannel, fileChannel.position() + fileSize, ZIP_ENTRY_DIR_HEARD)) {
isEnd = true;
} else if (!ByteUtil.matchToken(fileChannel, fileChannel.position() + fileSize,
ZIP_ENTRY_FILE_HEARD)) {
//找到真实文件长度 大于4G找4G之后的标识
fileSize = ByteUtil
.getNextTokenSize(fileChannel, fileChannel.position() + _4G,
ZIP_ENTRY_FILE_HEARD, ZIP_ENTRY_DIR_HEARD);
System.out.println(fileSize);
if (ByteUtil
.matchToken(fileChannel, fileChannel.position() + fileSize, ZIP_ENTRY_DIR_HEARD)) {
isEnd = true;
}
}
}
LOGGER.debug("bdyUnzip:" + bdyZipEntry.getFileName() + "\t" + fileSize + "\t" + isEnd);
if (fileSize == 0
&& bdyZipEntry.getFileName().lastIndexOf("/") == bdyZipEntry.getFileName().length() - 1) {
FileUtil.createDirSmart(toDir.getPath() + File.separator + bdyZipEntry.getFileName());
} else {
File unzipFile = FileUtil
.createFileSmart(toDir.getPath() + File.separator + bdyZipEntry.getFileName());
FileChannel unzipChannel = new RandomAccessFile(unzipFile, "rw").getChannel();
long position = fileChannel.position();
long remaining = fileSize;
while (remaining > 0) {
long transferred = fileChannel.transferTo(position, remaining, unzipChannel);
remaining -= transferred;
position += transferred;
LOGGER.debug("bdyUnzip:" + bdyZipEntry.getFileName() + "\t" + fileSize + "\t" + isEnd);
if (fileSize == 0
&& bdyZipEntry.getFileName().lastIndexOf("/")
== bdyZipEntry.getFileName().length() - 1) {
FileUtil.createDirSmart(toDir.getPath() + File.separator + bdyZipEntry.getFileName());
} else {
File unzipFile = FileUtil
.createFileSmart(toDir.getPath() + File.separator + bdyZipEntry.getFileName());
FileChannel unzipChannel = new RandomAccessFile(unzipFile, "rw").getChannel();
long position = fileChannel.position();
long remaining = fileSize;
while (remaining > 0) {
long transferred = fileChannel.transferTo(position, remaining, unzipChannel);
remaining -= transferred;
position += transferred;
}
unzipChannel.close();
fileChannel.position(fileChannel.position() + fileSize);
}
if (fileChannel.position() == fileChannel.size()) {
isEnd = true;
}
unzipChannel.close();
fileChannel.position(fileChannel.position() + fileSize);
}
if (fileChannel.position() == fileChannel.size()) {
isEnd = true;
}
}

/**
* 检查是否为百度云合并下载ZIP
*/
public static boolean isBdyZip(String filePath) throws IOException {
try (
RandomAccessFile raf = new RandomAccessFile(filePath, "rw")
) {
byte[] speHeard = new byte[10];
raf.read(speHeard);
if (Arrays.equals(speHeard, ZIP_ENTRY_FILE_HEARD)
|| Arrays.equals(speHeard, ZIP_ENTRY_DIR_HEARD)) {
return true;
}
}
fileChannel.close();
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public final void put(ByteBuffer byteBuffer) throws IOException {
bufferList.get(index).put(byteBuffer);
}
} catch (Exception e) {
throw new IOException("LargeMappedByteBuffer put rawPosition-"+rawPosition+" size-"+size, e);
throw new IOException(
"LargeMappedByteBuffer put rawPosition-" + rawPosition + "\tposition-" + position
+ "\tsize-" + size, e);
}
}

Expand Down
26 changes: 9 additions & 17 deletions common/src/main/java/lee/study/down/util/ByteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,8 @@ public static Object deserialize(String path) throws IOException, ClassNotFoundE
}
}

/*public static byte[] stringToBytes(String str) {
byte[] bts = new byte[str.length()];
for (int i = 0; i < str.length(); i++) {
bts[i] = (byte) str.charAt(i);
}
return bts;
}*/

public static byte[] stringToBytes(String str) {
return str.getBytes();
}

public static int findText(ByteBuf byteBuf, String str) {
byte[] text = stringToBytes(str);
byte[] text = str.getBytes();
int matchIndex = 0;
for (int i = byteBuf.readerIndex(); i < byteBuf.readableBytes(); i++) {
for (int j = matchIndex; j < text.length; j++) {
Expand All @@ -149,12 +137,16 @@ public static int findText(ByteBuf byteBuf, String str) {
}

public static ByteBuf insertText(ByteBuf byteBuf, int index, String str) {
return insertText(byteBuf, index, str, Charset.defaultCharset());
}

public static ByteBuf insertText(ByteBuf byteBuf, int index, String str, Charset charset) {
byte[] begin = new byte[index + 1];
byte[] end = new byte[byteBuf.readableBytes() - begin.length];
byteBuf.readBytes(begin);
byteBuf.readBytes(end);
byteBuf.writeBytes(begin);
byteBuf.writeBytes(stringToBytes(str));
byteBuf.writeBytes(str.getBytes(charset));
byteBuf.writeBytes(end);
return byteBuf;
}
Expand All @@ -176,13 +168,13 @@ public static String btsToHex(byte[] bts) {
}

public static String readJsContent(InputStream inputStream) {
return readJsContent(inputStream,Charset.defaultCharset());
return readJsContent(inputStream, Charset.defaultCharset());
}

public static String readJsContent(InputStream inputStream,Charset charset) {
public static String readJsContent(InputStream inputStream, Charset charset) {
StringBuilder sb = new StringBuilder();
try (
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,charset))
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, charset))
) {
sb.append("<script type=\"text/javascript\">");
String line;
Expand Down
43 changes: 19 additions & 24 deletions common/src/main/java/lee/study/down/util/OsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OsUtil {

Expand Down Expand Up @@ -95,19 +93,21 @@ public static void disabledIEProxy() throws IOException {
Runtime.getRuntime().exec(REG_HEAD + PROXY_ENABLE_KEY + "/d 0" + REG_TYPE_DWORD + REG_TAIL);
}

public static void execFile(InputStream inputStream, String dirPath) throws IOException {
File file = new File(dirPath + File.separator + "ca.crt");
try (
FileOutputStream fos = new FileOutputStream(file)
) {
byte[] bts = new byte[8192];
int len;
while ((len = inputStream.read(bts)) != -1) {
fos.write(bts, 0, len);
}
} finally {
if (inputStream != null) {
inputStream.close();
public static void execFile(InputStream inputStream, String filePath) throws IOException {
File file = new File(filePath);
if (!file.exists()) {
try (
FileOutputStream fos = new FileOutputStream(file)
) {
byte[] bts = new byte[8192];
int len;
while ((len = inputStream.read(bts)) != -1) {
fos.write(bts, 0, len);
}
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
Desktop.getDesktop().open(file);
Expand All @@ -127,6 +127,10 @@ public static boolean isUnix() {
return OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") >= 0;
}

public static boolean isSolaris() {
return (OS.indexOf("sunos") >= 0);
}

private static final String ARCH = System.getProperty("sun.arch.data.model");

public static boolean is64() {
Expand All @@ -136,13 +140,4 @@ public static boolean is64() {
public static boolean is32() {
return "32".equals(ARCH);
}

public static void main(String[] args) {
System.out.println(System.getProperty("sun.arch.data.model"));
}

public static boolean isSolaris() {
return (OS.indexOf("sunos") >= 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,18 @@ public void continueDown()
throws Exception {
TaskInfo taskInfo = httpDownInfo.getTaskInfo();
synchronized (taskInfo) {
if (taskInfo.getStatus() == HttpDownStatus.MERGE_CANCEL) {
merge();
} else {
//如果文件被删除重新开始下载
if (!FileUtil.exists(taskInfo.buildTaskFilePath())) {
close();
startDown();
} else {
taskInfo.setStatus(HttpDownStatus.RUNNING);
long curTime = System.currentTimeMillis();
taskInfo.setPauseTime(
taskInfo.getPauseTime() + (curTime - taskInfo.getLastTime()));
taskInfo.setLastTime(curTime);
for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) {
synchronized (chunkInfo) {
if (chunkInfo.getStatus() == HttpDownStatus.PAUSE) {
chunkInfo.setPauseTime(taskInfo.getPauseTime());
chunkInfo.setLastTime(curTime);
retryChunkDown(chunkInfo, HttpDownStatus.CONNECTING_NORMAL);
}
if (continueDownHandle()) {
taskInfo.setStatus(HttpDownStatus.RUNNING);
long curTime = System.currentTimeMillis();
taskInfo.setPauseTime(
taskInfo.getPauseTime() + (curTime - taskInfo.getLastTime()));
taskInfo.setLastTime(curTime);
for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) {
synchronized (chunkInfo) {
if (chunkInfo.getStatus() == HttpDownStatus.PAUSE) {
chunkInfo.setPauseTime(taskInfo.getPauseTime());
chunkInfo.setLastTime(curTime);
retryChunkDown(chunkInfo, HttpDownStatus.CONNECTING_NORMAL);
}
}
}
Expand All @@ -200,14 +192,18 @@ public void continueDown()
}
}

public abstract boolean continueDownHandle() throws Exception;

public abstract void merge() throws Exception;

public void close(ChunkInfo chunkInfo) {
try {
Channel channel = getChannel(chunkInfo);
Closeable[] fileChannels = getFileWriter(chunkInfo);
LOGGER.debug(
"下载连接关闭:channelId[" + (channel != null ? channel.id() : "null") + "]\t" + chunkInfo);
HttpDownUtil.safeClose(channel, getFileWriter(chunkInfo));
attr.remove(chunkInfo.getIndex());
HttpDownUtil.safeClose(channel, fileChannels);
} catch (Exception e) {
LOGGER.error("closeChunk error", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class HttpDownBootstrapFactory {

public static AbstractHttpDownBootstrap create(HttpDownInfo httpDownInfo,
SslContext clientSslContext, NioEventLoopGroup clientLoopGroup, HttpDownCallback callback) {
/*if (OsUtil.is64()) {
if (OsUtil.is64()) {
return new X64HttpDownBootstrap(httpDownInfo, clientSslContext, clientLoopGroup, callback);
} else {*/
return new X32HttpDownBootstrap(httpDownInfo, clientSslContext, clientLoopGroup, callback);
// }
} else {
return new X32HttpDownBootstrap(httpDownInfo, clientSslContext, clientLoopGroup, callback);
}
}
}
Loading

0 comments on commit dfbd79f

Please sign in to comment.