package de.craften.craftenlauncher.logic.download;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.util.ArrayList;
import java.util.List;

public class VersionLoader {
    public static List<String> getVersionStringList() {
        String jsonString = DownloadHelper.downloadFileToString("https://s3.amazonaws.com/Minecraft.Download/versions/versions.json");
        JsonObject versionsJson = new Gson().fromJson(jsonString, JsonObject.class);

        List<String> versions = new ArrayList<>();
        for (JsonElement version : versionsJson.getAsJsonArray("versions")) {
            versions.add(version.getAsJsonObject().get("id").getAsString());
        }
        return versions;
    }
}

@@ -149,89 +149,258 @@
 ct;%0A
-%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class VersionLoader %7B
+import org.apache.logging.log4j.LogManager;%0Aimport org.apache.logging.log4j.Logger;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class VersionLoader %7B%0A    private static final Logger LOGGER = LogManager.getLogger(VersionLoader.class);%0A
 %0A   
@@ -669,24 +669,64 @@
 ct.class);%0A%0A
+        if (versionsJson != null) %7B%0A    
         List
@@ -772,16 +772,20 @@
         
+ 
+   
 for (Jso
@@ -858,16 +858,20 @@
         
+    
 versions
@@ -935,18 +935,26 @@
         
+ 
-%7D%0A
+   %7D%0A    
         
@@ -970,16 +970,217 @@
 rsions;%0A
+        %7D else %7B%0A            LOGGER.warn(%22Downloading versions list failed, using local versions only%22);%0A            return new ArrayList%3C%3E(); //TODO cache the versions or throw an exception%0A        %7D%0A
     %7D%0A%7D%0A

Fix crash when the launcher is started without internet access.