Updates:
-Removed LinkInstPair -Added installer field to FileOrLink -Changed to file system in FileOrLink -Added filter for multiple types in getRelations
This commit is contained in:
parent
30c7ee114a
commit
ff0996372e
|
@ -27,6 +27,8 @@ public class ASWrapper {
|
|||
public Map<String, IInstaller> INSTALLERS;
|
||||
public Map<String, AddonscriptJSON> ADDONS;
|
||||
public Map<Integer, ASWrapper.VersionWrapper> VERSIONS;
|
||||
@Nullable
|
||||
File asdir;
|
||||
|
||||
public ASWrapper(AddonscriptJSON json) {
|
||||
this.json = json;
|
||||
|
@ -57,6 +59,7 @@ public class ASWrapper {
|
|||
|
||||
public ASWrapper(File file) throws FileNotFoundException {
|
||||
this(AddonscriptJSON.read(new FileReader(file)));
|
||||
asdir = file.getParentFile();
|
||||
}
|
||||
|
||||
public ASWrapper(URL url) {
|
||||
|
@ -122,7 +125,7 @@ public class ASWrapper {
|
|||
return version != null;
|
||||
}
|
||||
|
||||
public List<RelationWrapper> getRelations(String[] conditions, @Nullable String type) {
|
||||
public List<RelationWrapper> getRelations(String[] conditions, @Nullable String[] types) {
|
||||
List<RelationWrapper> list = new ArrayList<>();
|
||||
if (exists() && version.relations != null) {
|
||||
for (AddonscriptJSON.Relation r : version.relations) {
|
||||
|
@ -131,7 +134,7 @@ public class ASWrapper {
|
|||
opt = r.options;
|
||||
else
|
||||
opt = defaultOptions();
|
||||
if (opt.containsAll(Arrays.asList(conditions)) && (type== null || r.type.equals(type))) {
|
||||
if (opt.containsAll(Arrays.asList(conditions)) && (types == null || Arrays.asList(types).contains(r.type))) {
|
||||
list.add(new RelationWrapper(r));
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +199,7 @@ public class ASWrapper {
|
|||
}
|
||||
|
||||
public FileOrLink get() {
|
||||
return new FileOrLink(getLink());
|
||||
return new FileOrLink(getLink(), file.installer).setASDir(asdir);
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
|
|
|
@ -10,11 +10,19 @@ import java.net.URL;
|
|||
public class FileOrLink {
|
||||
|
||||
String link;
|
||||
File asdir;
|
||||
public String installer;
|
||||
|
||||
|
||||
public FileOrLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
public FileOrLink(String link, String installer) {
|
||||
this.link = link;
|
||||
this.installer = installer;
|
||||
}
|
||||
|
||||
public boolean isFile() {
|
||||
return Utils.notEmpty(link) && link.startsWith("file://");
|
||||
}
|
||||
|
@ -33,12 +41,23 @@ public class FileOrLink {
|
|||
* @param path The path to the directory, in which the Addonscript.json is placed
|
||||
* @return A File
|
||||
*/
|
||||
@Deprecated
|
||||
public File getFile(@Nonnull String path) {
|
||||
if (isFile())
|
||||
return new File(Utils.slashEnd(path) + link.replace("file://", ""));
|
||||
throw new RuntimeException("This is no file");
|
||||
}
|
||||
|
||||
/**
|
||||
* To call this, the ASDir should be set. If it isn't set, set it with setASDir before calling this.
|
||||
* @return The File, which is represented by this object
|
||||
*/
|
||||
public File getFile() {
|
||||
if (isFile() && isASDirSet())
|
||||
return new File(Utils.slashEnd(asdir.getPath()) + link.replace("file://", ""));
|
||||
throw new RuntimeException("This is no file or the AS Dir was not set");
|
||||
}
|
||||
|
||||
public URL getURL() {
|
||||
if (isURL()) {
|
||||
try {
|
||||
|
@ -50,4 +69,19 @@ public class FileOrLink {
|
|||
throw new RuntimeException("This is no URL");
|
||||
}
|
||||
|
||||
/**
|
||||
* In Addonscript file:// links are relative paths from the Addonscript.json,
|
||||
* so you have to specify the path of the directory in which it is placed.
|
||||
* @param dir The path to the directory, in which the Addonscript.json is placed
|
||||
* @return This FileOrLink object
|
||||
*/
|
||||
public FileOrLink setASDir(File dir) {
|
||||
asdir = dir;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isASDirSet() {
|
||||
return asdir != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
package ley.anvil.addonscript.wrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class LinkInstPair {
|
||||
|
||||
public String link;
|
||||
public String installer;
|
||||
|
||||
public LinkInstPair(String link, String installer) {
|
||||
this.link = link;
|
||||
this.installer = installer;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public String getInstaller() {
|
||||
return installer;
|
||||
}
|
||||
|
||||
public boolean isURL() {
|
||||
return link.startsWith("http://") || link.startsWith("https://");
|
||||
}
|
||||
|
||||
public boolean isFile() {
|
||||
return link.startsWith("file://");
|
||||
}
|
||||
|
||||
public File asFile(String jsonDir) {
|
||||
if (isFile()) {
|
||||
String f = link.replace("file://", jsonDir + (jsonDir.endsWith("/") ? "" : "/"));
|
||||
return new File(f);
|
||||
}
|
||||
throw new RuntimeException("This is not a file");
|
||||
}
|
||||
|
||||
public URL asURL() {
|
||||
if (isURL()) {
|
||||
try {
|
||||
return new URL(link);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("This is not a URL");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue