Documented the update class

This commit is contained in:
mmk2410 2015-06-09 10:39:09 +02:00
parent cbfc4f3f33
commit 17e2599c19
1 changed files with 39 additions and 6 deletions

View File

@ -8,11 +8,9 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.util.logging.FileHandler;
/*
This is a Java application for converting writtenMorse and normal morse code.
This is a class for updating a application.
Copyright (C) 2014-2015 Marcel Michael Kapfer
This program is free software: you can redistribute it and/or modify
@ -31,10 +29,18 @@ import java.util.logging.FileHandler;
marcelmichaelkapfer@yahoo.co.nz
*/
public class Update {
private static URL update;
/**
*
* Checks, if a connection to the server is possible
*
* Argument: The URL of the file with the version number as a string
*
*/
public static boolean isConnected(String url){
try {
update = new URL(url);
@ -46,6 +52,13 @@ public class Update {
}
}
/**
*
* Updates the application by overwriting the existing .jar file
*
* Arguments: The path where the jar file is located, the name of the jar file
*
*/
public static boolean update(String path, String filename){
try {
ReadableByteChannel updateChannel = Channels.newChannel(update.openStream());
@ -58,15 +71,35 @@ public class Update {
}
}
/**
*
* Get the version number of the latest version.
*
* Argument: The URL of the version file as a string
*
* It is highly recommended to give also the version number of the current version as an argument
*
*/
public static int getLatestVersion(String versionFile){
return getLatestVersion(versionFile, 0);
}
/**
*
* Get the version number of the latest version.
*
* Arguments: The URL of the version file as a string, the current version number
*
* The current version number is used as a backup if getting the actual version number fails.
*
*/
public static int getLatestVersion(String versionFile, int currentVersion){
int latestVersion = currentVersion;
try {
URL versionURL = new URL(versionFile);
BufferedReader versionReader = new BufferedReader(new InputStreamReader(versionURL.openStream()));
latestVersion = Integer.valueOf(versionReader.readLine());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
return latestVersion;