mirror of
https://github.com/topjohnwu/Magisk
synced 2025-09-01 00:31:43 +00:00
Magisk-Modules-Repo now names repo with ID, simplify logic here
This commit is contained in:
@@ -66,17 +66,15 @@ public class UpdateRepos {
|
|||||||
|
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject rawRepo = jsonArray.getJSONObject(i);
|
JSONObject rawRepo = jsonArray.getJSONObject(i);
|
||||||
String id = rawRepo.getString("description");
|
String id = rawRepo.getString("name");
|
||||||
String name = rawRepo.getString("name");
|
|
||||||
Date date = dateFormat.parse(rawRepo.getString("pushed_at"));
|
Date date = dateFormat.parse(rawRepo.getString("pushed_at"));
|
||||||
Set<String> set = Collections.synchronizedSet(cached);
|
|
||||||
threadPool.execute(() -> {
|
threadPool.execute(() -> {
|
||||||
Repo repo = mm.repoDB.getRepo(id);
|
Repo repo = mm.repoDB.getRepo(id);
|
||||||
try {
|
try {
|
||||||
if (repo == null)
|
if (repo == null)
|
||||||
repo = new Repo(name);
|
repo = new Repo(id);
|
||||||
else
|
else
|
||||||
set.remove(id);
|
cached.remove(id);
|
||||||
repo.update(date);
|
repo.update(date);
|
||||||
mm.repoDB.addRepo(repo);
|
mm.repoDB.addRepo(repo);
|
||||||
} catch (Repo.IllegalRepoException e) {
|
} catch (Repo.IllegalRepoException e) {
|
||||||
@@ -141,7 +139,7 @@ public class UpdateRepos {
|
|||||||
public void exec(boolean force) {
|
public void exec(boolean force) {
|
||||||
Topic.reset(Topic.REPO_LOAD_DONE);
|
Topic.reset(Topic.REPO_LOAD_DONE);
|
||||||
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
||||||
cached = mm.repoDB.getRepoIDSet();
|
cached = Collections.synchronizedSet(mm.repoDB.getRepoIDSet());
|
||||||
threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE);
|
threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE);
|
||||||
|
|
||||||
if (loadPage(0)) {
|
if (loadPage(0)) {
|
||||||
|
@@ -2,7 +2,6 @@ package com.topjohnwu.magisk.container;
|
|||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.Const;
|
import com.topjohnwu.magisk.Const;
|
||||||
import com.topjohnwu.magisk.utils.Download;
|
import com.topjohnwu.magisk.utils.Download;
|
||||||
@@ -15,16 +14,14 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class Repo extends BaseModule {
|
public class Repo extends BaseModule {
|
||||||
|
|
||||||
private String repoName;
|
|
||||||
private Date mLastUpdate;
|
private Date mLastUpdate;
|
||||||
|
|
||||||
public Repo(String name) {
|
public Repo(String id) {
|
||||||
repoName = name;
|
setId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Repo(Cursor c) {
|
public Repo(Cursor c) {
|
||||||
super(c);
|
super(c);
|
||||||
repoName = c.getString(c.getColumnIndex("repo_name"));
|
|
||||||
mLastUpdate = new Date(c.getLong(c.getColumnIndex("last_update")));
|
mLastUpdate = new Date(c.getLong(c.getColumnIndex("last_update")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,17 +30,14 @@ public class Repo extends BaseModule {
|
|||||||
try {
|
try {
|
||||||
parseProps(props);
|
parseProps(props);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new IllegalRepoException("Repo [" + repoName + "] parse error: " + e.getMessage());
|
throw new IllegalRepoException("Repo [" + getId() + "] parse error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.isEmpty(getId())) {
|
|
||||||
throw new IllegalRepoException("Repo [" + repoName + "] does not contain id");
|
|
||||||
}
|
|
||||||
if (getVersionCode() < 0) {
|
if (getVersionCode() < 0) {
|
||||||
throw new IllegalRepoException("Repo [" + repoName + "] does not contain versionCode");
|
throw new IllegalRepoException("Repo [" + getId() + "] does not contain versionCode");
|
||||||
}
|
}
|
||||||
if (getMinMagiskVersion() < Const.MIN_MODULE_VER()) {
|
if (getMinMagiskVersion() < Const.MIN_MODULE_VER()) {
|
||||||
Logger.debug("Repo [" + repoName + "] is outdated");
|
Logger.debug("Repo [" + getId() + "] is outdated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,25 +49,20 @@ public class Repo extends BaseModule {
|
|||||||
@Override
|
@Override
|
||||||
public ContentValues getContentValues() {
|
public ContentValues getContentValues() {
|
||||||
ContentValues values = super.getContentValues();
|
ContentValues values = super.getContentValues();
|
||||||
values.put("repo_name", repoName);
|
|
||||||
values.put("last_update", mLastUpdate.getTime());
|
values.put("last_update", mLastUpdate.getTime());
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRepoName() {
|
|
||||||
return repoName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getZipUrl() {
|
public String getZipUrl() {
|
||||||
return String.format(Const.Url.ZIP_URL, repoName);
|
return String.format(Const.Url.ZIP_URL, getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getManifestUrl() {
|
public String getManifestUrl() {
|
||||||
return String.format(Const.Url.FILE_URL, repoName, "module.prop");
|
return String.format(Const.Url.FILE_URL, getId(), "module.prop");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDetailUrl() {
|
public String getDetailUrl() {
|
||||||
return String.format(Const.Url.FILE_URL, repoName, "README.md");
|
return String.format(Const.Url.FILE_URL, getId(), "README.md");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastUpdateString() {
|
public String getLastUpdateString() {
|
||||||
|
@@ -16,7 +16,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static final int DATABASE_VER = 3;
|
private static final int DATABASE_VER = 4;
|
||||||
private static final String TABLE_NAME = "repos";
|
private static final String TABLE_NAME = "repos";
|
||||||
|
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
@@ -40,21 +40,14 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
try {
|
if (oldVersion != newVersion) {
|
||||||
if (oldVersion < 3) {
|
// Nuke old DB and create new table
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " " +
|
"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " " +
|
||||||
"(id TEXT, name TEXT, version TEXT, versionCode INT, minMagisk INT, " +
|
"(id TEXT, name TEXT, version TEXT, versionCode INT, minMagisk INT, " +
|
||||||
"author TEXT, description TEXT, repo_name TEXT, last_update INT, " +
|
"author TEXT, description TEXT, last_update INT, PRIMARY KEY(id))");
|
||||||
"PRIMARY KEY(id))");
|
mm.prefs.edit().remove(Const.Key.ETAG_KEY).apply();
|
||||||
mm.prefs.edit().remove(Const.Key.ETAG_KEY).apply();
|
|
||||||
oldVersion = 3;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
// Reset database
|
|
||||||
onDowngrade(db, DATABASE_VER, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +68,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeRepo(Repo repo) {
|
public void removeRepo(Repo repo) {
|
||||||
mDb.delete(TABLE_NAME, "repo_name=?", new String[] { repo.getRepoName() });
|
removeRepo(repo.getId());
|
||||||
notifyAdapter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRepo(Iterable<String> list) {
|
public void removeRepo(Iterable<String> list) {
|
||||||
|
Reference in New Issue
Block a user