Skip to content

Commit

Permalink
Merge pull request 864381832#7 from 864381832/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
864381832 authored Jul 8, 2020
2 parents 70e39e6 + cf6d5b0 commit d8c43b8
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 127 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) ==**

#### 项目简介:
Expand All @@ -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
Expand Down Expand Up @@ -100,6 +100,7 @@ xJavaFxTool是使用javaFx开发的实用小工具集,利用业余时间把工
57. Sudoku:数独游戏
58. LiteappCode:小程序码生成工具
59. RdbmsSyncTool:关系型数据库同步工具
60. FileBuildTool:文件生成工具

项目开发中,以后会陆续添加新工具,欢迎大家参与其中,多提提意见,谢谢。

Expand Down
8 changes: 3 additions & 5 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.xwintop</groupId>
<artifactId>xJavaFxTool</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<packaging>jar</packaging>
<name>xJavaFxTool</name>
<description>基于JavaFx搭建的实用小工具集合</description>
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>com.xwintop</groupId>
<artifactId>xcore</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/xwintop/xJavaFxTool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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;
Expand All @@ -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;

Expand Down Expand Up @@ -69,8 +67,13 @@ public void start(Stage primaryStage) throws Exception {
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +16,17 @@
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;
Expand All @@ -34,16 +48,6 @@
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: 主页
Expand Down Expand Up @@ -81,7 +85,7 @@ public void initialize(URL location, ResourceBundle resources) {
initService();
initNotepad();

this.indexService.addWebView("欢迎吐槽", QQ_URL, null);
this.indexService.addWebView(RESOURCE_BUNDLE.getString("feedback"), QQ_URL, null);
this.tongjiWebView.getEngine().load(STATISTICS_URL);
}

Expand Down
85 changes: 63 additions & 22 deletions src/main/java/com/xwintop/xJavaFxTool/plugin/PluginManager.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.xwintop.xJavaFxTool.plugin;

import cn.hutool.http.HttpStatus;
import cn.hutool.http.HttpUtil;
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.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;
Expand All @@ -22,20 +30,6 @@
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 {
Expand All @@ -46,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() {
Expand Down Expand Up @@ -212,16 +215,27 @@ public File downloadPlugin(
this.currentProgressListener =
(bytesRead, contentLength, done) -> onProgressUpdate.accept(contentLength, bytesRead);

try (
Response response = pluginDownloader
.newCall(new Builder().url(pluginJarInfo.getDownloadUrl()).build())
.execute();
InputStream inputStream = response.body().byteStream();
FileOutputStream outputStream = new FileOutputStream(file)
) {
IOUtils.copy(inputStream, outputStream);
// 使用多个 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 (downloadFailure != null) {
if (downloadFailure instanceof IOException) {
throw (IOException) downloadFailure;
} else {
throw new IOException("插件下载失败 " + pluginJarInfo.getJarName(), downloadFailure);
}
}

// 下载完毕
plugin.setIsDownload(true);
plugin.setIsEnable(true);
plugin.setLocalVersionNumber(plugin.getVersionNumber());
Expand All @@ -233,8 +247,33 @@ public File downloadPlugin(
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);
Expand All @@ -244,6 +283,7 @@ public void saveToFile() throws IOException {
Files.write(path, json.getBytes(DEFAULT_CHARSET));
}

// 保存配置,如果失败不抛出异常
public void saveToFileQuietly() {
try {
saveToFile();
Expand Down Expand Up @@ -306,6 +346,7 @@ public BufferedSource source() {

private Source source(Source source) {
return new ForwardingSource(source) {

long totalBytesRead = 0L;

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,6 +24,7 @@ public class SystemSettingService {
public static void openSystemSettings(String title) {

FxDialog<SystemSettingController> dialog = new FxDialog<SystemSettingController>()
.setResourceBundle(Main.RESOURCE_BUNDLE)
.setTitle(title)
.setBodyFxml("/com/xwintop/xJavaFxTool/fxmlView/index/SystemSetting.fxml")
.setOwner(FxApp.primaryStage)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xwintop/xJavaFxTool/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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版本信息

///////////////////////////////////////////////////////////////

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;
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;

Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
::: Project (version:0.2.3) ::: http://www.xwintop.com\(^O^)/ Spring-Boot ${spring-boot.version}
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
</padding>

<TabPane VBox.vgrow="ALWAYS" tabMinWidth="45" fx:id="tabPane" tabClosingPolicy="ALL_TABS">
<Tab closable="false" text="开始">
<Tab closable="false" text="%start">
<ScrollPane fitToWidth="true" style="-fx-border-width: 0 1 1 1;-fx-border-color: #CCCCCC;-fx-background:#2a2a2a">
<VBox>
<padding>
<Insets left="15"/>
</padding>
<HBox alignment="BASELINE_LEFT" style="-fx-padding: 10">
<Label text="搜索:"/>
<Label text="%search"/>
<TextField prefWidth="200" styleClass="search-text" fx:id="txtSearch"/>
<Pane HBox.hgrow="ALWAYS"/>
<Hyperlink onAction="#openProjectUrl" style="-fx-text-fill: #868686"
text="https://gitee.com/xwintop/xJavaFxTool"/>
<Hyperlink onAction="#openConfigDialog" text="设置"/>
<Hyperlink onAction="#openPluginManager" text="插件管理"/>
<Hyperlink onAction="#openPluginCreator" text="新建" fx:id="lnkCreatePlugin"/>
<Hyperlink onAction="#openConfigDialog" text="%Setting"/>
<Hyperlink onAction="#openPluginManager" text="%plugin_manage"/>
<Hyperlink onAction="#openPluginCreator" text="%newPlugin" fx:id="lnkCreatePlugin"/>
</HBox>
<VBox fx:id="pluginCategories" alignment="TOP_CENTER">
</VBox>
</VBox>
</ScrollPane>
</Tab>
<Tab text="欢迎吐槽">
<Tab text="%feedback">
<WebView fx:id="startWebView"/>
</Tab>
</TabPane>
Expand Down
Loading

0 comments on commit d8c43b8

Please sign in to comment.