Update.java
上传用户:hainatieta
上传日期:2019-07-13
资源大小:1076k
文件大小:2k
- package cn.seejava.lei2;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import javax.swing.JOptionPane;
- public class Update implements Runnable{
- int version = 182;
- public void loadUpdate() throws UnknownHostException, IOException, InterruptedException{
- int i = 10 ;
- if(getInfo()){
- i = showMessage();
- }
- if(i == 0){
- String filePath = SetFrame.f.getCanonicalPath().toLowerCase();
- int j = filePath.indexOf("config.ini");
- String newPath = filePath.substring(0, j)+"update";
- String jarFile = "update.jar";
- Runtime.getRuntime().exec("cmd /c cmd /c start ""/d ""+newPath+"" ""+jarFile+""");
- Thread.sleep(100);
- System.exit(0);
- }
- }
- public boolean getInfo() throws UnknownHostException, IOException{
- boolean flag = false;
- Socket s = new Socket("feiyuhen.gicp.net",80);
- BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line = br.readLine();
- br.close();
- if(Integer.parseInt(line)>version){
- //更新
- flag = true;
- }
- return flag;
-
- }
- public int showMessage(){
- int k = 10 ;
- k = JOptionPane.showConfirmDialog(null, "程序检测到有更新 是不是调用自动更新", "更新", JOptionPane.YES_NO_OPTION);
- return k;
- }
- @Override
- public void run() {
- try {
- loadUpdate();
- } catch (UnknownHostException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
-
- }