Skip to content

Commit

Permalink
Added support for getting news URLs from update manifests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Jun 11, 2013
1 parent 191bcb3 commit a5d2d8a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/sk89q/mclauncher/InstallFromURLTask.java
Expand Up @@ -20,6 +20,7 @@


import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;


import javax.swing.JOptionPane; import javax.swing.JOptionPane;
Expand Down Expand Up @@ -74,6 +75,16 @@ protected void execute() throws ExecutionException {
Configuration configuration = Configuration configuration =
Configuration.createInstance( Configuration.createInstance(
id, manifest.getName(), urlObject); 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); options.getConfigurations().register(configuration);


Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/sk89q/mclauncher/model/UpdateManifest.java
Expand Up @@ -34,6 +34,7 @@ public class UpdateManifest {
private String name; private String name;
private String latestVersion; private String latestVersion;
private String packageUrl; private String packageUrl;
private String newsUrl;


@XmlElement @XmlElement
public String getId() { public String getId() {
Expand Down Expand Up @@ -75,6 +76,22 @@ public URL toPackageURL(URL baseUrl) throws MalformedURLException {
return LauncherUtils.concat(baseUrl, getPackageURL()); 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() { public boolean isValidForInstall() {
return getId() != null && Configuration.isValidId(getId()) && return getId() != null && Configuration.isValidId(getId()) &&
getName() != null && getName().length() > 0 && getName().length() <= 60; getName() != null && getName().length() > 0 && getName().length() <= 60;
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;


import com.sk89q.mclauncher.Launcher;
import com.sk89q.mclauncher.config.Configuration; import com.sk89q.mclauncher.config.Configuration;
import com.sk89q.mclauncher.model.PackageManifest; import com.sk89q.mclauncher.model.PackageManifest;
import com.sk89q.mclauncher.model.UpdateManifest; import com.sk89q.mclauncher.model.UpdateManifest;
Expand Down Expand Up @@ -56,6 +57,14 @@ public boolean needsUpdate() throws InterruptedException, UpdateException {
throw new UpdateException(e.getMessage(), e); 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 || return cache.getLastUpdateId() == null ||
!cache.getLastUpdateId().equals(fetcher.getManifest().getLatestVersion()); !cache.getLastUpdateId().equals(fetcher.getManifest().getLatestVersion());
} }
Expand Down

0 comments on commit a5d2d8a

Please sign in to comment.