我的程序有更新检查,更新链接到这里,当我运行应用程序时,它说我的程序已过期(如果您当前的启动器版本与在线版本不同,则默认消息。但我测试了它打印出我拥有的当前版本和最新版本是什么,它们是相同的。这是我的代码:
package net.ogpc.updates;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Scanner;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import net.ogpc.GUI.Launcher;
public class UpdatesCheck {
JFrame frame = new JFrame("Checking For Updates...");
JLabel lb = new JLabel("Checking For Updates...");
String build = Launcher.build;
public UpdatesCheck() {
frame.setSize(160, 50);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
frame.add(lb, BorderLayout.NORTH);
updateCheck();
frame.setVisible(true);
}
@SuppressWarnings("resource")
public void updateCheck() {
try {
URL url = new URL("http://pastebin.com/raw.php?i=mWNT0sZa");
Scanner s = new Scanner(url.openStream());
String vs = s.nextLine();
if (vs != build) { //there is an update!
System.out.println("update found");
int ans = JOptionPane.showConfirmDialog(null, "You seem to be using an outdated Launcher.. \nCurrent Version: " + vs + " - Newest Version: " + Launcher.build + "\nDo you want to update the launcher?", "UPDATE FOUND!", JOptionPane.YES_NO_OPTION);
if (ans == JOptionPane.YES_OPTION) {
//go to update page
try {
openWebpage(url.toURI()); //open update page from website
} catch (URISyntaxException e) {
e.printStackTrace();
}
System.exit(0);
} else if (ans == JOptionPane.NO_OPTION) {
//end application
JOptionPane.showMessageDialog(null, "You canceled the update!\nYou must have the most up to date verion of the launcher to run.", "You need to update!", JOptionPane.NO_OPTION);
System.exit(0);
}
}else if (vs == build){ //no update found
frame.setVisible(false);
Launcher.frame.setEnabled(true);
Launcher.frame.setVisible(true);
}
}
catch(IOException ex) {
ex.printStackTrace();
}
}
public static void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(new URL("http://hahn2014.weebly.com/ogpc-2014-update.html").toURI());
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new UpdatesCheck();
}
}
任何帮助,将不胜感激!