diff --git a/common/pom.xml b/common/pom.xml index 8016ac60..002644e3 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.41 + 2.42 4.0.0 diff --git a/core/pom.xml b/core/pom.xml index 3fb1a50d..2fd69d08 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.41 + 2.42 4.0.0 @@ -18,10 +18,10 @@ proxyee-down-common ${project.version} - + \ No newline at end of file diff --git a/core/src/main/java/lee/study/down/boot/AbstractHttpDownBootstrap.java b/core/src/main/java/lee/study/down/boot/AbstractHttpDownBootstrap.java index 2266052d..46849a63 100644 --- a/core/src/main/java/lee/study/down/boot/AbstractHttpDownBootstrap.java +++ b/core/src/main/java/lee/study/down/boot/AbstractHttpDownBootstrap.java @@ -11,9 +11,9 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.ssl.SslContext; import io.netty.resolver.NoopAddressResolverGroup; -import java.io.Closeable; import java.io.File; import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; @@ -67,7 +67,12 @@ public void startDown() throws Exception { if (new File(taskInfo.buildTaskFilePath()).exists()) { throw new BootstrapException("文件名已存在,请修改文件名"); } - initBoot(); + //创建文件 + try ( + RandomAccessFile randomAccessFile = new RandomAccessFile(taskInfo.buildTaskFilePath(), "rw") + ) { + randomAccessFile.setLength(taskInfo.getTotalSize()); + } //文件下载开始回调 taskInfo.reset(); taskInfo.setStatus(HttpDownStatus.RUNNING); @@ -81,6 +86,7 @@ public void startDown() throws Exception { if (callback != null) { callback.onStart(httpDownInfo); } + afterStart(); } protected void startChunkDown(ChunkInfo chunkInfo, int updateStatus) throws Exception { @@ -200,13 +206,17 @@ public void continueDown() throws Exception { TaskInfo taskInfo = httpDownInfo.getTaskInfo(); synchronized (taskInfo) { - if (continueDownHandle()) { + if (!FileUtil.exists(taskInfo.buildTaskFilePath())) { + close(); + startDown(); + } else { taskInfo.setStatus(HttpDownStatus.RUNNING); taskInfo.getChunkInfoList().forEach((chunk) -> chunk.setErrorCount(0)); long curTime = System.currentTimeMillis(); taskInfo.setPauseTime( taskInfo.getPauseTime() + (curTime - taskInfo.getLastTime())); taskInfo.setLastTime(curTime); + afterStart(); for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) { synchronized (chunkInfo) { if (chunkInfo.getStatus() == HttpDownStatus.PAUSE @@ -224,21 +234,16 @@ public void continueDown() } } - protected abstract boolean continueDownHandle() throws Exception; - - public abstract void merge() throws Exception; - public void close(ChunkInfo chunkInfo) { try { if (!attr.containsKey(chunkInfo.getIndex())) { return; } Channel channel = getChannel(chunkInfo); - Closeable[] fileChannels = getFileWriter(chunkInfo); LOGGER.debug( "下载连接关闭:channelId[" + (channel != null ? channel.id() : "null") + "]\t" + chunkInfo); attr.remove(chunkInfo.getIndex()); - HttpDownUtil.safeClose(channel, fileChannels); + HttpDownUtil.safeClose(channel); } catch (Exception e) { LOGGER.error("closeChunk error", e); } @@ -299,14 +304,9 @@ public Channel getChannel(ChunkInfo chunkInfo) { return (Channel) getAttr(chunkInfo, ATTR_CHANNEL); } - protected abstract void initBoot() throws Exception; - - public abstract Closeable[] initFileWriter(ChunkInfo chunkInfo) throws Exception; + protected void afterStart() throws Exception { + } public abstract int doFileWriter(ChunkInfo chunkInfo, ByteBuffer buffer) throws IOException; - - protected Closeable[] getFileWriter(ChunkInfo chunkInfo) { - return (Closeable[]) getAttr(chunkInfo, ATTR_FILE_CHANNELS); - } } diff --git a/core/src/main/java/lee/study/down/boot/X64HttpDownBootstrap.java b/core/src/main/java/lee/study/down/boot/X64HttpDownBootstrap.java index 682d5dbf..ff8969dc 100644 --- a/core/src/main/java/lee/study/down/boot/X64HttpDownBootstrap.java +++ b/core/src/main/java/lee/study/down/boot/X64HttpDownBootstrap.java @@ -2,16 +2,12 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.handler.ssl.SslContext; -import java.io.Closeable; import java.io.IOException; -import java.io.RandomAccessFile; import java.nio.ByteBuffer; import lee.study.down.dispatch.HttpDownCallback; import lee.study.down.io.Mmap; import lee.study.down.model.ChunkInfo; import lee.study.down.model.HttpDownInfo; -import lee.study.down.model.TaskInfo; -import lee.study.down.util.FileUtil; public class X64HttpDownBootstrap extends AbstractHttpDownBootstrap { @@ -27,38 +23,9 @@ public X64HttpDownBootstrap(HttpDownInfo httpDownInfo, } @Override - public boolean continueDownHandle() throws Exception { - TaskInfo taskInfo = getHttpDownInfo().getTaskInfo(); - if (!FileUtil.exists(taskInfo.buildTaskFilePath())) { - close(); - startDown(); - return false; - } - return true; - } - - @Override - public void merge() throws Exception { - - } - - @Override - public void initBoot() throws IOException { - TaskInfo taskInfo = getHttpDownInfo().getTaskInfo(); - try ( - RandomAccessFile randomAccessFile = new RandomAccessFile(taskInfo.buildTaskFilePath(), "rw") - ) { - randomAccessFile.setLength(taskInfo.getTotalSize()); - } - } - - @Override - public Closeable[] initFileWriter(ChunkInfo chunkInfo) throws Exception { - if (mmap == null) { - mmap = new Mmap(getHttpDownInfo().getTaskInfo().buildTaskFilePath(), - getHttpDownInfo().getTaskInfo().getTotalSize()); - } - return null; + public void afterStart() throws Exception { + mmap = new Mmap(getHttpDownInfo().getTaskInfo().buildTaskFilePath(), + getHttpDownInfo().getTaskInfo().getTotalSize()); } @Override diff --git a/core/src/main/java/lee/study/down/boot/X86HttpDownBootstrap.java b/core/src/main/java/lee/study/down/boot/X86HttpDownBootstrap.java index c598b4cc..c9417ac5 100644 --- a/core/src/main/java/lee/study/down/boot/X86HttpDownBootstrap.java +++ b/core/src/main/java/lee/study/down/boot/X86HttpDownBootstrap.java @@ -2,26 +2,19 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.handler.ssl.SslContext; -import java.io.Closeable; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; -import java.util.LinkedList; -import java.util.List; -import lee.study.down.constant.HttpDownStatus; import lee.study.down.dispatch.HttpDownCallback; import lee.study.down.model.ChunkInfo; import lee.study.down.model.HttpDownInfo; -import lee.study.down.model.TaskInfo; import lee.study.down.util.FileUtil; public class X86HttpDownBootstrap extends AbstractHttpDownBootstrap { - private static final String ATTR_CACHE = "cache"; - public X86HttpDownBootstrap(HttpDownInfo httpDownInfo, int retryCount, SslContext clientSslContext, @@ -31,101 +24,22 @@ public X86HttpDownBootstrap(HttpDownInfo httpDownInfo, super(httpDownInfo, retryCount, clientSslContext, clientLoopGroup, callback, timeoutCheckTask); } - @Override - public void initBoot() throws Exception { - TaskInfo taskInfo = getHttpDownInfo().getTaskInfo(); - if (taskInfo.getChunkInfoList().size() > 1) { - FileUtil.deleteIfExists(taskInfo.buildChunksPath()); - FileUtil.createDirSmart(taskInfo.buildChunksPath()); - FileUtil.createFile(taskInfo.buildTaskFilePath()); - } - } - - @Override - public boolean continueDownHandle() throws Exception { - TaskInfo taskInfo = getHttpDownInfo().getTaskInfo(); - if (taskInfo.getStatus() == HttpDownStatus.MERGE_CANCEL) { - merge(); - } else if (!FileUtil.exists(taskInfo.buildChunksPath())) { - close(); - startDown(); - } else { - return true; - } - return false; - } - - @Override - public void merge() throws Exception { - /*TaskInfo taskInfo = getHttpDownInfo().getTaskInfo(); - String filePath = taskInfo.buildTaskFilePath(); - long position = 0; - taskInfo.setStatus(HttpDownStatus.MERGE); - if (getCallback() != null) { - getCallback().onMerge(getHttpDownInfo()); - } - synchronized (taskInfo) { - try ( - FileChannel targetChannel = new RandomAccessFile(filePath, "rw").getChannel() - ) { - for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) { - try ( - FileChannel chunkChannel = new RandomAccessFile( - taskInfo.buildChunkFilePath(chunkInfo.getIndex()), "rw").getChannel() - ) { - long remaining = chunkChannel.size(); - while (remaining > 0) { - long transferred = targetChannel.transferFrom(chunkChannel, position, remaining); - remaining -= transferred; - position += transferred; - } - } - } - } - } - FileUtil.deleteIfExists(taskInfo.buildChunksPath());*/ - } - - @Override - public Closeable[] initFileWriter(ChunkInfo chunkInfo) throws Exception { - setAttr(chunkInfo, "cache", new LinkedList()); - return null; - } - - @Override public int doFileWriter(ChunkInfo chunkInfo, ByteBuffer buffer) throws IOException { - int ret = -1; - List cache = (List) getAttr(chunkInfo, ATTR_CACHE); - if (cache != null) { - cache.add(buffer); - if (cache.size() == 64) { - ret = cacheFlush(chunkInfo); + int ret = buffer.remaining(); + MappedByteBuffer mappedByteBuffer = null; + try ( + FileChannel fileChannel = new RandomAccessFile( + getHttpDownInfo().getTaskInfo().buildTaskFilePath(), "rw").getChannel() + ) { + mappedByteBuffer = fileChannel + .map(MapMode.READ_WRITE, chunkInfo.getNowStartPosition() + chunkInfo.getDownSize(), ret); + mappedByteBuffer.put(buffer); + } finally { + if (mappedByteBuffer != null) { + FileUtil.unmap(mappedByteBuffer); } } return ret; } - - public int getCacheSize(ChunkInfo chunkInfo) { - List cache = (List) getAttr(chunkInfo, ATTR_CACHE); - if (cache != null && cache.size() > 0) { - return cache.stream().map(bc -> bc.remaining()).reduce((r1, r2) -> r1 + r2).get(); - } - return 0; - } - - public int cacheFlush(ChunkInfo chunkInfo) throws IOException { - int ret = getCacheSize(chunkInfo); - if (ret > 0) { - List cache = (List) getAttr(chunkInfo, ATTR_CACHE); - MappedByteBuffer mappedByteBuffer = new RandomAccessFile( - getHttpDownInfo().getTaskInfo().buildTaskFilePath(), "rw").getChannel() - .map(MapMode.READ_WRITE, chunkInfo.getNowStartPosition() + chunkInfo.getDownSize(), - ret); - cache.forEach(bc -> mappedByteBuffer.put(bc)); - cache.clear(); - FileUtil.unmap(mappedByteBuffer); - } - return ret; - } } diff --git a/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java b/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java index a2596f6a..f41893ca 100644 --- a/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java +++ b/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java @@ -10,10 +10,8 @@ import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.LastHttpContent; import io.netty.util.ReferenceCountUtil; -import java.io.Closeable; import java.io.IOException; import lee.study.down.boot.AbstractHttpDownBootstrap; -import lee.study.down.boot.X86HttpDownBootstrap; import lee.study.down.constant.HttpDownStatus; import lee.study.down.dispatch.HttpDownCallback; import lee.study.down.model.ChunkInfo; @@ -53,7 +51,6 @@ protected void initChannel(Channel ch) throws Exception { .addLast("httpCodec", new HttpClientCodec()); ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { - private Closeable[] fileChannels; private TaskInfo taskInfo = bootstrap.getHttpDownInfo().getTaskInfo(); private HttpDownCallback callback = bootstrap.getCallback(); @@ -71,14 +68,6 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception if (chunkInfo.getStatus() == HttpDownStatus.RUNNING && nowChannel == ctx.channel()) { int readableBytes = bootstrap.doFileWriter(chunkInfo, byteBuf.nioBuffer()); - if (bootstrap instanceof X86HttpDownBootstrap) { - X86HttpDownBootstrap x86Bootstrap = (X86HttpDownBootstrap) bootstrap; - long downSize = chunkInfo.getDownSize() + x86Bootstrap.getCacheSize(chunkInfo); - //下载完成 - if (isDone(downSize, httpContent) || isContinue(downSize)) { - readableBytes = x86Bootstrap.cacheFlush(chunkInfo); - } - } if (readableBytes > 0) { //文件已下载大小 chunkInfo.setDownSize(chunkInfo.getDownSize() + readableBytes); @@ -87,7 +76,6 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception callback.onProgress(bootstrap.getHttpDownInfo(), chunkInfo); } } else { - return; } } else { @@ -112,9 +100,6 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception taskInfo.setTotalSize(taskInfo.getDownSize()); taskInfo.getChunkInfoList().get(0).setTotalSize(taskInfo.getDownSize()); } - if (taskInfo.getChunkInfoList().size() > 1) { - bootstrap.merge(); - } //文件下载完成回调 taskInfo.setStatus(HttpDownStatus.DONE); LOGGER.debug("下载完成:channelId[" + ctx.channel().id() + "]\t" + chunkInfo); @@ -146,7 +131,6 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception + "]" + chunkInfo); chunkInfo .setDownSize(chunkInfo.getNowStartPosition() - chunkInfo.getOriStartPosition()); - fileChannels = bootstrap.initFileWriter(chunkInfo); chunkInfo.setStatus(HttpDownStatus.RUNNING); if (callback != null) { callback.onChunkConnected(bootstrap.getHttpDownInfo(), chunkInfo); @@ -185,7 +169,7 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { private void safeClose(Channel channel) { try { - HttpDownUtil.safeClose(channel, fileChannels); + HttpDownUtil.safeClose(channel); } catch (IOException e) { LOGGER.error("safeClose fail:", e); } diff --git a/core/src/main/java/lee/study/down/util/HttpDownUtil.java b/core/src/main/java/lee/study/down/util/HttpDownUtil.java index 9eb6d6c1..9f1f93f1 100644 --- a/core/src/main/java/lee/study/down/util/HttpDownUtil.java +++ b/core/src/main/java/lee/study/down/util/HttpDownUtil.java @@ -56,6 +56,7 @@ public static TaskInfo getTaskInfo(HttpRequest httpRequest, HttpHeaders resHeade httpResponse = getResponse(httpRequest, proxyConfig, clientSslCtx, loopGroup); //处理重定向 if ((httpResponse.status().code() + "").indexOf("30") == 0) { + //TODO 302重定向乱码 https://link.gimhoy.com/googledrive/aHR0cHM6Ly9kcml2ZS5nb29nbGUuY29tL29wZW4/aWQ9MThlVmNKeEhwaE40RUpGTUowSk10bWNXOVhCcWJhVE1k.jpg String redirectUrl = httpResponse.headers().get(HttpHeaderNames.LOCATION); HttpRequestInfo requestInfo = (HttpRequestInfo) httpRequest; requestInfo.headers().remove("Host"); diff --git a/pom.xml b/pom.xml index 91790c91..cd63b741 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 lee.study proxyee-down - 2.41 + 2.42 pom diff --git a/sniff/pom.xml b/sniff/pom.xml index 4fe5e5c7..f2ee079f 100644 --- a/sniff/pom.xml +++ b/sniff/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.41 + 2.42 4.0.0 diff --git a/sniff/src/main/java/lee/study/down/plug/PluginContent.java b/sniff/src/main/java/lee/study/down/plug/PluginContent.java index 222e7f7b..8acca5f0 100644 --- a/sniff/src/main/java/lee/study/down/plug/PluginContent.java +++ b/sniff/src/main/java/lee/study/down/plug/PluginContent.java @@ -30,26 +30,27 @@ public static void init() { JarURLConnection jarURLConnection = (JarURLConnection) connection; JarFile jarFile = jarURLConnection.getJarFile(); Enumeration entries = jarFile.entries(); - while(entries.hasMoreElements()){ + while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().matches("^.*hookjs/[^/]+$")) { - String key = entry.getName().substring(entry.getName().indexOf("hookjs/")+7); - update(key, PluginUtil.getPluginBean(jarFile.getInputStream(entry))); + String key = entry.getName().substring(entry.getName().indexOf("hookjs/") + 7); + set(key, PluginUtil.checkAndUpdateLocalPlugin(key, jarFile.getInputStream(entry))); } } jarFile.close(); } else { File file = new File(url.getPath()); for (File hook : file.listFiles()) { - update(hook.getName(), PluginUtil.getPluginBean(new FileInputStream(hook))); + set(hook.getName(), + PluginUtil.checkAndUpdateLocalPlugin(hook.getName(), new FileInputStream(hook))); } } } catch (Exception e) { - LOGGER.error("plugin content init error",e); + LOGGER.error("plugin content init error", e); } } - public static void update(String key, PluginBean value) { + public static void set(String key, PluginBean value) { content.put(key, value); } diff --git a/sniff/src/main/java/lee/study/down/plug/PluginUtil.java b/sniff/src/main/java/lee/study/down/plug/PluginUtil.java index 0aa76d59..e3a70fe5 100644 --- a/sniff/src/main/java/lee/study/down/plug/PluginUtil.java +++ b/sniff/src/main/java/lee/study/down/plug/PluginUtil.java @@ -1,16 +1,24 @@ package lee.study.down.plug; import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import lee.study.down.model.PluginBean; +import lee.study.down.util.FileUtil; +import lee.study.down.util.PathUtil; public class PluginUtil { - public static PluginBean getPluginBean(InputStream inputStream, float currentVersion) + private static final String PLUG_PATH = PathUtil.ROOT_PATH + "plugs"; + + public static PluginBean getPluginBean(String key, InputStream inputStream, float currentVersion) throws IOException { PluginBean pluginBean = new PluginBean(); + FileOutputStream outputStream = null; try ( BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")) ) { @@ -23,20 +31,67 @@ public static PluginBean getPluginBean(InputStream inputStream, float currentVer float newVersion = Float.parseFloat(line.substring(2)); if (newVersion > currentVersion) { pluginBean.setVersion(newVersion); + String localFile = PLUG_PATH + File.separator + key; + FileUtil.createFileSmart(localFile); + outputStream = new FileOutputStream(localFile); } else { return null; } num++; } - sb.append(line + "\r\n"); + String temp = line + "\r\n"; + sb.append(temp); + outputStream.write(temp.getBytes("UTF-8")); } pluginBean.setContent(sb.toString()); + } finally { + if (outputStream != null) { + outputStream.close(); + } } return pluginBean; } - public static PluginBean getPluginBean(InputStream inputStream) + private static PluginBean getPluginBean(InputStream inputStream) throws IOException { - return getPluginBean(inputStream, -1F); + return getPluginBean(null, inputStream, -1F); + } + + public static PluginBean checkAndUpdateLocalPlugin(String key, InputStream inputStream) + throws IOException { + String localFile = PLUG_PATH + File.separator + key; + float localVersion = -1F; + if (FileUtil.exists(localFile)) { + try ( + BufferedReader reader = new BufferedReader( + new InputStreamReader(new FileInputStream(PLUG_PATH + File.separator + key), "UTF-8")) + ) { + String str = reader.readLine(); + localVersion = Float.parseFloat(str.substring(2)); + } catch (Exception e) { + + } + } + try ( + BufferedReader reader = new BufferedReader( + new InputStreamReader(inputStream, "UTF-8")) + ) { + String str = reader.readLine(); + float targetVersion = Float.parseFloat(str.substring(2)); + //plug需要更新 + if (targetVersion > localVersion) { + FileUtil.createFileSmart(localFile); + try ( + FileOutputStream outputStream = new FileOutputStream(localFile); + ) { + outputStream.write((str + "\r\n").getBytes("UTF-8")); + String line; + while ((line = reader.readLine()) != null) { + outputStream.write((line + "\r\n").getBytes("UTF-8")); + } + } + } + } + return getPluginBean(new FileInputStream(localFile)); } } diff --git a/sniff/src/main/resources/hookjs/bdyHook.js b/sniff/src/main/resources/hookjs/bdyHook.js index 9f8b385f..f5bff786 100644 --- a/sniff/src/main/resources/hookjs/bdyHook.js +++ b/sniff/src/main/resources/hookjs/bdyHook.js @@ -1,4 +1,4 @@ -//1.1 +//1.2 var initHookInterval = setInterval(function () { if (!window.$) { return; @@ -324,7 +324,7 @@ var initHookInterval = setInterval(function () { }); } else { $('span.' + wordMap['checkbox']).parent().each(function () { - if ($(this).attr('class').split(' ').length > 3) { + if ($(this).hasClass('mixjMpAl')) { var fileName = $(this).find('div.file-name div.text>a').text(); $.each(fileList, function (i, file) { if (file.server_filename == fileName) { diff --git a/ui/pom.xml b/ui/pom.xml index b56446e1..d9b56cdd 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.41 + 2.42 4.0.0 diff --git a/ui/src/main/java/lee/study/down/content/ConfigContent.java b/ui/src/main/java/lee/study/down/content/ConfigContent.java index e27dcb6c..7d66a9f6 100644 --- a/ui/src/main/java/lee/study/down/content/ConfigContent.java +++ b/ui/src/main/java/lee/study/down/content/ConfigContent.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSON; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -49,6 +50,13 @@ public void init() { ) { set(JSON.parseObject(inputStream, ConfigInfo.class)); } catch (Exception e) { + if (!(e instanceof FileNotFoundException)) { + try { + FileUtil.deleteIfExists(HttpDownConstant.CONFIG_PATH); + } catch (IOException e1) { + e1.printStackTrace(); + } + } LOGGER.error("加载配置文件失败:", e); } } diff --git a/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java b/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java index a1ace88d..3e06fb86 100644 --- a/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java +++ b/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java @@ -20,6 +20,8 @@ import java.util.concurrent.TimeUnit; import javafx.application.Application; import javafx.application.Platform; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.geometry.HPos; import javafx.geometry.Rectangle2D; import javafx.geometry.VPos; @@ -202,12 +204,13 @@ public void start(Stage stage) throws Exception { stage.setTitle("proxyee-down-" + version); Rectangle2D bounds = Screen.getPrimary().getVisualBounds(); ConfigInfo cf = ContentManager.CONFIG.get(); - stage.setX(cf.getGuiX() != -1 ? cf.getGuiX() : bounds.getMinX()); - stage.setY(cf.getGuiY() != -1 ? cf.getGuiY() : bounds.getMinY()); - stage.setWidth(cf.getGuiWidth() != -1 ? cf.getGuiWidth() : bounds.getWidth()); - stage.setHeight(cf.getGuiHeight() != -1 ? cf.getGuiHeight() : bounds.getHeight()); + stage.setX(cf.getGuiX() >= 0 ? cf.getGuiX() : bounds.getMinX()); + stage.setY(cf.getGuiY() >= 0 ? cf.getGuiY() : bounds.getMinY()); + stage.setWidth(cf.getGuiWidth() >= 0 ? cf.getGuiWidth() : bounds.getWidth()); + stage.setHeight(cf.getGuiHeight() >= 0 ? cf.getGuiHeight() : bounds.getHeight()); stage.getIcons().add(new Image( Thread.currentThread().getContextClassLoader().getResourceAsStream("favicon.png"))); + //关闭窗口监听 stage.setOnCloseRequest(event -> { event.consume(); close(); diff --git a/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java b/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java index 4e7fefd4..4e6f8116 100644 --- a/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java +++ b/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java @@ -462,6 +462,8 @@ public static ResultInfo commonBuildTask(BuildTaskForm form) throws Exception { resultInfo.setData(taskInfo.getId()); } catch (MalformedURLException e) { resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("链接格式不正确"); + } catch (TimeoutException e) { + resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("连接超时,请重试"); } catch (Exception e) { throw new RuntimeException("buildTask error:" + form.toString(), e); } diff --git a/ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java b/ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java index f620455a..a02b347b 100644 --- a/ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java +++ b/ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java @@ -28,13 +28,13 @@ public void run() { URL url = new URL(HOST + name); URLConnection connection = url.openConnection(); PluginBean pluginBean = PluginUtil - .getPluginBean(connection.getInputStream(), PluginContent.get(name).getVersion()); + .getPluginBean(name, connection.getInputStream(), PluginContent.get(name).getVersion()); if (pluginBean != null) { - PluginContent.update(name, pluginBean); + PluginContent.set(name, pluginBean); } } } catch (IOException e) { - LOGGER.error("plugin update error", e); + LOGGER.error("plugin set error", e); } } } diff --git a/ui/src/main/resources/application.properties b/ui/src/main/resources/application.properties index 4da4d279..3324f953 100644 --- a/ui/src/main/resources/application.properties +++ b/ui/src/main/resources/application.properties @@ -1,4 +1,4 @@ -app.version=2.41 +app.version=2.42 spring.profiles.active=prd view.server.port = 8999 tomcat.server.port = 26339 diff --git a/update/pom.xml b/update/pom.xml index e8ad83de..1546efba 100644 --- a/update/pom.xml +++ b/update/pom.xml @@ -7,7 +7,7 @@ lee.study proxyee-down-update jar - 2.41 + 2.42 UTF-8