Permalink
Browse files

Added support for getting news URLs from update manifests.

  • Loading branch information...
sk89q committed Jun 11, 2013
1 parent 191bcb3 commit a5d2d8adf6b5849263fae646cc2c09f6f21bbb3d
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JOptionPane;
@@ -74,6 +75,16 @@ protected void execute() throws ExecutionException {
Configuration configuration =
Configuration.createInstance(
id, manifest.getName(), urlObject);
+
+
+ // Update the configuration's news URL
+ try {
+ configuration.setNewsUrl(manifest.toNewsURL(urlObject));
+ Launcher.getInstance().getOptions().save();
+ } catch (MalformedURLException e) {
+ throw new ExecutionException(
+ "The manfiest at the URL has an invalid news URL.");
+ }
options.getConfigurations().register(configuration);
@@ -34,6 +34,7 @@
private String name;
private String latestVersion;
private String packageUrl;
+ private String newsUrl;
@XmlElement
public String getId() {
@@ -75,6 +76,22 @@ public URL toPackageURL(URL baseUrl) throws MalformedURLException {
return LauncherUtils.concat(baseUrl, getPackageURL());
}
+ @XmlElement(name = "newsURL")
+ public String getNewsUrl() {
+ return newsUrl;
+ }
+
+ public void setNewsUrl(String newsUrl) {
+ this.newsUrl = newsUrl;
+ }
+
+ public URL toNewsURL(URL baseUrl) throws MalformedURLException {
+ if (getNewsUrl() == null) {
+ return null;
+ }
+ return LauncherUtils.concat(baseUrl, getNewsUrl());
+ }
+
public boolean isValidForInstall() {
return getId() != null && Configuration.isValidId(getId()) &&
getName() != null && getName().length() > 0 && getName().length() <= 60;
@@ -25,6 +25,7 @@
import java.net.URL;
import java.net.UnknownHostException;
+import com.sk89q.mclauncher.Launcher;
import com.sk89q.mclauncher.config.Configuration;
import com.sk89q.mclauncher.model.PackageManifest;
import com.sk89q.mclauncher.model.UpdateManifest;
@@ -56,6 +57,14 @@ public boolean needsUpdate() throws InterruptedException, UpdateException {
throw new UpdateException(e.getMessage(), e);
}
+ // Update the configuration's news URL while we are at it
+ try {
+ configuration.setNewsUrl(
+ fetcher.getManifest().toNewsURL(fetcher.getUpdateURL()));
+ Launcher.getInstance().getOptions().save();
+ } catch (MalformedURLException e) {
+ }
+
return cache.getLastUpdateId() == null ||
!cache.getLastUpdateId().equals(fetcher.getManifest().getLatestVersion());
}

0 comments on commit a5d2d8a

Please sign in to comment.