replace FiremindJsonFile and NewVersionJsonFile with DownloadableJsonFile.
parent
915f05a77b
commit
a8a0cfe2c5
|
@ -9,15 +9,13 @@ import java.nio.file.Files;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
import magic.data.DownloadableFile;
|
||||
|
||||
public class NewVersionJsonFile extends DownloadableFile {
|
||||
|
||||
private static final String JSON_URL = "https://api.github.com/repos/magarena/magarena/tags";
|
||||
public class DownloadableJsonFile extends DownloadableFile {
|
||||
|
||||
private final URL url;
|
||||
private final File file;
|
||||
|
||||
public NewVersionJsonFile(final File jsonFile) throws MalformedURLException {
|
||||
url = new URL(JSON_URL);
|
||||
public DownloadableJsonFile(final String url, final File jsonFile) throws MalformedURLException {
|
||||
this.url = new URL(url);
|
||||
file = jsonFile;
|
||||
}
|
||||
|
|
@ -16,7 +16,8 @@ public final class NewVersionJsonParser {
|
|||
|
||||
private static void downloadLatestJsonFile(final File jsonFile) {
|
||||
try {
|
||||
final NewVersionJsonFile downloadFile = new NewVersionJsonFile(jsonFile);
|
||||
final DownloadableJsonFile downloadFile =
|
||||
new DownloadableJsonFile("https://api.github.com/repos/magarena/magarena/tags", jsonFile);
|
||||
downloadFile.download(GeneralConfig.getInstance().getProxy());
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Download of json file failed : " + ex.getMessage());
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package magic.firemind;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import magic.data.DownloadableFile;
|
||||
|
||||
public class FiremindJsonFile extends DownloadableFile {
|
||||
|
||||
private static final String JSON_URL = "https://www.firemind.ch/decks/top.json";
|
||||
|
||||
private final URL url;
|
||||
private final File file;
|
||||
|
||||
public FiremindJsonFile(final File jsonFile) throws MalformedURLException {
|
||||
url = new URL(JSON_URL);
|
||||
file = jsonFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(Proxy proxy) throws IOException {
|
||||
final File tempFile = new File(file.getParent(), "~" + file.getName());
|
||||
DownloadableFile.downloadToFile(proxy, url, tempFile);
|
||||
Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getDownloadUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
import java.util.ArrayList;
|
||||
import magic.data.DeckUtils;
|
||||
import magic.data.GeneralConfig;
|
||||
import magic.data.json.DownloadableJsonFile;
|
||||
import magic.model.MagicDeck;
|
||||
import magic.utility.MagicFileSystem;
|
||||
import magic.utility.MagicFileSystem.DataPath;
|
||||
|
@ -27,7 +28,8 @@ public final class FiremindJsonReader {
|
|||
|
||||
private static void downloadLatestJsonFile(final File jsonFile) {
|
||||
try {
|
||||
final FiremindJsonFile downloadFile = new FiremindJsonFile(jsonFile);
|
||||
final DownloadableJsonFile downloadFile =
|
||||
new DownloadableJsonFile("https://www.firemind.ch/decks/top.json", jsonFile);
|
||||
downloadFile.download(GeneralConfig.getInstance().getProxy());
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Download of json file failed : " + ex.getMessage());
|
||||
|
|
Loading…
Reference in New Issue