Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
1.百度云插件加载提示优化
Browse files Browse the repository at this point in the history
2.百度云解压工具bug修复
3.修复异常打印阻塞netty线程导致代理无法加载网页问题
4.相关页面微调
5.log打印修改
6.安装路径中有+号导致程序无法运行问题修复
7.下载速度显示不正确问题修复
8.guide update
  • Loading branch information
monkeyWie committed Jan 20, 2018
1 parent 49a32eb commit 5ca49b5
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 57 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
*由于windows权限问题,保存目录不能放在C盘,请修改保存目录*
8. **下载过程中是否可以关闭浏览器?**
*可以,但是proxyee.exe软件不能关闭*
9. **关机后是否能接着下载**
9. **电脑重启后是否能接着下载**
*可以*
10. **切换了下载的代理服务器导致网页浏览过慢?**
*下载代理服务器只是用与嗅探下载请求的,若没有新的下载任务可以不使用*
11. **百度云下载没有弹出下载页面?**
*浏览器里按F12,看下Console里是否有请求为403,如果是403请尝试重新分享文件再下载*
*浏览器里按F12,看下Console里是否有请求为403,如果是403请尝试登录再下载或重新分享文件再下载*
12. **任务列表界面不显示下载速度?**
*点击任务列表中的任务圈即可显示下载详情*

# 开发
本项目依赖[proxyee](https://github.com/monkeyWie/proxyee),因为还没上传maven中央仓库,需自行编译打包至本地仓库。
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/lee/study/down/io/BdyZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public static void unzip(String path, String toPath) throws IOException {
isEnd = true;
} else if (!ByteUtil.matchToken(fileChannel, fileChannel.position() + fileSize,
ZIP_ENTRY_FILE_HEARD)) {
//找到真实文件长度
fileSize = ByteUtil.getNextTokenSize(fileChannel, ZIP_ENTRY_FILE_HEARD, ZIP_ENTRY_DIR_HEARD);
//找到真实文件长度 大于4G找4G之后的标识
fileSize = ByteUtil.getNextTokenSize(fileChannel,fileChannel.position()+Integer.MAX_VALUE, ZIP_ENTRY_FILE_HEARD, ZIP_ENTRY_DIR_HEARD);
if (ByteUtil.matchToken(fileChannel, fileChannel.position() + fileSize, ZIP_ENTRY_DIR_HEARD)) {
isEnd = true;
}
Expand Down
7 changes: 1 addition & 6 deletions common/src/main/java/lee/study/down/util/ByteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,14 @@ public static int findBytes(ByteBuffer buffer, byte[]... btsArr) {
return -1;
}

public static long getNextTokenSize(FileChannel fileChannel, byte[]... btsArr)
throws IOException {
return getNextTokenSize(fileChannel, -1, btsArr);
}

public static long getNextTokenSize(FileChannel fileChannel, long position, byte[]... btsArr)
throws IOException {
long ret = -1;
ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
long startPosition = fileChannel.position();
if (position >= 0) {
fileChannel.position(position);
}
long startPosition = fileChannel.position();
outer:
while (fileChannel.read(buffer) != -1) {
buffer.flip();
Expand Down
54 changes: 31 additions & 23 deletions common/src/main/java/lee/study/down/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,44 @@ public static long getFileSize(String path) {
}

public static File createFileSmart(String path) throws IOException {
File file = new File(path);
if (file.exists()) {
file.delete();
file.createNewFile();
} else {
createDirSmart(file.getParent());
file.createNewFile();
try {
File file = new File(path);
if (file.exists()) {
file.delete();
file.createNewFile();
} else {
createDirSmart(file.getParent());
file.createNewFile();
}
return file;
} catch (IOException e) {
throw new IOException("createFileSmart=" + path, e);
}
return file;
}

public static File createDirSmart(String path) throws IOException {
File file = new File(path);
if (file.exists()) {
file.delete();
file.mkdir();
} else {
Stack<File> stack = new Stack<>();
while (file != null) {
stack.push(file);
file = file.getParentFile();
}
while (stack.size() > 0) {
File dir = stack.pop();
if (!dir.exists()) {
dir.mkdir();
try {
File file = new File(path);
if (file.exists()) {
file.delete();
file.mkdir();
} else {
Stack<File> stack = new Stack<>();
while (file != null) {
stack.push(file);
file = file.getParentFile();
}
while (stack.size() > 0) {
File dir = stack.pop();
if (!dir.exists()) {
dir.mkdir();
}
}
}
return file;
} catch (Exception e) {
throw new IOException("createDirSmart=" + path, e);
}
return file;
}

public static void unmap(MappedByteBuffer mappedBuffer) throws IOException {
Expand Down
12 changes: 6 additions & 6 deletions common/src/main/java/lee/study/down/util/OsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

public class OsUtil {

private static final Logger LOGGER = LoggerFactory.getLogger(OsUtil.class);

private static final String REG_HEAD = "reg add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v ";
private static final String REG_TAIL = " /f";
private static final String PROXY_ENABLE_KEY = "ProxyEnable ";
Expand All @@ -38,7 +36,9 @@ public static int getFreePort(int defaultPort) throws Exception {
} catch (IOException e1) {
throw e1;
} finally {
serverSocket2.close();
if (serverSocket2 != null) {
serverSocket2.close();
}
}
} finally {
if (serverSocket1 != null) {
Expand Down Expand Up @@ -70,18 +70,18 @@ public static boolean isBusyPort(int port) {
return ret;
}

public static void openBrowse(String url) {
public static void openBrowse(String url) throws Exception {
Desktop desktop = Desktop.getDesktop();
boolean flag = Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE);
if (flag) {
try {
URI uri = new URI(url);
desktop.browse(uri);
} catch (Exception e) {
LOGGER.error("can't open browse", e);
throw new Exception("can't open browse", e);
}
} else {
LOGGER.error("don't support browse");
throw new Exception("don't support browse");
}
}

Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/lee/study/down/util/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PathUtil {
}
}
if (needDecode) {
ROOT_PATH = ROOT_PATH.replaceAll("\\+", "%2b");
try {
ROOT_PATH = URLDecoder.decode(ROOT_PATH, "UTF-8");
} catch (UnsupportedEncodingException e) {
Expand Down
13 changes: 13 additions & 0 deletions sniff/src/main/java/lee/study/down/HttpDownProxyServer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package lee.study.down;

import io.netty.channel.Channel;
import lee.study.down.intercept.BdyIntercept;
import lee.study.down.intercept.HttpDownSniffIntercept;
import lee.study.down.intercept.common.HttpDownInterceptFactory;
import lee.study.proxyee.exception.HttpProxyExceptionHandle;
import lee.study.proxyee.intercept.CertDownIntercept;
import lee.study.proxyee.intercept.HttpProxyIntercept;
import lee.study.proxyee.intercept.HttpProxyInterceptInitializer;
Expand Down Expand Up @@ -46,6 +48,17 @@ public void init(HttpProxyInterceptPipeline pipeline) {
pipeline.addLast(downIntercept);
}
}
})
.httpProxyExceptionHandle(new HttpProxyExceptionHandle() {
@Override
public void beforeCatch(Channel clientChannel, Throwable cause) throws Exception {
LOGGER.warn("beforeCatch:",cause);
}

@Override
public void afterCatch(Channel clientChannel, Channel proxyChannel, Throwable cause) throws Exception {
LOGGER.warn("afterCatch:",cause);
}
}).start(port);
}

Expand Down
23 changes: 21 additions & 2 deletions ui/src/main/java/lee/study/down/HttpDownApplication.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package lee.study.down;

import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakDetector.Level;
import javax.swing.JOptionPane;
import lee.study.down.constant.HttpDownConstant;
import lee.study.down.content.ContentManager;
Expand All @@ -8,6 +10,8 @@
import lee.study.down.task.HttpDownErrorCheckTask;
import lee.study.down.task.HttpDownProgressEventTask;
import lee.study.down.util.OsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -19,6 +23,8 @@
@SpringBootApplication
public class HttpDownApplication implements InitializingBean, EmbeddedServletContainerCustomizer {

private static final Logger LOGGER = LoggerFactory.getLogger(HttpDownApplication.class);

static {
//设置slf4j日志打印目录
System.setProperty("LOG_PATH", HttpDownConstant.HOME_PATH);
Expand Down Expand Up @@ -48,7 +54,11 @@ public static void main(String[] args) throws Exception {
//托盘初始化
new HttpDownTray(application.homeUrl).init();
//打开浏览器访问前端页面
OsUtil.openBrowse(application.homeUrl);
try {
OsUtil.openBrowse(application.homeUrl);
} catch (Exception e) {
LOGGER.error("openBrowse:", e);
}
//启动线程
new HttpDownErrorCheckTask().start();
new HttpDownProgressEventTask().start();
Expand All @@ -73,7 +83,16 @@ public HttpDownProxyServer getProxyServer() {
@Override
public void afterPropertiesSet() throws Exception {
if (!"dev".equalsIgnoreCase(active.trim())) {
viewServerPort = tomcatServerPort = OsUtil.getFreePort(tomcatServerPort);
try {
viewServerPort = tomcatServerPort = OsUtil.getFreePort(tomcatServerPort);
} catch (Exception e) {
LOGGER.error("getFreePort:", e);
JOptionPane.showMessageDialog(null, "系统异常,请尝试在命令行中执行netsh winsock reset,再运行软件", "运行警告",
JOptionPane.ERROR_MESSAGE);
throw e;
}
} else {
ResourceLeakDetector.setLevel(Level.ADVANCED);
}
homeUrl = "http://127.0.0.1:" + viewServerPort;
}
Expand Down
18 changes: 16 additions & 2 deletions ui/src/main/java/lee/study/down/gui/HttpDownTray.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
import java.net.URL;
import javax.swing.JFrame;
import lee.study.down.util.OsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* 系统托盘
*/
public class HttpDownTray extends JFrame {

private static final Logger LOGGER = LoggerFactory.getLogger(HttpDownTray.class);

private static final long serialVersionUID = 7380717165373045846L;

private String homeUrl;
Expand All @@ -39,7 +43,11 @@ public void init() throws Exception {
public void mouseClicked(MouseEvent event) {
// 判断是否双击了鼠标
if (event.getClickCount() == 2) {
OsUtil.openBrowse(homeUrl);
try {
OsUtil.openBrowse(homeUrl);
} catch (Exception e) {
LOGGER.error("openBrowse:", e);
}
}
}
});
Expand All @@ -50,7 +58,13 @@ public void mouseClicked(MouseEvent event) {
popupMenu.add(openItem);
// popupMenu.addSeparator();
popupMenu.add(closeItem);
openItem.addActionListener((event) -> OsUtil.openBrowse(homeUrl));
openItem.addActionListener((event) -> {
try {
OsUtil.openBrowse(homeUrl);
} catch (Exception e) {
LOGGER.error("openBrowse:", e);
}
});
closeItem.addActionListener((event) -> System.exit(0));
// 为托盘图标加弹出菜弹
trayIcon.setPopupMenu(popupMenu);
Expand Down
25 changes: 16 additions & 9 deletions ui/src/main/resources/hookjs/bdyHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ if (Object.defineProperty) {
navigator.__defineGetter__('userAgent', uaHook);
}
window.onload = function () {
var pd_dd = $('.module-header-wrapper dl:first').find('dd:first');
var pd_parent_span_class = pd_dd.find(">span").attr("class").split(" ")[0];
var pd_child_span_class = pd_dd.find(">span>span").attr("class").split(" ")[0];
$('.module-header-wrapper dl:first').find('dd:first').append(
'<span class="'+pd_parent_span_class+' find-light">'
+ '<a href="https://github.com/monkeyWie/proxyee-down" target="_blank" title="proxyee-down">proxyee-down</a>'
+ '<span class="'+pd_child_span_class+'"></span>'
+ '<i class="find-light-icon"></i>'
+ '</span>');
var initHookInterval = setInterval(function(){
try {
var pd_dd = $('.module-header-wrapper dl:first').find('dd:first');
if(pd_dd.find(">span").attr("class")&&pd_dd.find(">span>span").attr("class")){
var pd_parent_span_class = pd_dd.find(">span").attr("class").split(" ")[0];
var pd_child_span_class = pd_dd.find(">span>span").attr("class").split(" ")[0];
$('.module-header-wrapper dl:first').find('dd:first').append(
'<span class="'+pd_parent_span_class+' find-light">'
+ '<a href="https://github.com/monkeyWie/proxyee-down" target="_blank" title="百度云下载插件加载成功">proxyee-down</a>'
+ '<span class="'+pd_child_span_class+'"></span>'
+ '<i class="find-light-icon"></i>'
+ '</span>');
clearInterval(initHookInterval);
}
}catch (e){}
},200)
}
6 changes: 3 additions & 3 deletions ui/view/src/components/AboutPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<el-col :span="16">
<span>
<a target="_blank"
href="https://github.com/monkeyWie/proxyee-down/blob/master/README.md">官方</a>
href="https://github.com/monkeyWie/proxyee-down/blob/master/README.md">@官方编写</a>
</span>
<span>
<span style="padding-left: 20px">
<a target="_blank"
href="https://www.zhanghuanglong.com/detail/another-download-of-magic-proxyee-down">出品@°只为大大</a>
href="https://www.zhanghuanglong.com/detail/another-download-of-magic-proxyee-down">@°只为大大编写</a>
</span>
</el-col>
</el-row>
Expand Down
9 changes: 7 additions & 2 deletions ui/view/src/components/TaskList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@
return 0;
},
speedTask(task) {
let sumSpeed = task.chunkInfoList.map((chunk)=>{
if(task.status == 7 || task.status == 5){
return this.speedAvg(task);
}
return task.chunkInfoList.map((chunk)=>{
if(chunk.status == 7 || chunk.status == 5){
return 0;
}
return this.speedChunk(chunk);
}).reduce((speed1, speed2) => {
return speed1 + speed2;
});
return sumSpeed;
},
speedChunk(chunk) {
if (chunk.status == 7 || chunk.status == 5) {
Expand Down

0 comments on commit 5ca49b5

Please sign in to comment.