Skip to content

Commit

Permalink
修复exe更新时自定义的端口无效
Browse files Browse the repository at this point in the history
  • Loading branch information
wushuo894 committed Oct 30, 2024
1 parent 30843b4 commit 33b9ba8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion UPDATE.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
优化RSS选择
修复exe更新时自定义的端口无效
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ani.rss</groupId>
<artifactId>ani-rss</artifactId>
<version>1.1.167</version>
<version>1.1.168</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/ani/rss/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import ani.rss.task.UpdateTrackersTask;
import ani.rss.util.*;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Main {

public static String[] ARGS = new String[]{};

public static void main(String[] args) {
Main.ARGS = ObjectUtil.defaultIfNull(args, new String[]{});
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
try {
UpdateUtil.manageWindows();
Expand All @@ -17,9 +21,9 @@ public static void main(String[] args) {
String version = MavenUtil.getVersion();
log.info("version {}", version);

MenuUtil.start(args);
MenuUtil.start();
UpdateTrackersTask.start();
ServerUtil.create(args).start();
ServerUtil.create().start();
} catch (Exception e) {
String message = ExceptionUtil.getMessage(e);
log.error(message, e);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ani/rss/util/MenuUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ani.rss.util;

import ani.rss.Main;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
Expand All @@ -17,8 +17,8 @@ public class MenuUtil {

public static TrayIcon trayIcon;

public static void start(String[] args) {
args = ObjectUtil.defaultIfNull(args, new String[]{});
public static void start() {
String[] args = Main.ARGS;
// 仅在添加--gui参数时启动托盘
if (Arrays.asList(args).contains("--gui")) {
try {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ani/rss/util/ServerUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ani.rss.util;

import ani.rss.Main;
import ani.rss.action.BaseAction;
import ani.rss.action.RootAction;
import ani.rss.annotation.Auth;
Expand Down Expand Up @@ -31,8 +32,9 @@ public class ServerUtil {
public static String PORT = "7789";
public static SimpleServer server;

public static SimpleServer create(String... args) {
public static SimpleServer create() {
Map<String, String> env = System.getenv();
String[] args = Main.ARGS;
int i = Arrays.asList(args).indexOf("--port");

if (i > -1) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/ani/rss/util/UpdateUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package ani.rss.util;

import ani.rss.Main;
import ani.rss.entity.About;
import cn.hutool.core.comparator.VersionComparator;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.StrUtil;
import lombok.SneakyThrows;
Expand All @@ -16,6 +19,8 @@

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
Expand Down Expand Up @@ -73,6 +78,8 @@ public static void update(About about) {
String downloadUrl = about.getDownloadUrl();
HttpReq.get(downloadUrl, true)
.then(res -> {
int status = res.getStatus();
Assert.isTrue(res.isOk(), "Error: {}", status);
long contentLength = res.contentLength();
FileUtil.writeFromStream(res.bodyStream(), file, true);
if (contentLength != file.length()) {
Expand All @@ -93,7 +100,12 @@ public static void update(About about) {
try (InputStream stream = ResourceUtil.getStream(filename)) {
FileUtil.writeFromStream(stream, updateExe, true);
ServerUtil.stop();
RuntimeUtil.exec(updateExe.toString(), file.getParent());
List<String> strings = new ArrayList<>();
strings.add(updateExe.toString());
strings.add(file.getParent());
strings.addAll(Arrays.asList(Main.ARGS));
String[] array = ArrayUtil.toArray(strings, String.class);
RuntimeUtil.exec(array);
System.exit(0);
} catch (Exception e) {
log.error(e.getMessage(), e);
Expand Down

0 comments on commit 33b9ba8

Please sign in to comment.