From 2ea8b37e2b48e03bb46f04be01914e6121a4b645 Mon Sep 17 00:00:00 2001 From: He Yiding Date: Thu, 7 May 2020 10:12:42 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20locale=20=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xwintop/xJavaFxTool/Main.java | 13 ++-- .../xJavaFxTool/utils/XJavaFxSystemUtil.java | 5 ++ .../xJavaFxTool/fxmlView/newui/main.fxml | 12 ++-- src/main/resources/locale/Menu.properties | 72 ++++++++++--------- .../resources/locale/Menu_en_US.properties | 72 ++++++++++--------- 5 files changed, 95 insertions(+), 79 deletions(-) diff --git a/src/main/java/com/xwintop/xJavaFxTool/Main.java b/src/main/java/com/xwintop/xJavaFxTool/Main.java index d6c8bce0..6f2ba130 100644 --- a/src/main/java/com/xwintop/xJavaFxTool/Main.java +++ b/src/main/java/com/xwintop/xJavaFxTool/Main.java @@ -8,7 +8,6 @@ import com.xwintop.xJavaFxTool.utils.StageUtils; import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil; import com.xwintop.xcore.javafx.FxApp; import com.xwintop.xcore.javafx.dialog.FxAlerts; -import com.xwintop.xcore.javafx.helper.FxmlHelper; import com.xwintop.xcore.util.javafx.JavaFxViewUtil; import java.io.IOException; import java.util.ResourceBundle; @@ -32,8 +31,7 @@ public class Main extends Application { public static final String LOGO_PATH = "/images/icon.jpg"; - public static final ResourceBundle RESOURCE_BUNDLE = - ResourceBundle.getBundle("locale.Menu", Config.defaultLocale); + public static ResourceBundle RESOURCE_BUNDLE; private static Stage stage; @@ -69,8 +67,13 @@ public class Main extends Application { StageUtils.updateStageStyle(primaryStage); } - private void loadNewUI(Stage primaryStage) { - FxmlHelper.loadIntoStage("/com/xwintop/xJavaFxTool/fxmlView/newui/main.fxml", primaryStage).show(); + private void loadNewUI(Stage primaryStage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(); + fxmlLoader.setLocation(Main.class.getResource("/com/xwintop/xJavaFxTool/fxmlView/newui/main.fxml")); + fxmlLoader.setResources(RESOURCE_BUNDLE); + + Parent root = fxmlLoader.load(); + primaryStage.setScene(new Scene(root)); } private void loadClassicUI(Stage primaryStage) throws IOException { diff --git a/src/main/java/com/xwintop/xJavaFxTool/utils/XJavaFxSystemUtil.java b/src/main/java/com/xwintop/xJavaFxTool/utils/XJavaFxSystemUtil.java index 2a4aa86e..698b42e4 100644 --- a/src/main/java/com/xwintop/xJavaFxTool/utils/XJavaFxSystemUtil.java +++ b/src/main/java/com/xwintop/xJavaFxTool/utils/XJavaFxSystemUtil.java @@ -1,5 +1,6 @@ package com.xwintop.xJavaFxTool.utils; +import com.xwintop.xJavaFxTool.Main; import com.xwintop.xJavaFxTool.plugin.PluginManager; import com.xwintop.xJavaFxTool.services.index.PluginManageService; import java.io.File; @@ -7,6 +8,7 @@ import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.Locale; +import java.util.ResourceBundle; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -26,10 +28,13 @@ public class XJavaFxSystemUtil { public static void initSystemLocal() { try { String localeString = Config.get(Config.Keys.Locale, ""); + if (StringUtils.isNotEmpty(localeString)) { String[] locale1 = localeString.split("_"); Config.defaultLocale = new Locale(locale1[0], locale1[1]); } + + Main.RESOURCE_BUNDLE = ResourceBundle.getBundle("locale.Menu", Config.defaultLocale); } catch (Exception e) { log.error("初始化本地语言失败", e); } diff --git a/src/main/resources/com/xwintop/xJavaFxTool/fxmlView/newui/main.fxml b/src/main/resources/com/xwintop/xJavaFxTool/fxmlView/newui/main.fxml index fa018986..dff369f8 100644 --- a/src/main/resources/com/xwintop/xJavaFxTool/fxmlView/newui/main.fxml +++ b/src/main/resources/com/xwintop/xJavaFxTool/fxmlView/newui/main.fxml @@ -21,28 +21,28 @@ - + - - + diff --git a/src/main/resources/locale/Menu.properties b/src/main/resources/locale/Menu.properties index 763f1dd5..ecf333e8 100644 --- a/src/main/resources/locale/Menu.properties +++ b/src/main/resources/locale/Menu.properties @@ -1,40 +1,44 @@ # Dorian.properties\u662F\u9ED8\u8BA4\u7684"Dorian"\u8D44\u6E90\u675F\u6587\u4EF6\u3002 # \u4F5C\u4E3A\u4E2D\u56FD\u4EBA,\u6211\u7528\u81EA\u5DF1\u7684\u5730\u533A\u4F5C\u4E3A\u9ED8\u8BA4 -Title=javaFx\u5DE5\u5177\u96C6\u5408 +Title = javaFx\u5DE5\u5177\u96C6\u5408 # MenuFiled -File=\u83DC\u5355 -closeAllTab=\u5173\u95ED\u6240\u6709\u6807\u7B7E -openAllTab=\u6253\u5F00\u6240\u6709\u6807\u7B7E -addNodepad=\u4E34\u65F6\u8BB0\u4E8B\u672C -addLogConsole=\u65E5\u5FD7\u63A7\u5236\u53F0 -Exit=\u9000\u51FA -Tools=\u5DE5\u5177 -More_Tools=\u66F4\u591A\u5DE5\u5177 -plugin_manage=\u63D2\u4EF6\u7BA1\u7406 -NetWork_Tools=\u7F51\u9875\u5DE5\u5177 -Help=\u5E2E\u52A9 -About=\u5173\u4E8E -SetLanguage=\u8BBE\u7F6E\u8BED\u8A00 -Setting=\u8BBE\u7F6E -openLogFile=\u6253\u5F00\u65E5\u5FD7\u6587\u4EF6 -openLogFolder=\u6253\u5F00\u65E5\u5FD7\u76EE\u5F55 -openConfigFolder=\u6253\u5F00\u914D\u7F6E\u76EE\u5F55 -openPluginFolder=\u6253\u5F00\u63D2\u4EF6\u76EE\u5F55 -userSupport=\u7528\u6237\u8BBA\u575B +File = \u83DC\u5355 +closeAllTab = \u5173\u95ED\u6240\u6709\u6807\u7B7E +openAllTab = \u6253\u5F00\u6240\u6709\u6807\u7B7E +addNodepad = \u4E34\u65F6\u8BB0\u4E8B\u672C +addLogConsole = \u65E5\u5FD7\u63A7\u5236\u53F0 +Exit = \u9000\u51FA +Tools = \u5DE5\u5177 +More_Tools = \u66F4\u591A\u5DE5\u5177 +plugin_manage = \u63D2\u4EF6\u7BA1\u7406 +NetWork_Tools = \u7F51\u9875\u5DE5\u5177 +Help = \u5E2E\u52A9 +About = \u5173\u4E8E +SetLanguage = \u8BBE\u7F6E\u8BED\u8A00 +Setting = \u8BBE\u7F6E +openLogFile = \u6253\u5F00\u65E5\u5FD7\u6587\u4EF6 +openLogFolder = \u6253\u5F00\u65E5\u5FD7\u76EE\u5F55 +openConfigFolder = \u6253\u5F00\u914D\u7F6E\u76EE\u5F55 +openPluginFolder = \u6253\u5F00\u63D2\u4EF6\u76EE\u5F55 +userSupport = \u7528\u6237\u8BBA\u575B -aboutText=\u6B22\u8FCE\u4F7F\u7528JavaFx\u5DE5\u5177\u96C6\u5408\u3002\ngit\u5730\u5740\uFF1Ahttps://gitee.com/xwintop/xJavaFxTool\n\u4F5C\u8005\uFF1A\u8FFD\u98CE\n\u535A\u5BA2\uFF1Awww.xwintop.com\n\u6B22\u8FCE\u524D\u6765\u63D0\u51FA\u610F\u89C1\uFF0C\u4E00\u8D77\u5B8C\u5584\u8BE5\u5DE5\u5177\uFF0C\u8C22\u8C22\uFF01\uFF01\n\u5F53\u524D\u7248\u672C\uFF1A -SetLanguageText=\u8BED\u8A00\u9009\u62E9\u8BBE\u7F6E\u6210\u529F\uFF0C\u91CD\u542F\u540E\u751F\u6548\u3002 +aboutText = \u6B22\u8FCE\u4F7F\u7528JavaFx\u5DE5\u5177\u96C6\u5408\u3002\ngit\u5730\u5740\uFF1Ahttps://gitee.com/xwintop/xJavaFxTool\n\u4F5C\u8005\uFF1A\u8FFD\u98CE\n\u535A\u5BA2\uFF1Awww.xwintop.com\n\u6B22\u8FCE\u524D\u6765\u63D0\u51FA\u610F\u89C1\uFF0C\u4E00\u8D77\u5B8C\u5584\u8BE5\u5DE5\u5177\uFF0C\u8C22\u8C22\uFF01\uFF01\n\u5F53\u524D\u7248\u672C\uFF1A +SetLanguageText = \u8BED\u8A00\u9009\u62E9\u8BBE\u7F6E\u6210\u529F\uFF0C\u91CD\u542F\u540E\u751F\u6548\u3002 +feedback = \u6B22\u8FCE\u5410\u69FD -selectTextField=\u8BF7\u8F93\u5165\u83DC\u5355\u540D -selectButton=\u641C\u7D22 -singleWindowBootCheckBox=\u5728\u65B0\u7A97\u53E3\u4E2D\u6253\u5F00 +selectTextField = \u8BF7\u8F93\u5165\u83DC\u5355\u540D +selectButton = \u641C\u7D22 +singleWindowBootCheckBox = \u5728\u65B0\u7A97\u53E3\u4E2D\u6253\u5F00 -codeTools=Code\u5DE5\u5177 -debugTools=\u8C03\u8BD5\u5DE5\u5177 -epmsTools=epms\u5DE5\u5177 -javaFxTools=javaFx\u5DE5\u5177 -littleTools=\u5C0F\u5DE5\u5177 -webTools=html\u5DE5\u5177 -developTools=\u5F00\u53D1\u5DE5\u5177 -assistTools=\u8F85\u52A9\u5DE5\u5177 -games=\u6E38\u620F +codeTools = Code\u5DE5\u5177 +debugTools = \u8C03\u8BD5\u5DE5\u5177 +epmsTools = epms\u5DE5\u5177 +javaFxTools = javaFx\u5DE5\u5177 +littleTools = \u5C0F\u5DE5\u5177 +webTools = html\u5DE5\u5177 +developTools = \u5F00\u53D1\u5DE5\u5177 +assistTools = \u8F85\u52A9\u5DE5\u5177 +games = \u6E38\u620F +start = \u5F00\u59CB +newPlugin = \u65B0\u5EFA +search = \u641C\u7D22 \ No newline at end of file diff --git a/src/main/resources/locale/Menu_en_US.properties b/src/main/resources/locale/Menu_en_US.properties index 155e7fb9..add76ab0 100644 --- a/src/main/resources/locale/Menu_en_US.properties +++ b/src/main/resources/locale/Menu_en_US.properties @@ -1,40 +1,44 @@ # \u6587\u4EF6Dorian_en_US.properties\uFF0C\u662F\u7F8E\u56FD\u5730\u533A\u7684\u8D44\u6E90\u675F # \u5B83\u8986\u76D6\u4E86\u9ED8\u8BA4\u8D44\u6E90\u675F -Title=JavaFxTool +Title = JavaFxTool -File=File -closeAllTab=closeAllTab -openAllTab=openAllTab -addNodepad=Nodepad -addLogConsole=LogConsole -Exit=Exit -Tools=Tools -More_Tools=More Tools -plugin_manage=Plugin manage -NetWork_Tools=NetWork Tools -Help=Help -About=About -SetLanguage=Set Language -Setting=Setting -openLogFile=open Log File -openLogFolder=open Log Folder -openConfigFolder=open Config Folder -openPluginFolder=open Plugin Folder -userSupport=user Support +File = File +closeAllTab = closeAllTab +openAllTab = openAllTab +addNodepad = Nodepad +addLogConsole = LogConsole +Exit = Exit +Tools = Tools +More_Tools = More Tools +plugin_manage = Plugin manage +NetWork_Tools = NetWork Tools +Help = Help +About = About +SetLanguage = Set Language +Setting = Setting +openLogFile = open Log File +openLogFolder = open Log Folder +openConfigFolder = open Config Folder +openPluginFolder = open Plugin Folder +userSupport = user Support -aboutText=Welcome to the JavaFx tool set.\ngitUrl:https://gitee.com/xwintop/xJavaFxTool\nAuthor:xwintop\nblog:www.xwintop.com\nWelcome to make comments and improve the tool together. Thank you!!\ncurrent version: -SetLanguageText=The language selection settings have been successful and will take effect after reboot. +aboutText = Welcome to the JavaFx tool set.\ngitUrl:https://gitee.com/xwintop/xJavaFxTool\nAuthor:xwintop\nblog:www.xwintop.com\nWelcome to make comments and improve the tool together. Thank you!!\ncurrent version: +SetLanguageText = The language selection settings have been successful and will take effect after reboot. -selectTextField=Please enter a menu name -selectButton=select -singleWindowBootCheckBox=isSingleWindowBoot +selectTextField = Please enter a menu name +selectButton = select +singleWindowBootCheckBox = isSingleWindowBoot +feedback = Feedback +search = Search -codeTools=codeTools -debugTools=debugTools -epmsTools=epmsTools -javaFxTools=javaFxTools -littleTools=littleTools -webTools=webTools -developTools=developTools -assistTools=assistTools -games=games +codeTools = codeTools +debugTools = debugTools +epmsTools = epmsTools +javaFxTools = javaFxTools +littleTools = littleTools +webTools = webTools +developTools = developTools +assistTools = assistTools +games = games +start = Start +newPlugin = New Plugin -- Gitee From e0ffa141c102e9adba1285ce29e910b384e0bef8 Mon Sep 17 00:00:00 2001 From: He Yiding Date: Thu, 7 May 2020 10:12:57 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20locale=20=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IndexController.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java b/src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java index 4ff99fd7..0910b2e8 100644 --- a/src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java +++ b/src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java @@ -1,5 +1,8 @@ package com.xwintop.xJavaFxTool.controller; +import static com.xwintop.xJavaFxTool.Main.RESOURCE_BUNDLE; +import static com.xwintop.xJavaFxTool.utils.Config.Keys.NotepadEnabled; + import com.xwintop.xJavaFxTool.controller.index.PluginManageController; import com.xwintop.xJavaFxTool.model.ToolFxmlLoaderConfiguration; import com.xwintop.xJavaFxTool.plugin.PluginManager; @@ -13,6 +16,17 @@ import com.xwintop.xcore.util.HttpClientUtil; import com.xwintop.xcore.util.javafx.AlertUtil; import com.xwintop.xcore.util.javafx.JavaFxSystemUtil; import com.xwintop.xcore.util.javafx.JavaFxViewUtil; +import java.io.File; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -34,16 +48,6 @@ import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; -import java.io.File; -import java.io.InputStream; -import java.net.URL; -import java.util.*; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import static com.xwintop.xJavaFxTool.Main.RESOURCE_BUNDLE; -import static com.xwintop.xJavaFxTool.utils.Config.Keys.NotepadEnabled; - /** * @ClassName: IndexController * @Description: 主页 @@ -81,7 +85,7 @@ public class IndexController extends IndexView { initService(); initNotepad(); - this.indexService.addWebView("欢迎吐槽", QQ_URL, null); + this.indexService.addWebView(RESOURCE_BUNDLE.getString("feedback"), QQ_URL, null); this.tongjiWebView.getEngine().load(STATISTICS_URL); } -- Gitee From a274d70e46c0539d08f3c7bb3f93de513313b450 Mon Sep 17 00:00:00 2001 From: He Yiding Date: Sat, 9 May 2020 16:26:28 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E6=B2=A1=E6=9C=89=E5=AE=9E=E7=8E=B0=20i18n?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- .../xJavaFxTool/services/index/SystemSettingService.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4de873e9..dec59217 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.xwintop xJavaFxTool - 0.2.2 + 0.2.2-SNAPSHOT jar xJavaFxTool 基于JavaFx搭建的实用小工具集合 @@ -47,7 +47,7 @@ com.xwintop xcore - 0.0.5 + 0.0.5-SNAPSHOT org.projectlombok diff --git a/src/main/java/com/xwintop/xJavaFxTool/services/index/SystemSettingService.java b/src/main/java/com/xwintop/xJavaFxTool/services/index/SystemSettingService.java index 26ab4fb6..5da7176a 100644 --- a/src/main/java/com/xwintop/xJavaFxTool/services/index/SystemSettingService.java +++ b/src/main/java/com/xwintop/xJavaFxTool/services/index/SystemSettingService.java @@ -1,5 +1,6 @@ package com.xwintop.xJavaFxTool.services.index; +import com.xwintop.xJavaFxTool.Main; import com.xwintop.xJavaFxTool.controller.index.SystemSettingController; import com.xwintop.xcore.javafx.FxApp; import com.xwintop.xcore.javafx.dialog.FxDialog; @@ -23,6 +24,7 @@ public class SystemSettingService { public static void openSystemSettings(String title) { FxDialog dialog = new FxDialog() + .setResourceBundle(Main.RESOURCE_BUNDLE) .setTitle(title) .setBodyFxml("/com/xwintop/xJavaFxTool/fxmlView/index/SystemSetting.fxml") .setOwner(FxApp.primaryStage) -- Gitee From 5d6851cbfe985b4715daf0f24dab039570e5976f Mon Sep 17 00:00:00 2001 From: xufeng <1277032935@qq.com> Date: Sun, 17 May 2020 23:02:32 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0QQ=E7=BE=A4=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 80d9de9b..6b873de1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [英文说明/English Documentation](README_EN.md) -**xJavaFxTool交流QQ群:== [387473650](https://jq.qq.com/?_wv=1027&k=59UDEAD) ==** +**xJavaFxTool交流QQ群:== [387473650(此群已满)](https://jq.qq.com/?_wv=1027&k=59UDEAD) [1104780992](https://jq.qq.com/?_wv=1027&k=bhAdkju9) ==** **xJavaFxTool吐个槽:== [进来吐槽](https://support.qq.com/product/127577) ==** #### 项目简介: -- Gitee From 822c9bdd96b3d50cb32be55c7526a8ed6fb3d171 Mon Sep 17 00:00:00 2001 From: Yiding He Date: Sun, 24 May 2020 00:00:34 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=A4=9A=20UA=20?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xJavaFxTool/plugin/PluginManager.java | 88 +++++++++++++------ .../xJavaFxTool/utils/UserAgentUtils.java | 41 --------- 2 files changed, 61 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/com/xwintop/xJavaFxTool/utils/UserAgentUtils.java diff --git a/src/main/java/com/xwintop/xJavaFxTool/plugin/PluginManager.java b/src/main/java/com/xwintop/xJavaFxTool/plugin/PluginManager.java index 4f906fb2..e7cc86ab 100644 --- a/src/main/java/com/xwintop/xJavaFxTool/plugin/PluginManager.java +++ b/src/main/java/com/xwintop/xJavaFxTool/plugin/PluginManager.java @@ -6,8 +6,14 @@ import com.alibaba.fastjson.JSON; import com.xwintop.xJavaFxTool.model.PluginJarInfo; import com.xwintop.xJavaFxTool.utils.Config; import com.xwintop.xJavaFxTool.utils.Config.Keys; -import com.xwintop.xJavaFxTool.utils.UserAgentUtils; import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil; +import lombok.extern.slf4j.Slf4j; +import okhttp3.*; +import okhttp3.Request.Builder; +import okio.*; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -24,20 +30,6 @@ import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; import java.util.function.Consumer; -import lombok.extern.slf4j.Slf4j; -import okhttp3.Interceptor; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request.Builder; -import okhttp3.Response; -import okhttp3.ResponseBody; -import okio.Buffer; -import okio.BufferedSource; -import okio.ForwardingSource; -import okio.Okio; -import okio.Source; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; @Slf4j public class PluginManager { @@ -48,6 +40,15 @@ public class PluginManager { public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + /** + * 当下载插件时,模拟数种 UA + */ + public static final String[] OPTIONAL_UA_LIST = { + "Mozilla/5.0 (Windows NT 6.1; rv:51.0) Gecko/20100101 Firefox/51.0", + "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.0 Safari/537.36", + "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko" + }; + private static PluginManager instance; public static PluginManager getInstance() { @@ -214,21 +215,27 @@ public class PluginManager { this.currentProgressListener = (bytesRead, contentLength, done) -> onProgressUpdate.accept(contentLength, bytesRead); - // 插件下载 - int retryTimes = UserAgentUtils.getUserAgentSize()-1; - Response response = null; - while (retryTimes > 0 && (response== null || response.code() != HttpStatus.HTTP_OK)){ - response = pluginDownloader.newCall(new Builder().header("User-Agent", UserAgentUtils.getUserAgent(retryTimes)).url(pluginJarInfo.getDownloadUrl()).build()).execute(); - retryTimes--; + // 使用多个 UA 尝试下载 + Throwable downloadFailure = null; + for (String ua : OPTIONAL_UA_LIST) { + try { + tryDownload(pluginJarInfo.getDownloadUrl(), ua, file); + downloadFailure = null; + break; + } catch (Exception e) { + downloadFailure = e; + } } - // 下载仍未成功,需要抛出异常,提示下载失败 - if(response== null || response.code() != HttpStatus.HTTP_OK){ - throw new IOException("插件下载失败 " + pluginJarInfo.getJarName()); + + if (downloadFailure != null) { + if (downloadFailure instanceof IOException) { + throw (IOException) downloadFailure; + } else { + throw new IOException("插件下载失败 " + pluginJarInfo.getJarName(), downloadFailure); + } } - InputStream inputStream = response.body().byteStream(); - FileOutputStream outputStream = new FileOutputStream(file); - IOUtils.copy(inputStream, outputStream); + // 下载完毕 plugin.setIsDownload(true); plugin.setIsEnable(true); plugin.setLocalVersionNumber(plugin.getVersionNumber()); @@ -240,8 +247,33 @@ public class PluginManager { return file; } + /** + * 尝试指定的 UA 进行下载,如果下载失败则抛出异常 + * + * @param url 下载地址 + * @param ua UA 字符串 + * @param file 下载到的目标文件 + * + * @throws IOException 如果下载失败 + */ + private void tryDownload(String url, String ua, File file) throws IOException { + Request request = new Builder().header("User-Agent", ua).url(url).build(); + + try (Response response = pluginDownloader.newCall(request).execute()) { + if (response.code() != HttpStatus.HTTP_OK) { + throw new IOException("插件下载失败 : HTTP " + response.code()); + } + + InputStream inputStream = Objects.requireNonNull(response.body()).byteStream(); + try (FileOutputStream outputStream = new FileOutputStream(file)) { + IOUtils.copy(inputStream, outputStream); + } + } + } + ////////////////////////////////////////////////////////////// 保存配置 + // 保存配置,如果失败则抛出异常 public void saveToFile() throws IOException { String json = JSON.toJSONString(this.pluginList, true); Path path = Paths.get(this.localPluginsPath); @@ -251,6 +283,7 @@ public class PluginManager { Files.write(path, json.getBytes(DEFAULT_CHARSET)); } + // 保存配置,如果失败不抛出异常 public void saveToFileQuietly() { try { saveToFile(); @@ -313,6 +346,7 @@ public class PluginManager { private Source source(Source source) { return new ForwardingSource(source) { + long totalBytesRead = 0L; @Override diff --git a/src/main/java/com/xwintop/xJavaFxTool/utils/UserAgentUtils.java b/src/main/java/com/xwintop/xJavaFxTool/utils/UserAgentUtils.java deleted file mode 100644 index 7bb34ee9..00000000 --- a/src/main/java/com/xwintop/xJavaFxTool/utils/UserAgentUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.xwintop.xJavaFxTool.utils; - -import java.util.ArrayList; -import java.util.List; - -/** - * @Description 用于i伪造请求的UserAgent - * @Author LiFaXin - * @Date 2020/5/14 17:24 - * @Version - **/ -public class UserAgentUtils { - - private static List userAgents = new ArrayList<>(3); - static{ - // Firefox - userAgents.add("Mozilla/5.0 (Windows NT 6.1; rv:51.0) Gecko/20100101 Firefox/51.0"); - // Chrome - userAgents.add("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.0 Safari/537.36"); - // IE - userAgents.add("Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"); - } - - /** - * 获取UserAgent - * @param index - * @return - */ - public static String getUserAgent(int index){ - index = index > userAgents.size()-1 ? userAgents.size()-1 : index; - return userAgents.get(index); - } - - /** - * 获取UserAgent配置数量 - * @return - */ - public static int getUserAgentSize(){ - return userAgents.size(); - } -} -- Gitee From 4537657aca6d78c475448e16bdfeb6161437a25a Mon Sep 17 00:00:00 2001 From: xufeng <1277032935@qq.com> Date: Fri, 3 Jul 2020 19:40:17 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E4=B8=BA0.2.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- src/main/java/com/xwintop/xJavaFxTool/utils/Config.java | 2 +- src/main/resources/banner.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index dec59217..615fc2c4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.xwintop xJavaFxTool - 0.2.2-SNAPSHOT + 0.2.3 jar xJavaFxTool 基于JavaFx搭建的实用小工具集合 @@ -47,7 +47,7 @@ com.xwintop xcore - 0.0.5-SNAPSHOT + 0.0.6 org.projectlombok diff --git a/src/main/java/com/xwintop/xJavaFxTool/utils/Config.java b/src/main/java/com/xwintop/xJavaFxTool/utils/Config.java index ecd61c2f..c2a0684e 100644 --- a/src/main/java/com/xwintop/xJavaFxTool/utils/Config.java +++ b/src/main/java/com/xwintop/xJavaFxTool/utils/Config.java @@ -14,7 +14,7 @@ public class Config { public static Locale defaultLocale = Locale.getDefault();// 设置系统语言 - public static final String xJavaFxToolVersions = "V0.2.2";// xJavaFxTool版本信息 + public static final String xJavaFxToolVersions = "V0.2.3";// xJavaFxTool版本信息 /////////////////////////////////////////////////////////////// diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt index 337a90fb..d07ecdd8 100644 --- a/src/main/resources/banner.txt +++ b/src/main/resources/banner.txt @@ -47,4 +47,4 @@ // ; iEEEL ,EEEEEL, EEEE // ////////////////////////////////////////////////////////////////////// ${AnsiColor.BRIGHT_BLUE} -::: Project (version:0.2.1) ::: http://www.xwintop.com\(^O^)/ Spring-Boot ${spring-boot.version} \ No newline at end of file +::: Project (version:0.2.3) ::: http://www.xwintop.com\(^O^)/ Spring-Boot ${spring-boot.version} \ No newline at end of file -- Gitee From cf6d5b0a97e0df308bc6f7a71a618e4e144a70a9 Mon Sep 17 00:00:00 2001 From: xufeng <1277032935@qq.com> Date: Sat, 4 Jul 2020 14:46:55 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0readme=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ README_EN.md | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6b873de1..9a6294c9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [英文说明/English Documentation](README_EN.md) -**xJavaFxTool交流QQ群:== [387473650(此群已满)](https://jq.qq.com/?_wv=1027&k=59UDEAD) [1104780992](https://jq.qq.com/?_wv=1027&k=bhAdkju9) ==** +**xJavaFxTool交流QQ群:== [387473650(此群已满)](https://jq.qq.com/?_wv=1027&k=59UDEAD) 请加群②[1104780992](https://jq.qq.com/?_wv=1027&k=bhAdkju9) ==** **xJavaFxTool吐个槽:== [进来吐槽](https://support.qq.com/product/127577) ==** #### 项目简介: @@ -19,11 +19,11 @@ xJavaFxTool是使用javaFx开发的实用小工具集,利用业余时间把工 由于SpringBoot的火热,项目已经出SpringBoot-javafx版本,[xJavaFxTool-spring](https://gitee.com/xwintop/xJavaFxTool-spring) 欢迎参考,谢谢。 #### 下载试用地址: -- 可直接运行的jar包(本地需要有jdk1.8环境)[xJavaFxTool-0.2.2.jar](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.2.jar) -- Windows x86安装包(兼容xp、windows7、8、10等系统)[xJavaFxTool-0.2.2-windows-x86.exe](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.2-windows-x86.exe) -- Windows x64安装包(兼容xp、windows7、8、10等系统)[xJavaFxTool-0.2.2-windows-x64.exe](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.2-windows-x64.exe) -- Linux x64 [xJavaFxTool-0.2.2-linux-x64.zip](https://xwintop.coding.net/s/a9ae5e67-ba0d-4421-955b-7cba0662a976) (Linux平台64位运行压缩包,解压即可运行) -- Mac OS X x64 [xJavaFxTool-0.2.2-macosx-x64.pkg](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.2-macosx-x64.pkg) +- 可直接运行的jar包(本地需要有jdk1.8环境)[xJavaFxTool-0.2.3.jar](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.3.jar) +- Windows x86安装包(兼容xp、windows7、8、10等系统)(请在下面网盘中下载) +- Windows x64安装包(兼容xp、windows7、8、10等系统)[xJavaFxTool-0.2.3-windows-x64.exe](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.3-windows-x64.exe) +- Linux x64 (请在下面网盘中下载) +- Mac OS X x64 [xJavaFxTool-0.2.3-macosx-x64.pkg](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.3-macosx-x64.pkg) #### 若上面下链接失效可使用下面下载链接: - 百度云链接:[https://pan.baidu.com/s/193fhGnJL4dDWcqDnFJcHbA](https://pan.baidu.com/s/193fhGnJL4dDWcqDnFJcHbA) 提取码:mokl - 腾讯微云链接:[https://share.weiyun.com/5T6FPLW](https://share.weiyun.com/5T6FPLW) 提取码:java diff --git a/README_EN.md b/README_EN.md index 22894c40..fd041987 100644 --- a/README_EN.md +++ b/README_EN.md @@ -29,11 +29,9 @@ xJavaFxTool is a practical gadget set developed by javaFx. It uses some time to Due to the hot SpringBoot, the project has been released SpringBoot-javafx version, [xJavaFxTool-spring](https://gitee.com/xwintop/xJavaFxTool-spring) welcome reference, thank you. #### Download trial address: -- Jar package that can be run directly (local need to have jdk1.8 environment)[xJavaFxTool-0.2.1.jar](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.1.jar) -- Windows x86 installation package (compatible with xp, windows7, 8, 10, etc.) [xJavaFxTool-0.2.1-windows-x86.exe](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.1-windows-x86.exe) -- Windows x64 installation package (compatible with xp, windows7, 8, 10, etc.)[xJavaFxTool-0.2.1-windows-x64.exe](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.1-windows-x64.exe) -- Linux x64 [xJavaFxTool-0.2.1-linux-x64.zip](https://xwintop.coding.net/s/5dc71c30-065d-4d0d-a238-3663291a18f7) (Linux platform 64-bit running compression package, decompression can run) -- Mac OS X x64 [xJavaFxTool-0.2.1-macosx-x64.pkg](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.1-macosx-x64.pkg) +- Jar package that can be run directly (local need to have jdk1.8 environment)[xJavaFxTool-0.2.3.jar](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.3.jar) +- Windows x64 installation package (compatible with xp, windows7, 8, 10, etc.)[xJavaFxTool-0.2.3-windows-x64.exe](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.3-windows-x64.exe) +- Mac OS X x64 [xJavaFxTool-0.2.3-macosx-x64.pkg](https://xwintop.gitee.io/maven/package/xJavaFxTool/xJavaFxTool-0.2.3-macosx-x64.pkg) #### If the above link fails, use the download link below: - Baidu cloud link: [https://pan.baidu.com/s/193fhGnJL4dDWcqDnFJcHbA](https://pan.baidu.com/s/193fhGnJL4dDWcqDnFJcHbA) extraction code: mokl - Tencent micro cloud link: [https://share.weiyun.com/5T6FPLW](https://share.weiyun.com/5T6FPLW) extraction code: java -- Gitee