2016-09-02 08:32:34 -05:00
|
|
|
package com.topjohnwu.magisk.module;
|
|
|
|
|
2017-02-12 23:26:30 +08:00
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.database.Cursor;
|
2016-09-02 08:32:34 -05:00
|
|
|
|
2016-09-30 03:18:08 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Logger;
|
2017-01-11 17:37:35 +08:00
|
|
|
import com.topjohnwu.magisk.utils.WebService;
|
2016-09-02 08:32:34 -05:00
|
|
|
|
2016-09-02 13:18:37 -05:00
|
|
|
import java.util.Date;
|
2016-09-02 08:32:34 -05:00
|
|
|
|
2016-09-21 11:29:43 +08:00
|
|
|
public class Repo extends BaseModule {
|
2017-02-12 23:26:30 +08:00
|
|
|
|
|
|
|
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;
|
2016-11-13 03:07:16 +08:00
|
|
|
private Date mLastUpdate;
|
2016-09-21 11:29:43 +08:00
|
|
|
|
2017-02-12 23:26:30 +08:00
|
|
|
public Repo(String name, Date lastUpdate) throws CacheModException {
|
2016-09-21 11:29:43 +08:00
|
|
|
mLastUpdate = lastUpdate;
|
2017-02-12 23:26:30 +08:00
|
|
|
repoName = name;
|
2016-09-21 11:29:43 +08:00
|
|
|
update();
|
2016-09-06 16:54:08 -05:00
|
|
|
}
|
|
|
|
|
2017-02-12 23:26:30 +08:00
|
|
|
public Repo(Cursor c) {
|
2017-02-19 08:05:16 +08:00
|
|
|
super(c);
|
2017-02-12 23:26:30 +08:00
|
|
|
repoName = c.getString(c.getColumnIndex("repo_name"));
|
|
|
|
mLastUpdate = new Date(c.getLong(c.getColumnIndex("last_update")));
|
|
|
|
}
|
|
|
|
|
2016-11-09 00:46:26 +08:00
|
|
|
public void update() throws CacheModException {
|
2017-04-26 00:14:01 +08:00
|
|
|
String props = WebService.request(getManifestUrl(), WebService.GET);
|
2016-09-21 11:29:43 +08:00
|
|
|
String lines[] = props.split("\\n");
|
|
|
|
parseProps(lines);
|
2017-04-26 00:14:01 +08:00
|
|
|
Logger.dev("Repo: Fetching prop: " + getId());
|
2016-09-06 16:54:08 -05:00
|
|
|
}
|
2016-09-02 08:32:34 -05:00
|
|
|
|
2017-07-21 02:46:02 +08:00
|
|
|
public boolean update(Date lastUpdate) throws CacheModException {
|
2016-09-21 11:29:43 +08:00
|
|
|
if (lastUpdate.after(mLastUpdate)) {
|
|
|
|
mLastUpdate = lastUpdate;
|
|
|
|
update();
|
2017-07-21 02:46:02 +08:00
|
|
|
return true;
|
2016-09-02 08:32:34 -05:00
|
|
|
}
|
2017-07-21 02:46:02 +08:00
|
|
|
return false;
|
2016-09-06 16:54:08 -05:00
|
|
|
}
|
2016-09-02 08:32:34 -05:00
|
|
|
|
2017-02-12 23:26:30 +08:00
|
|
|
public ContentValues getContentValues() {
|
|
|
|
ContentValues values = new ContentValues();
|
2017-02-19 08:05:16 +08:00
|
|
|
values.put("id", getId());
|
|
|
|
values.put("name", getName());
|
|
|
|
values.put("version", getVersion());
|
|
|
|
values.put("versionCode", getVersionCode());
|
|
|
|
values.put("author", getAuthor());
|
|
|
|
values.put("description", getDescription());
|
2017-02-12 23:26:30 +08:00
|
|
|
values.put("repo_name", repoName);
|
|
|
|
values.put("last_update", mLastUpdate.getTime());
|
2017-03-30 06:52:18 +08:00
|
|
|
values.put("template", getTemplateVersion());
|
2017-02-12 23:26:30 +08:00
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2016-09-21 11:29:43 +08:00
|
|
|
public String getZipUrl() {
|
2017-02-12 23:26:30 +08:00
|
|
|
return String.format(ZIP_URL, repoName);
|
2016-09-06 16:54:08 -05:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:29:43 +08:00
|
|
|
public String getManifestUrl() {
|
2017-02-12 23:26:30 +08:00
|
|
|
return String.format(FILE_URL, repoName, "module.prop");
|
2016-09-02 08:36:03 -05:00
|
|
|
}
|
|
|
|
|
2017-02-16 05:45:31 +08:00
|
|
|
public String getDetailUrl() {
|
|
|
|
return String.format(FILE_URL, repoName, "README.md");
|
|
|
|
}
|
|
|
|
|
2016-09-21 11:29:43 +08:00
|
|
|
public Date getLastUpdate() {
|
|
|
|
return mLastUpdate;
|
2016-09-02 08:32:34 -05:00
|
|
|
}
|
2016-09-06 16:54:08 -05:00
|
|
|
}
|