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

Commit

Permalink
更新升级调整
Browse files Browse the repository at this point in the history
mac shell调整
  • Loading branch information
monkeyWie committed Mar 2, 2018
1 parent 256fb7e commit 1f65e09
Show file tree
Hide file tree
Showing 25 changed files with 174 additions and 177 deletions.
Binary file modified .guide/common/firefox-ca/imgs/1-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 removed .guide/common/firefox-ca/imgs/1-2.png
Binary file not shown.
10 changes: 4 additions & 6 deletions .guide/common/firefox-ca/read.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
## 下载证书
1. 右击软件托盘,点下载证书
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/firefox-ca/imgs/1-1.png)
2. 之后会跳转到下载页面,点击ProxyeeRoot ca.crt进行下载
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/firefox-ca/imgs/1-2.png)
1. 右击软件托盘,点证书目录会跳转到对应目录
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/firefox-ca/imgs/1-1.png)
## 安装证书
1. 打开火狐浏览器并进入设置页面
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/firefox-ca/imgs/2-1.png)
2. 进入火狐浏览器证书管理页面
在设置页面内找到隐私与安全->证书->查看证书,在打开的证书管理页面选中证书机构
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/firefox-ca/imgs/2-2.png)
3. 导入刚刚下载的证书
点击导入,选中刚刚下载的证书
3. 导入刚刚的证书
点击导入,选中刚刚的证书
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/firefox-ca/imgs/2-3-1.png)
把信任框都勾上点击确定
![](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/common/firefox-ca/imgs/2-3-2.png)
Expand Down
Binary file modified .guide/mac/imgs/1-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/mac/imgs/1-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 removed .guide/mac/imgs/4-1.png
Binary file not shown.
Binary file removed .guide/mac/imgs/4-3.png
Binary file not shown.
Binary file removed .guide/mac/imgs/4-4.png
Binary file not shown.
8 changes: 6 additions & 2 deletions .guide/mac/read.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## 下载
进入[下载页面](https://github.com/monkeyWie/proxyee-down/releases),选择对应proxyee-down-x.xx-mac.zip文件进行下载。
## 解压并运行
将下载好的proxyee-down-x.xx-mac.zip解压至电脑任意目录。双击start运行软件,运行成功后会有提示和托盘出现。
![1-1](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/windows/imgs/1-1.png)
将下载好的proxyee-down-x.xx-mac.zip解压至电脑任意目录。双击start运行软件,由于安装证书和切换代理需要root权限,所以在运行软件会提示输入用户密码,输入完按回车确认即可。
![1-1](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/windows/imgs/1-1.png)
运行成功后会有提示和托盘出现。
![1-2](https://github.com/monkeyWie/proxyee-down/raw/master/.guide/windows/imgs/1-2.png)
## safari浏览器
safari浏览器不支持百度云破解插件,建议使用chrome浏览器。
## 火狐浏览器
由于火狐浏览器的特殊性,需要自行安装根证书,查看[安装步骤](https://github.com/monkeyWie/proxyee-down/blob/master/.guide/common/firefox-ca/read.md)
## 完成
Expand Down
Binary file modified .pack/proxyee-down-pack.jar
Binary file not shown.
34 changes: 34 additions & 0 deletions common/src/main/java/lee/study/down/util/FileUtil.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package lee.study.down.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Stack;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class FileUtil {

Expand Down Expand Up @@ -239,4 +245,32 @@ public static boolean canWrite(String path) {
}
return true;
}

public static void unzip(String zipPath, String toPath, String... unzipFile) throws IOException {
try (
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipPath))
) {
toPath = toPath == null ? new File(zipPath).getParent() : toPath;
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
final String entryName = entry.getName();
if (entry.isDirectory() || (unzipFile != null && unzipFile.length > 0
&& Arrays.stream(unzipFile)
.noneMatch((file) -> entryName.equalsIgnoreCase(file)))) {
zipInputStream.closeEntry();
continue;
}
File file = createFileSmart(toPath + File.separator + entryName);
try (
FileOutputStream outputStream = new FileOutputStream(file)
) {
byte[] bts = new byte[8192];
int len;
while ((len = zipInputStream.read(bts)) != -1) {
outputStream.write(bts, 0, len);
}
}
}
}
}
}
40 changes: 26 additions & 14 deletions core/src/main/java/lee/study/down/dispatch/HttpDownCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,42 @@
import lee.study.down.model.ChunkInfo;
import lee.study.down.model.HttpDownInfo;

public interface HttpDownCallback {
public class HttpDownCallback {

void onStart(HttpDownInfo httpDownInfo) throws Exception;
public void onStart(HttpDownInfo httpDownInfo) throws Exception {
}

void onChunkConnecting(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception;
public void onChunkConnecting(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
}

void onChunkConnected(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception;
public void onChunkConnected(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
}

void onProgress(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception;
public void onProgress(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
}

void onPause(HttpDownInfo httpDownInfo) throws Exception;
public void onPause(HttpDownInfo httpDownInfo) throws Exception {
}

void onContinue(HttpDownInfo httpDownInfo) throws Exception;
public void onContinue(HttpDownInfo httpDownInfo) throws Exception {
}

void onError(HttpDownInfo httpDownInfo, Throwable cause) throws Exception;
public void onError(HttpDownInfo httpDownInfo, Throwable cause) throws Exception {
}

void onChunkError(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo, Throwable cause)
throws Exception;
public void onChunkError(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo, Throwable cause)
throws Exception {
}

void onChunkDone(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception;
public void onChunkDone(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
}

void onMerge(HttpDownInfo httpDownInfo) throws Exception;
public void onMerge(HttpDownInfo httpDownInfo) throws Exception {
}

void onDone(HttpDownInfo httpDownInfo) throws Exception;
public void onDone(HttpDownInfo httpDownInfo) throws Exception {
}

void onDelete(HttpDownInfo httpDownInfo) throws Exception;
public void onDelete(HttpDownInfo httpDownInfo) throws Exception {
}
}
2 changes: 1 addition & 1 deletion start
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
cd `dirname $0`
ehco "正在启动proxyee-down,运行需要管理员权限,请输入用户密码(若无输入提示请忽略)"
echo "正在启动proxyee-down,运行需要管理员权限,请输入用户密码按回车键确认(若无输入提示请忽略)"
sudo ./jre1.8.0_162/Contents/Home/bin/java -jar ./proxyee-down.jar
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import lee.study.down.mvc.ws.WsDataType;
import lee.study.down.util.FileUtil;

public class HttpDownHandleCallback implements HttpDownCallback {
public class HttpDownHandleCallback extends HttpDownCallback {

private void sendTask(String id) {
ContentManager.WS.sendMsg(ContentManager.DOWN.buildWsForm(id));
Expand All @@ -23,18 +23,6 @@ public void onStart(HttpDownInfo httpDownInfo) throws Exception {
sendTask(httpDownInfo.getTaskInfo().getId());
}

@Override
public void onChunkConnecting(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
}

@Override
public void onChunkConnected(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
}

@Override
public void onProgress(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {

}

@Override
public void onPause(HttpDownInfo httpDownInfo) throws Exception {
Expand All @@ -52,10 +40,6 @@ public void onError(HttpDownInfo httpDownInfo, Throwable cause) {
sendTask(httpDownInfo.getTaskInfo().getId());
}

@Override
public void onChunkError(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo, Throwable cause) {
}

@Override
public void onChunkDone(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) {
ContentManager.DOWN.saveTask(httpDownInfo.getTaskInfo().getId());
Expand Down
5 changes: 5 additions & 0 deletions ui/src/main/java/lee/study/down/model/UpdateInfo.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package lee.study.down.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateInfo {

private String url;
private float version;
private String versionStr;
private String desc;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import lee.study.down.boot.AbstractHttpDownBootstrap;
import lee.study.down.boot.TimeoutCheckTask;
import lee.study.down.constant.HttpDownConstant;
import lee.study.down.constant.HttpDownStatus;
import lee.study.down.content.ContentManager;
import lee.study.down.content.DownContent;
import lee.study.down.dispatch.HttpDownCallback;
import lee.study.down.exception.BootstrapException;
import lee.study.down.gui.HttpDownApplication;
import lee.study.down.io.BdyZip;
Expand Down Expand Up @@ -387,9 +387,8 @@ public ResultInfo getVersion() {
return resultInfo;
}

private static AbstractHttpDownBootstrap bootstrap;
public static volatile AbstractHttpDownBootstrap updateBootstrap;
private static volatile UpdateInfo updateInfo;
// private static final UpdateService updateService = new TestUpdateService();
private static final UpdateService updateService = new GithubUpdateService();

@RequestMapping("/checkUpdate")
Expand All @@ -411,28 +410,43 @@ public ResultInfo doUpdate() throws Exception {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("没有可用版本进行更新");
return resultInfo;
}
if (bootstrap != null) {
bootstrap.close();
bootstrap = null;
if (updateBootstrap != null) {
updateBootstrap.close();
updateBootstrap = null;
}
try {
bootstrap = updateService.update(updateInfo);
updateBootstrap = updateService.update(updateInfo, new HttpDownCallback() {
@Override
public void onDone(HttpDownInfo httpDownInfo) throws Exception {
String zipPath = httpDownInfo.getTaskInfo().buildTaskFilePath();
String unzipDir = "proxyee-down-" + updateInfo.getVersionStr();
String unzipPath = unzipDir + "/main/proxyee-down-core.jar";
//下载完解压
FileUtil.unzip(zipPath, null, unzipPath);
//复制出来
Files.copy(
Paths.get(httpDownInfo.getTaskInfo().getFilePath() + File.separator + unzipPath),
Paths.get(httpDownInfo.getTaskInfo().getFilePath() + File.separator
+ "proxyee-down-core.jar.bak"));
//删除临时的文件
FileUtil
.deleteIfExists(zipPath);
FileUtil
.deleteIfExists(httpDownInfo.getTaskInfo().getFilePath() + File.separator + unzipDir);
//通知客户端
ContentManager.WS
.sendMsg(new WsForm(WsDataType.UPDATE_PROGRESS, httpDownInfo.getTaskInfo()));
//清空更新下载信息
updateBootstrap = null;
}
});
} catch (TimeoutException e) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("检测更新超时,请重试");
return resultInfo;
}
return resultInfo;
}

@RequestMapping("/getUpdateProgress")
public ResultInfo getUpdateProgress() throws Exception {
ResultInfo resultInfo = new ResultInfo();
if (bootstrap != null) {
resultInfo.setData(bootstrap.getHttpDownInfo().getTaskInfo());
}
return resultInfo;
}

@RequestMapping("/restart")
public ResultInfo restart() throws Exception {
ResultInfo resultInfo = new ResultInfo();
Expand Down
4 changes: 4 additions & 0 deletions ui/src/main/java/lee/study/down/mvc/ws/WsDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ public class WsDataType {
* 创建解压任务
*/
public final static int UNZIP_NEW = 3;
/**
* 升级进度条
*/
public final static int UPDATE_PROGRESS = 4;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import lee.study.down.content.ContentManager;
import lee.study.down.model.ChunkInfo;
import lee.study.down.model.TaskInfo;
import lee.study.down.mvc.controller.HttpDownController;
import lee.study.down.mvc.form.WsForm;
import lee.study.down.mvc.ws.WsDataType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -39,6 +42,12 @@ public void run() {
}
}
ContentManager.WS.sendMsg(ContentManager.DOWN.buildDowningWsForm());
if (HttpDownController.updateBootstrap != null
&& HttpDownController.updateBootstrap.getHttpDownInfo().getTaskInfo().getStatus()
!= HttpDownStatus.DONE) {
ContentManager.WS.sendMsg(new WsForm(WsDataType.UPDATE_PROGRESS,
HttpDownController.updateBootstrap.getHttpDownInfo().getTaskInfo()));
}
TimeUnit.MILLISECONDS.sleep(1000);
} catch (Exception e) {
LOGGER.error("eventTask:", e);
Expand Down
24 changes: 13 additions & 11 deletions ui/src/main/java/lee/study/down/update/GithubUpdateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import lee.study.down.boot.AbstractHttpDownBootstrap;
import lee.study.down.boot.HttpDownBootstrapFactory;
import lee.study.down.constant.HttpDownConstant;
import lee.study.down.dispatch.HttpDownCallback;
import lee.study.down.model.HttpDownInfo;
import lee.study.down.model.HttpRequestInfo;
import lee.study.down.model.TaskInfo;
import lee.study.down.model.UpdateInfo;
import lee.study.down.util.FileUtil;
import lee.study.down.util.HttpDownUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
Expand All @@ -16,9 +18,6 @@

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
public UpdateInfo check(float currVersion) throws Exception {
UpdateInfo updateInfo = new UpdateInfo();
Expand All @@ -32,10 +31,11 @@ public UpdateInfo check(float currVersion) throws Exception {
float maxVersion = Float.parseFloat(versions.get(0).text());
if (maxVersion > currVersion) {
updateInfo.setVersion(maxVersion);
updateInfo.setVersionStr(versions.get(0).text());
Element releaseDiv = versions.get(0).parent().parent();
for (Element element : releaseDiv.select(".d-block.py-2")) {
if (UPDATE_CORE_FILE_NAME.equalsIgnoreCase(element.select("strong").text())) {
updateInfo.setUrl("https://" + HOST + element.select("a").attr("href"));
if (element.select("strong").text().indexOf("-jar.zip") != -1) {
updateInfo.setUrl("https://github.com" + element.select("a").attr("href"));
break;
}
}
Expand All @@ -49,25 +49,27 @@ public UpdateInfo check(float currVersion) throws Exception {
}

@Override
public AbstractHttpDownBootstrap update(UpdateInfo updateInfo)
public AbstractHttpDownBootstrap update(UpdateInfo updateInfo, HttpDownCallback callback)
throws Exception {
HttpRequestInfo requestInfo = HttpDownUtil.buildGetRequest(updateInfo.getUrl());
TaskInfo taskInfo = HttpDownUtil
.getTaskInfo(requestInfo, null, null, HttpDownConstant.clientSslContext,
HttpDownConstant.clientLoopGroup)
.setConnections(32)
.setFileName(UPDATE_CORE_FILE_NAME + ".bak")
.setFilePath(HttpDownConstant.HOME_PATH);
.setConnections(64)
.setFileName("proxyee-down-jar.zip")
.setFilePath(
HttpDownConstant.HOME_PATH.substring(0, HttpDownConstant.HOME_PATH.length() - 1));
HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, requestInfo, null);
AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, 5,
HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, null);
HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, callback);
FileUtil.deleteIfExists(bootstrap.getHttpDownInfo().getTaskInfo().buildTaskFilePath());
bootstrap.startDown();
return bootstrap;
}

public static void main(String[] args) throws Exception {
GithubUpdateService githubUpdateService = new GithubUpdateService();
UpdateInfo updateInfo = githubUpdateService.check(1.0F);
githubUpdateService.update(updateInfo);
githubUpdateService.update(updateInfo, null);
}
}
Loading

0 comments on commit 1f65e09

Please sign in to comment.