3 import java.io.IOException;
6 import javax.swing.JOptionPane;
8 import org.slf4j.LoggerFactory;
10 import com.fasterxml.jackson.databind.JsonNode;
11 import com.fasterxml.jackson.databind.ObjectMapper;
12 import com.ranfa.main.DelesteRandomSelector;
14 public class CheckVersion {
16 private final static String URI = "https://raw.githubusercontent.com/hizumiaoba/DelesteRandomSelector/master/version.json";
17 private final static String RELEASE_STRING = "https://github.com/hizumiaoba/DelesteRandomSelector/releases";
19 public static void needToBeUpdated() {
20 if(!getSuffix().equals(Suffix.STABLE))
26 JsonNode node = new ObjectMapper().readTree(new URL(URI));
27 latestMajor = node.get("major").asInt();
28 latestMinor = node.get("minor").asInt();
29 latestPatch = node.get("patch").asInt();
30 } catch (IOException e) {
31 LoggerFactory.getLogger(CheckVersion.class).error("Error while processing version tag.", e);
33 String newVersion = String.format("v%d.%d.%d", latestMajor, latestMinor, latestPatch);
34 if(latestMajor > getMajorVersion()) {
35 JOptionPane.showInputDialog(null, String.format("大規模なソフトウェアの更新が公開されています。速やかにアップデートをお願いします。\n最新バージョン:%s", newVersion), RELEASE_STRING);
36 } else if(latestMinor > getMinorVersion()) {
37 JOptionPane.showInputDialog(null, String.format("ソフトウェアの軽微な機能改修が公開されています。こちらから最新バージョンをダウンロードしてください。\n最新バージョン:%s", newVersion), RELEASE_STRING);
38 } else if(latestPatch > getPatchVersion()) {
39 JOptionPane.showInputDialog(null, String.format("ソフトウェアのバグ修正が公開されています。こちらから最新バージョンをダウンロードしてください。\n最新バージョン:%s", newVersion), RELEASE_STRING);
45 * アノテーションで記載されているバージョンを取得します
47 * @return アノテーションで定義されているバージョン
49 public static String getVersion() {
51 + getMajorVersion() + "."
52 + getMinorVersion() + "."
53 + getPatchVersion() + "-"
54 + getSuffix().toString();
58 public static int getMajorVersion() {
59 Version version = DelesteRandomSelector.class.getAnnotation(Version.class);
60 return version.major();
63 public static int getMinorVersion() {
64 Version version = DelesteRandomSelector.class.getAnnotation(Version.class);
65 return version.minor();
68 public static int getPatchVersion() {
69 Version version = DelesteRandomSelector.class.getAnnotation(Version.class);
70 return version.patch();
73 public static Suffix getSuffix() {
74 Version version = DelesteRandomSelector.class.getAnnotation(Version.class);
75 return version.suffix();