Changes behavior to only allow the downloaded file to be optionally executed, not any chosen file
This commit is contained in:
parent
f304a7a546
commit
4cb0be6a8c
@ -11,10 +11,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static final String usageString = "Usage: downloadURL [sourceProgram] [targetFile] [delay]\nThe source " +
|
private static final String usageString = "Usage: downloadURL [runAfterDownload (y/n)] [targetFile] [delay]\nThe " +
|
||||||
"program will be executed upon successful download. The default target will be the file name defined in " +
|
"downloaded file will be run if runAfterDownload is given as y/yes. The default target will be the file " +
|
||||||
"the download URL. The default delay is 5 seconds, and is the time to wait for the calling .jar file to " +
|
"name defined in the download URL. The default delay is 5 seconds, and is the time to wait for the " +
|
||||||
"be writable.";
|
"calling .jar file to be writable.";
|
||||||
private static final String invalidTargetFilename = "Target filename is invalid. Please set a targetFile argument" +
|
private static final String invalidTargetFilename = "Target filename is invalid. Please set a targetFile argument" +
|
||||||
" ending with a three-letter extension";
|
" ending with a three-letter extension";
|
||||||
private static final String invalidDownloadURL = "Invalid download URL. Only URLs pointing to knarcraft.net can " +
|
private static final String invalidDownloadURL = "Invalid download URL. Only URLs pointing to knarcraft.net can " +
|
||||||
@ -22,16 +22,20 @@ public class Main {
|
|||||||
|
|
||||||
private static String downloadURL;
|
private static String downloadURL;
|
||||||
private static String targetFile;
|
private static String targetFile;
|
||||||
private static String sourceProgram;
|
private static boolean runAfterUpdate = false;
|
||||||
private static int delay = 5;
|
private static int delay = 5;
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException, IOException {
|
public static void main(String[] args) throws InterruptedException, IOException {
|
||||||
parseAndValidateArguments(args);
|
parseAndValidateArguments(args);
|
||||||
TimeUnit.SECONDS.sleep(delay);
|
TimeUnit.SECONDS.sleep(delay);
|
||||||
|
|
||||||
|
//Try to download the updated file
|
||||||
boolean success = DownloaderUtil.downloadFile(downloadURL,
|
boolean success = DownloaderUtil.downloadFile(downloadURL,
|
||||||
Paths.get(DownloaderUtil.getApplicationWorkDirectory() + File.separator + targetFile));
|
Paths.get(DownloaderUtil.getApplicationWorkDirectory() + File.separator + targetFile));
|
||||||
if (success && sourceProgram != null && !sourceProgram.equals("")) {
|
|
||||||
DownloaderUtil.runExecutable(sourceProgram);
|
//Run the downloaded file to start the updated software
|
||||||
|
if (success && runAfterUpdate) {
|
||||||
|
DownloaderUtil.runExecutable(targetFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +46,7 @@ public class Main {
|
|||||||
*/
|
*/
|
||||||
private static void parseAndValidateArguments(String[] args) {
|
private static void parseAndValidateArguments(String[] args) {
|
||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
sourceProgram = args[1];
|
runAfterUpdate = args[1].toLowerCase().startsWith("y");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length >= 4) {
|
if (args.length >= 4) {
|
||||||
|
Loading…
Reference in New Issue
Block a user