Skip to content

Commit

Permalink
升级
Browse files Browse the repository at this point in the history
  • Loading branch information
ClayGminx committed Sep 3, 2022
1 parent 5796d4e commit 6f87edd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/claygminx/common/Dict.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static class General {
public final static String GITHUB_CONNECT_TIMEOUT = "github.connectTimeout";
public final static String GITHUB_CONNECT_REQUEST_TIMEOUT = "github.connectRequestTimeout";
public final static String GITHUB_RESPONSE_TIMEOUT = "github.responseTimeout";
public final static String GITHUB_DOWNLOAD_TITLE = "github.downloadTitle";


// PPT
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/claygminx/common/entity/ReleaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class ReleaseEntity implements Serializable, Comparable<ReleaseEntity> {
private String name;

/**
* ZIP包地址
* fa'xing
*/
private String zipball_url;
private String body;

public Date getPublished_at() {
return published_at;
Expand All @@ -39,20 +39,20 @@ public void setName(String name) {
this.name = name;
}

public String getZipball_url() {
return zipball_url;
public String getBody() {
return body;
}

public void setZipball_url(String zipball_url) {
this.zipball_url = zipball_url;
public void setBody(String body) {
this.body = body;
}

@Override
public String toString() {
return "ReleaseEntity{" +
"published_at=" + published_at +
", name='" + name + '\'' +
", zipball_url='" + zipball_url + '\'' +
", body='" + body + '\'' +
'}';
}

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/claygminx/components/impl/UpgradeServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -67,22 +68,26 @@ public void checkNewRelease() {
} else if (HttpStatus.SC_OK == response.getCode()) {
logger.debug("{} 返回200!", url);
StringBuilder responseBuilder = new StringBuilder();
try (Scanner scanner = new Scanner(response.getEntity().getContent())) {

try (Scanner scanner = new Scanner(response.getEntity().getContent(), StandardCharsets.UTF_8.name())) {
while (scanner.hasNextLine()) {
responseBuilder.append(scanner.nextLine());
}
}
String responseString = responseBuilder.toString();
// 转码
responseString = new String(responseString.getBytes(), System.getProperty("file.encoding"));
logger.debug(responseString);

ReleaseEntity remoteReleaseEntity = new Gson().fromJson(responseString, ReleaseEntity.class);
ReleaseEntity thisReleaseEntity = getThisProjectReleaseEntity();
if (thisReleaseEntity.compareTo(remoteReleaseEntity) < 0) {
// 小于远程发行包版本,所以应提示要升级
String downloadUrl = getDownloadUrlFromGitHubBody(remoteReleaseEntity.getBody());
logger.info("温馨提示");
logger.info("有新的版本" + remoteReleaseEntity.getName());
logger.info("发布于" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(remoteReleaseEntity.getPublished_at()));
logger.info("新版本下载地址:" + remoteReleaseEntity.getZipball_url());
logger.info("新版本下载地址:" + downloadUrl);
} else {
logger.debug("该发行包应该是最新的,不用升级");
}
Expand Down Expand Up @@ -110,4 +115,21 @@ protected ReleaseEntity getThisProjectReleaseEntity() {
throw new SystemException(message, e);
}
}

protected String getDownloadUrlFromGitHubBody(String body) {
if (body == null) {
return "";
}
String downloadTitle = SystemConfig.getString(GITHUB_DOWNLOAD_TITLE);
String[] strArray = body.split("\r\n");
for (int i = 0; i < strArray.length; i++) {
String str = strArray[i];
if (downloadTitle.equals(str)) {
if (i != strArray.length - 1) {
return strArray[i + 1];
}
}
}
return "";
}
}
1 change: 1 addition & 0 deletions src/main/resources/worship-ppt.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ github.repo=worship-ppt
github.connectTimeout=30
github.connectRequestTimeout=30
github.responseTimeout=30
github.downloadTitle=### 下载地址

#此程序的属性,用于版本控制和升级
project.version=${project.version}
Expand Down

0 comments on commit 6f87edd

Please sign in to comment.