diff --git a/pom.xml b/pom.xml
index 879188b..8079237 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
istlab.KisoJikkenNWP
KisoJikkenNWP
jar
- 0.3
+ 0.4
KisoJikkenNWP
http://maven.apache.org
diff --git a/src/main/java/istlab/KisoJikken/Launcher.java b/src/main/java/istlab/KisoJikken/Launcher.java
index bcf36ed..ae5bbec 100644
--- a/src/main/java/istlab/KisoJikken/Launcher.java
+++ b/src/main/java/istlab/KisoJikken/Launcher.java
@@ -1,13 +1,22 @@
package istlab.KisoJikken;
+import java.awt.Desktop;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.channels.Channels;
+import java.nio.channels.FileChannel;
+import java.nio.channels.ReadableByteChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.CodeSource;
@@ -31,16 +40,23 @@
public static Launcher theapp;
public static String version = "0.3";
+ public static String downloadurl = "https://cit.istlab.info/KisoJikkenNWP/target/";
+ public static Path execPath;
// JPanel mainP;
JTree tree;
Hashtable file2editor;
public Launcher(String[] args) {
- super("Kiso NWP Launcher v"+version);
+ super("Kiso NWP Launcher v" + version);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// mainP = new JPanel();
file2editor = new Hashtable();
theapp = this;
+ try {
+ execPath = getApplicationPath(this.getClass());
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
File root;
if (args.length > 0)
@@ -70,14 +86,22 @@
// Menu
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("App");
- JMenuItem mi = new JMenuItem("show Version");
- mi.addActionListener(ae -> JOptionPane.showMessageDialog(this, "Kiso NWP Launcher v"+version));
+ JMenuItem mi = new JMenuItem("show version");
+ mi.addActionListener(ae -> JOptionPane.showMessageDialog(this, "Kiso NWP Launcher v" + version));
menu.add(mi);
- mi = new JMenuItem("download Latest");
+ mi = new JMenuItem("download latest");
mi.addActionListener(ae -> downloadLatest());
menu.add(mi);
+ mi = new JMenuItem("open download site");
+ mi.addActionListener(ae -> openURL(downloadurl));
+ menu.add(mi);
+
+ mi = new JMenuItem("open JAR folder");
+ mi.addActionListener(ae -> openExecPath());
+ menu.add(mi);
+
menuBar.add(menu);
setJMenuBar(menuBar);
@@ -86,22 +110,81 @@
}
public void downloadLatest() {
+ // 最初に、ダウンロードサイトから最新版の情報を得る
+ // 更新があれば、ダウンロードし、ファイルを表示する。
+ StringBuilder sb = new StringBuilder();
+ String latestVersion=null;
try {
- System.out.println(getApplicationPath(this.getClass()));
- } catch (URISyntaxException e) {
- e.printStackTrace();
+ URL url = new URL(downloadurl);
+ InputStream is = url.openConnection().getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ if (latestVersion==null) latestVersion = line.trim();
+ System.out.println(line);
+ sb.append(line+"\n");
+ }
+ reader.close();
+ } catch (Exception ex) {
+ }
+ // System.out.println(sb.toString());
+//同じかどうかチェック
+ System.out.println("["+latestVersion+"]");
+ System.out.println("="+execPath.getFileName()+"=");
+
+ if (latestVersion.equals(execPath.getFileName().toString())){
+ JOptionPane.showMessageDialog(this, "This is latest version : v"+version);
+ } else {
+ int res = JOptionPane.showConfirmDialog(this, "Download "+latestVersion+"??");
+ if (res==JOptionPane.YES_OPTION){
+ try {
+ URL url = new URL(downloadurl+"/"+latestVersion);
+ ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream());
+ FileOutputStream fileOutputStream = new FileOutputStream(latestVersion);
+ FileChannel fileChannel = fileOutputStream.getChannel();
+ fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
+ fileChannel.close();
+ fileOutputStream.close();
+ } catch (Exception ex) {
+ } finally {
+ }
+ openExecPath();
+ }
}
}
+ public void openExecPath() {
+ File execFolder = execPath.getParent().toFile();
+ openFolder(execFolder);
+ }
+
+ public void openFolder(File path) {
+ try {
+ Desktop.getDesktop().open(path);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void openURL(String url) {
+ if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
+ try {
+ Desktop.getDesktop().browse(new URI(url));
+ } catch (IOException | URISyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
public static Path getApplicationPath(Class> cls) throws URISyntaxException {
- ProtectionDomain pd = cls.getProtectionDomain();
- CodeSource cs = pd.getCodeSource();
- URL location = cs.getLocation();
- URI uri = location.toURI();
- Path path = Paths.get(uri);
- return path;
- }
+ ProtectionDomain pd = cls.getProtectionDomain();
+ CodeSource cs = pd.getCodeSource();
+ URL location = cs.getLocation();
+ URI uri = location.toURI();
+ Path path = Paths.get(uri);
+ return path;
+ }
@Override
public void mouseClicked(MouseEvent e) {