Fix coadloads

This commit is contained in:
Daniel Mills 2021-06-06 01:48:26 -04:00
parent c19857d463
commit 574860f117
2 changed files with 27 additions and 52 deletions

View File

@ -394,7 +394,7 @@ public class Iris extends VolmitPlugin
{ {
String h = IO.hash(name + "*" + url); String h = IO.hash(name + "*" + url);
File f = Iris.instance.getDataFile("cache", h.substring(0, 2), h.substring(3, 5), h); File f = Iris.instance.getDataFile("cache", h.substring(0, 2), h.substring(3, 5), h);
Iris.verbose("Download " + name + " -> " + url);
try(BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f)) try(BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f))
{ {
byte[] dataBuffer = new byte[1024]; byte[] dataBuffer = new byte[1024];
@ -405,9 +405,9 @@ public class Iris extends VolmitPlugin
} }
} }
catch(IOException ignored) catch(IOException e)
{ {
e.printStackTrace();
} }
return f; return f;

View File

@ -23,7 +23,7 @@ import java.util.regex.Pattern;
@Data @Data
public class ProjectManager public class ProjectManager
{ {
public static final String LISTING = "https://raw.githubusercontent.com/IrisDimensions/_listing/main/listing.json"; public static final String LISTING = "https://raw.githubusercontent.com/IrisDimensions/_listing/main/listing-v2.json";
public static final String WORKSPACE_NAME = "packs"; public static final String WORKSPACE_NAME = "packs";
private KMap<String, String> cacheListing = null; private KMap<String, String> cacheListing = null;
private IrisProject activeProject; private IrisProject activeProject;
@ -192,40 +192,24 @@ public class ProjectManager
public void downloadSearch(MortarSender sender, String key, boolean trim, boolean forceOverwrite) public void downloadSearch(MortarSender sender, String key, boolean trim, boolean forceOverwrite)
{ {
/* String url = "?";
* Regex removes "/branch" from "IrisDimensions/repo/branch"
* Results in "IrisDimensions/repo"
*/
final Pattern pattern = Pattern.compile("^[^/]*(?:/[^/]*)", Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(getListing(false).get(key));
while (matcher.find()) try
{ {
String repo = matcher.group(0); url = getListing(false).get(key);
/* url = url == null ? key : url;
* Regex removes "IrisDimensions/repo" from "IrisDimensions/repo/branch" Iris.info("Assuming URL " + url);
* Results in "/branch" String branch = "master";
*/ String[] nodes = url.split("\\Q/\\E");
String branch = getListing(false).get(key).replaceAll("^[^/]*(?:/[^/]*)", ""); String repo = nodes[0] + "/" + nodes[1];
if(branch == null || branch.equals("")) { branch = nodes.length > 2 ? nodes[2] : branch;
sender.sendMessage("Couldn't find specific branch, assuming master"); download(sender, repo, branch, trim, forceOverwrite);
branch = "/master"; }
}
if(repo == null)
{
sender.sendMessage("Couldn't find the pack '" + key + "' in the iris repo listing.");
return;
}
sender.sendMessage("Found '" + key + "' in the Iris Listing as " + repo + ", branch " + branch); catch(Throwable e)
try {
{ e.printStackTrace();
download(sender, repo, branch, trim, forceOverwrite); sender.sendMessage("Failed to download '" + key + "' from " + url + ".");
}
catch(JsonSyntaxException | IOException e)
{
sender.sendMessage("Failed to download '" + key + "'.");
}
} }
} }
@ -236,7 +220,7 @@ public class ProjectManager
public void download(MortarSender sender, String repo, String branch, boolean trim, boolean forceOverwrite) throws JsonSyntaxException, IOException public void download(MortarSender sender, String repo, String branch, boolean trim, boolean forceOverwrite) throws JsonSyntaxException, IOException
{ {
String url = "https://codeload.github.com/" + repo + "/zip" + branch; String url = "https://codeload.github.com/" + repo + "/zip/refs/heads/" + branch;
sender.sendMessage("Downloading " + url); sender.sendMessage("Downloading " + url);
File zip = Iris.getNonCachedFile("pack-" + trim + "-" + repo, url); File zip = Iris.getNonCachedFile("pack-" + trim + "-" + repo, url);
File temp = Iris.getTemp(); File temp = Iris.getTemp();
@ -245,7 +229,8 @@ public class ProjectManager
sender.sendMessage("Unpacking " + repo); sender.sendMessage("Unpacking " + repo);
try { try {
ZipUtil.unpack(zip, work); ZipUtil.unpack(zip, work);
} catch (Exception e){ } catch (Throwable e){
e.printStackTrace();
sender.sendMessage( sender.sendMessage(
"Issue when unpacking. Please check/do the following:" + "Issue when unpacking. Please check/do the following:" +
"\n1. Do you have a functioning internet connection?" + "\n1. Do you have a functioning internet connection?" +
@ -328,33 +313,23 @@ public class ProjectManager
return cacheListing; return cacheListing;
} }
JSONArray a; JSONObject a;
if(cached) if(cached)
{ {
a = new JSONArray(Objects.requireNonNull(Iris.getCached("cachedlisting", LISTING))); a = new JSONObject(Iris.getCached("cachedlisting", LISTING));
} }
else else
{ {
a = new JSONArray(Iris.getNonCached(true + "listing", LISTING)); a = new JSONObject(Iris.getNonCached(true + "listing", LISTING));
} }
KMap<String, String> l = new KMap<>(); KMap<String, String> l = new KMap<>();
for(int i = 0; i < a.length(); i++) for(String i : a.keySet())
{ {
try l.put(i, a.getString(i));
{
String m = a.getString(i).trim();
String[] v = m.split("\\Q \\E");
l.put(v[0], v[1]);
}
catch(Throwable ignored)
{
}
} }
return l; return l;