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

Commit

Permalink
支持自动启动默认旧版服务器端,包括自动更新。
Browse files Browse the repository at this point in the history
  • Loading branch information
KasumiNova committed Oct 10, 2022
1 parent 7124464 commit da8da67
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 12 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'github.kasuminova'
version '1.2.3-STABLE'
version '1.2.4-STABLE'

repositories {
maven {
Expand Down Expand Up @@ -41,8 +41,8 @@ dependencies {
implementation 'com.alibaba.fastjson2:fastjson2:2.0.14'
implementation 'io.netty:netty-all:4.1.82.Final'
implementation 'com.formdev:flatlaf:2.5'
implementation 'com.formdev:flatlaf-extras:2.4'
implementation 'com.formdev:flatlaf-intellij-themes:2.4'
implementation 'com.formdev:flatlaf-extras:2.5'
implementation 'com.formdev:flatlaf-intellij-themes:2.5'
implementation 'commons-io:commons-io:2.11.0'
}

Expand Down
6 changes: 3 additions & 3 deletions exe4j_configuration.exe4j
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<exe4j version="8.0.1" transformSequenceNumber="3">
<directoryPresets config="C:/Users/Kasumi_Nova/IdeaProjects/BalloonServer" />
<application name="BalloonServer-GUI-LIB-1.2.3-STABLE" distributionSourceDir="C:/Users/Kasumi_Nova/IdeaProjects/BalloonServer/build/libs" />
<executable name="BalloonServer-1.2.3-STABLE" wrapperType="embed" iconSet="true" iconFile="C:/Users/Kasumi_Nova/IdeaProjects/BalloonServer/src/main/resources/image/icon_16x16.ico" executableDir="." redirectStderr="false" stderrFile="balloonserver.log" stdoutFile="balloonserver.log" executableMode="gui" singleInstance="true" />
<application name="BalloonServer-GUI-LIB-1.2.4-STABLE" distributionSourceDir="C:/Users/Kasumi_Nova/IdeaProjects/BalloonServer/build/libs" />
<executable name="BalloonServer-1.2.4-STABLE" wrapperType="embed" iconSet="true" iconFile="C:/Users/Kasumi_Nova/IdeaProjects/BalloonServer/src/main/resources/image/icon_16x16.ico" executableDir="." redirectStderr="false" stderrFile="balloonserver.log" stdoutFile="balloonserver.log" executableMode="gui" singleInstance="true" />
<java mainClass="github.kasuminova.balloonserver.BalloonServer" vmParameters="-Xms512m -XX:+UseStringDeduplication -XX:+UseFastAccessorMethods -XX:+UseG1GC" preferredVM="server" minVersion="17" allowBetaVM="true">
<searchSequence>
<directory location="./java17-jre" />
<registry />
</searchSequence>
<classPath>
<archive location="C:/Users/Kasumi_Nova/IdeaProjects/BalloonServer/build/libs/BalloonServer-GUI-1.2.3-STABLE.jar" />
<archive location="C:/Users/Kasumi_Nova/IdeaProjects/BalloonServer/build/libs/BalloonServer-GUI-1.2.4-STABLE.jar" />
</classPath>
</java>
</exe4j>
24 changes: 20 additions & 4 deletions src/main/java/github/kasuminova/balloonserver/BalloonServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class BalloonServer {
//设置全局主题,字体等
SetupSwing.init();
}
public static final ApplicationVersion VERSION = new ApplicationVersion("1.2.3-STABLE");
public static final ApplicationVersion VERSION = new ApplicationVersion("1.2.4-STABLE");
public static final String TITLE = "BalloonServer " + VERSION;
/*
可执行文件名称。
Expand Down Expand Up @@ -102,7 +102,7 @@ private static void init() {
SERVER_TABBED_PANE.putClientProperty("JTabbedPane.tabCloseToolTipText", "关闭这个标签页。且只能关闭自定义服务器实例。");
SERVER_TABBED_PANE.putClientProperty("JTabbedPane.tabCloseCallback", (BiConsumer<JTabbedPane, Integer>) (tabbedPane, tabIndex) -> {
//检查是否为默认服务端
if (tabIndex == 0) {
if (tabIndex <= 1) {
JOptionPane.showMessageDialog(MAIN_FRAME, "你不可以删除默认服务端!", BalloonServer.TITLE, JOptionPane.WARNING_MESSAGE);
return;
}
Expand Down Expand Up @@ -142,7 +142,23 @@ private static void init() {
SERVER_TABBED_PANE.addTab("集成服务端 (4.1.15+)", DEFAULT_SERVER_ICON, abstractIntegratedServer.getPanel());
availableCustomServerInterfaces.add(abstractIntegratedServer.getServerInterface());

abstractIntegratedServer = new LegacyIntegratedServer("littleserver_legacy", false);
if (CONFIG.isAutoStartLegacyServer()) {
abstractIntegratedServer = new LegacyIntegratedServer("littleserver_legacy", true);
} else if (CONFIG.isAutoStartLegacyServerOnce()) {
abstractIntegratedServer = new LegacyIntegratedServer("littleserver_legacy", true);

CONFIG.setAutoStartLegacyServerOnce(false);
SettingsPanel.applyConfiguration();

try {
ConfigurationManager.saveConfigurationToFile(CONFIG, "./", "balloonserver");
BalloonServer.GLOBAL_LOGGER.info("已更新主程序配置文件.");
} catch (IOException e) {
GLOBAL_LOGGER.error("保存主程序配置文件失败!", e);
}
} else {
abstractIntegratedServer = new LegacyIntegratedServer("littleserver_legacy", false);
}
availableCustomServerInterfaces.add(abstractIntegratedServer.getServerInterface());
SERVER_TABBED_PANE.addTab("旧版集成服务端 (4.x.x)", DEFAULT_SERVER_ICON, abstractIntegratedServer.getPanel());
});
Expand Down Expand Up @@ -213,7 +229,7 @@ public static void stopAllServers(boolean inquireUser) {
for (int i = 0; i < availableCustomServerInterfaces.size(); i++) {
IntegratedServerInterface serverInterface = availableCustomServerInterfaces.get(i);
if (stopIntegratedServer(serverInterface, serverInterface.getServerName(), i, inquireUser)) {
if (i != 0) {
if (i > 1) {
SERVER_TABBED_PANE.removeTabAt(i);
availableCustomServerInterfaces.remove(i);
i--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ public BalloonServerConfig setAutoStartServer(boolean autoStartServer) {
this.autoStartServer = autoStartServer;
return this;
}
private boolean autoStartLegacyServer = false;
//自动启动旧版服务器
public boolean isAutoStartLegacyServer() {
return autoStartLegacyServer;
}
public BalloonServerConfig setAutoStartLegacyServer(boolean autoStartLegacyServer) {
this.autoStartLegacyServer = autoStartLegacyServer;
return this;
}
//自动启动旧版服务器(仅一次)
private boolean autoStartLegacyServerOnce = false;
public boolean isAutoStartLegacyServerOnce() {
return autoStartLegacyServerOnce;
}
public BalloonServerConfig setAutoStartLegacyServerOnce(boolean autoStartLegacyServerOnce) {
this.autoStartLegacyServerOnce = autoStartLegacyServerOnce;
return this;
}
//自动启动服务器(仅一次)
private boolean autoStartServerOnce = false;
public boolean isAutoStartServerOnce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static void loadBalloonServerConfigFromFile(String path, BalloonServerCon
BalloonServerConfig config = JSON.parseObject(Files.newInputStream(Paths.get(path)), BalloonServerConfig.class);
oldConfig.setAutoStartServer(config.isAutoStartServer())
.setAutoStartServerOnce(config.isAutoStartServerOnce())
.setAutoStartLegacyServer(config.isAutoStartLegacyServer())
.setAutoStartLegacyServerOnce(config.isAutoStartLegacyServerOnce())
.setDebugMode(config.isDebugMode())
.setCloseOperation(config.getCloseOperation())
.setAutoCheckUpdates(config.isAutoCheckUpdates())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
public class SettingsPanel {
private static final JCheckBox autoStartDefaultServer = new JCheckBox("自动启动主服务端");
private static final JCheckBox autoStartDefaultServerOnce = new JCheckBox("自动启动主服务端(单次)");
private static final JCheckBox autoStartDefaultLegacyServer = new JCheckBox("自动启动旧版主服务端");
private static final JCheckBox autoStartDefaultLegacyServerOnce = new JCheckBox("自动启动旧版主服务端(单次)");
private static final JCheckBox autoCheckUpdates = new JCheckBox("自动检查更新");
private static final JCheckBox autoUpdate = new JCheckBox("自动更新");
private static final Vector<CloseOperations> operations = new Vector<>();
Expand All @@ -46,9 +48,15 @@ public static JPanel getPanel() {
//自动启动主服务端
JLabel autoStartDefaultServerDesc = new JLabel("此项选中后,BalloonServer 在启动时会自动启动主服务端的服务器,无需手动开启服务端.");

//自动启动主服务端
//自动启动主服务端(单次)
JLabel autoStartDefaultServerOnceDesc = new JLabel("此项选中后,BalloonServer 在启动时会自动启动主服务端的服务器,仅生效一次,生效后自动关闭.");

//自动启动旧版主服务端
JLabel autoStartDefaultLegacyServerDesc = new JLabel("此项选中后,BalloonServer 在启动时会自动启动旧版主服务端的服务器,无需手动开启服务端.");

//自动启动旧版主服务端(单次)
JLabel autoStartDefaultLegacyServerOnceDesc = new JLabel("此项选中后,BalloonServer 在启动时会自动启动旧版主服务端的服务器,仅生效一次,生效后自动关闭.");

//自动检查更新
JLabel autoCheckUpdatesDesc = new JLabel("此项选中后,BalloonServer 在会在启动时检查最新更新.");

Expand Down Expand Up @@ -81,6 +89,10 @@ public static JPanel getPanel() {
settingsPanel.add(autoStartDefaultServerDesc);
settingsPanel.add(autoStartDefaultServerOnce);
settingsPanel.add(autoStartDefaultServerOnceDesc);
settingsPanel.add(autoStartDefaultLegacyServer);
settingsPanel.add(autoStartDefaultLegacyServerDesc);
settingsPanel.add(autoStartDefaultLegacyServerOnce);
settingsPanel.add(autoStartDefaultLegacyServerOnceDesc);
settingsPanel.add(autoCheckUpdates);
settingsPanel.add(autoCheckUpdatesDesc);
settingsPanel.add(autoUpdate);
Expand Down Expand Up @@ -124,6 +136,8 @@ public static void applyConfiguration()
{
autoStartDefaultServer.setSelected(CONFIG.isAutoStartServer());
autoStartDefaultServerOnce.setSelected(CONFIG.isAutoStartServerOnce());
autoStartDefaultLegacyServer.setSelected(CONFIG.isAutoStartLegacyServer());
autoStartDefaultLegacyServerOnce.setSelected(CONFIG.isAutoStartLegacyServerOnce());
autoCheckUpdates.setSelected(CONFIG.isAutoCheckUpdates());
autoUpdate.setSelected(CONFIG.isAutoUpdate());
closeOperationComboBox.setSelectedIndex(CONFIG.getCloseOperation());
Expand All @@ -137,6 +151,8 @@ private static void saveConfiguration()
{
CONFIG.setAutoStartServer(autoStartDefaultServer.isSelected());
CONFIG.setAutoStartServerOnce(autoStartDefaultServerOnce.isSelected());
CONFIG.setAutoStartLegacyServer(autoStartDefaultLegacyServer.isSelected());
CONFIG.setAutoStartLegacyServerOnce(autoStartDefaultLegacyServerOnce.isSelected());
CONFIG.setAutoCheckUpdates(autoCheckUpdates.isSelected());
CONFIG.setAutoUpdate(autoUpdate.isSelected());
CONFIG.setCloseOperation(closeOperationComboBox.getSelectedIndex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ public static void startProgram(String fileName, boolean exitThisProgram) {
//如果主服务端正在运行,则打开自动启动服务器(仅一次)选项并保存,下次启动服务端时自动启动服务器
if (availableCustomServerInterfaces.get(0).isStarted().get()) {
CONFIG.setAutoStartServerOnce(true);
BalloonServer.saveConfig();
}
if (availableCustomServerInterfaces.get(1).isStarted().get()) {
CONFIG.setAutoStartLegacyServerOnce(true);
}
BalloonServer.saveConfig();
//停止所有正在运行的服务器并保存配置
BalloonServer.stopAllServers(false);
System.exit(0);
Expand Down

0 comments on commit da8da67

Please sign in to comment.