3 import java.io.IOException;
4 import java.net.MalformedURLException;
7 import javax.swing.JOptionPane;
9 import com.fasterxml.jackson.core.JsonProcessingException;
10 import com.fasterxml.jackson.databind.JsonMappingException;
11 import com.fasterxml.jackson.databind.JsonNode;
12 import com.fasterxml.jackson.databind.ObjectMapper;
13 import com.ranfa.main.DelesteRandomSelector;
15 public class CheckVersion {
17 private final static String URI = "https://raw.githubusercontent.com/hizumiaoba/DelesteRandomSelector/master/version.json";
18 private final static String RELEASE_STRING = "https://github.com/hizumiaoba/DelesteRandomSelector/releases";
20 public static void needToBeUpdated() {
25 JsonNode node = new ObjectMapper().readTree(new URL(URI));
26 latestMajor = node.get("major").asInt();
27 latestMinor = node.get("minor").asInt();
28 latestPatch = node.get("patch").asInt();
29 } catch (JsonMappingException e) {
31 } catch (JsonProcessingException e) {
33 } catch (MalformedURLException e) {
35 } catch (IOException e) {
38 String newVersion = String.format("v%d.%d.%d", latestMajor, latestMinor, latestPatch);
39 if(latestMajor > getMajorVersion()) {
40 JOptionPane.showInputDialog(null, String.format("大規模なソフトウェアの更新が公開されています。速やかにアップデートをお願いします。\n最新バージョン:%s", newVersion), RELEASE_STRING);
41 } else if(latestMinor > getMinorVersion()) {
42 JOptionPane.showInputDialog(null, String.format("ソフトウェアの軽微な機能改修が公開されています。こちらから最新バージョンをダウンロードしてください。\n最新バージョン:%s", newVersion), RELEASE_STRING);
43 } else if(latestPatch > getPatchVersion()) {
44 JOptionPane.showInputDialog(null, String.format("ソフトウェアのバグ修正が公開されています。こちらから最新バージョンをダウンロードしてください。\n最新バージョン:%s", newVersion), RELEASE_STRING);
50 * アノテーションで記載されているバージョンを取得します
52 * @return アノテーションで定義されているバージョン
54 public static String getVersion() {
56 + getMajorVersion() + "."
57 + getMinorVersion() + "."
62 public static int getMajorVersion() {
63 Version version = DelesteRandomSelector.class.getAnnotation(Version.class);
64 return version.major();
67 public static int getMinorVersion() {
68 Version version = DelesteRandomSelector.class.getAnnotation(Version.class);
69 return version.minor();
72 public static int getPatchVersion() {
73 Version version = DelesteRandomSelector.class.getAnnotation(Version.class);
74 return version.patch();