mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-06 07:20:47 -05:00
Massive improvement on Online Repo fetching
This commit is contained in:
@@ -9,8 +9,8 @@ import java.util.List;
|
||||
|
||||
public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
|
||||
private String mId, mName, mVersion, mAuthor, mDescription;
|
||||
private int mVersionCode = 0, templateVersion = 0;
|
||||
private String mId = null, mName, mVersion, mAuthor, mDescription;
|
||||
private int mVersionCode = -1, templateVersion = -1;
|
||||
|
||||
protected BaseModule() {}
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
|
||||
protected void parseProps(List<String> props) { parseProps(props.toArray(new String[0])); }
|
||||
|
||||
protected void parseProps(String[] props) {
|
||||
protected void parseProps(String[] props) throws NumberFormatException {
|
||||
for (String line : props) {
|
||||
String[] prop = line.split("=", 2);
|
||||
if (prop.length != 2)
|
||||
@@ -59,9 +59,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
mVersion = prop[1];
|
||||
break;
|
||||
case "versionCode":
|
||||
try {
|
||||
mVersionCode = Integer.parseInt(prop[1]);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
mVersionCode = Integer.parseInt(prop[1]);
|
||||
break;
|
||||
case "author":
|
||||
mAuthor = prop[1];
|
||||
@@ -70,9 +68,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
mDescription = prop[1];
|
||||
break;
|
||||
case "template":
|
||||
try {
|
||||
templateVersion = Integer.parseInt(prop[1]);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
templateVersion = Integer.parseInt(prop[1]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -10,7 +10,9 @@ public class Module extends BaseModule {
|
||||
|
||||
public Module(Shell shell, String path) {
|
||||
|
||||
parseProps(Utils.readFile(shell, path + "/module.prop"));
|
||||
try {
|
||||
parseProps(Utils.readFile(shell, path + "/module.prop"));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
|
||||
mRemoveFile = path + "/remove";
|
||||
mDisableFile = path + "/disable";
|
||||
|
||||
@@ -9,13 +9,15 @@ import java.util.Date;
|
||||
|
||||
public class Repo extends BaseModule {
|
||||
|
||||
public static final int MIN_TEMPLATE_VER = 4;
|
||||
|
||||
private static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
|
||||
private static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip";
|
||||
|
||||
private String repoName;
|
||||
private Date mLastUpdate;
|
||||
|
||||
public Repo(String name, Date lastUpdate) {
|
||||
public Repo(String name, Date lastUpdate) throws IllegalRepoException {
|
||||
mLastUpdate = lastUpdate;
|
||||
repoName = name;
|
||||
update();
|
||||
@@ -27,13 +29,27 @@ public class Repo extends BaseModule {
|
||||
mLastUpdate = new Date(c.getLong(c.getColumnIndex("last_update")));
|
||||
}
|
||||
|
||||
public void update() {
|
||||
public void update() throws IllegalRepoException {
|
||||
String props = WebService.getString(getManifestUrl());
|
||||
String lines[] = props.split("\\n");
|
||||
parseProps(lines);
|
||||
try {
|
||||
parseProps(lines);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalRepoException("Repo [" + repoName + "] parse error: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (getId() == null) {
|
||||
throw new IllegalRepoException("Repo [" + repoName + "] does not contain id");
|
||||
}
|
||||
if (getVersionCode() < 0) {
|
||||
throw new IllegalRepoException("Repo [" + repoName + "] does not contain versionCode");
|
||||
}
|
||||
if (getTemplateVersion() < MIN_TEMPLATE_VER) {
|
||||
throw new IllegalRepoException("Repo [" + repoName + "] is outdated");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean update(Date lastUpdate) {
|
||||
public boolean update(Date lastUpdate) throws IllegalRepoException {
|
||||
if (lastUpdate.after(mLastUpdate)) {
|
||||
mLastUpdate = lastUpdate;
|
||||
update();
|
||||
@@ -49,6 +65,10 @@ public class Repo extends BaseModule {
|
||||
return values;
|
||||
}
|
||||
|
||||
public String getRepoName() {
|
||||
return repoName;
|
||||
}
|
||||
|
||||
public String getZipUrl() {
|
||||
return String.format(ZIP_URL, repoName);
|
||||
}
|
||||
@@ -64,4 +84,10 @@ public class Repo extends BaseModule {
|
||||
public Date getLastUpdate() {
|
||||
return mLastUpdate;
|
||||
}
|
||||
|
||||
public class IllegalRepoException extends Exception {
|
||||
IllegalRepoException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user