use of de.robv.android.xposed.installer.repo.RepoParser.RepoParserCallback in project XposedInstaller by rovo89.
the class RepoLoader method downloadAndParseFiles.
private boolean downloadAndParseFiles(List<String> messages) {
// These variables don't need to be atomic, just mutable
final AtomicBoolean hasChanged = new AtomicBoolean(false);
final AtomicInteger insertCounter = new AtomicInteger();
final AtomicInteger deleteCounter = new AtomicInteger();
for (Entry<Long, Repository> repoEntry : mRepositories.entrySet()) {
final long repoId = repoEntry.getKey();
final Repository repo = repoEntry.getValue();
String url = (repo.partialUrl != null && repo.version != null) ? String.format(repo.partialUrl, repo.version) : repo.url;
File cacheFile = getRepoCacheFile(url);
SyncDownloadInfo info = DownloadsUtil.downloadSynchronously(url, cacheFile);
Log.i(XposedApp.TAG, String.format("Downloaded %s with status %d (error: %s), size %d bytes", url, info.status, info.errorMessage, cacheFile.length()));
if (info.status != SyncDownloadInfo.STATUS_SUCCESS) {
if (info.errorMessage != null)
messages.add(info.errorMessage);
continue;
}
InputStream in = null;
RepoDb.beginTransation();
try {
in = new FileInputStream(cacheFile);
if (url.endsWith(".gz"))
in = new GZIPInputStream(in);
RepoParser.parse(in, new RepoParserCallback() {
@Override
public void onRepositoryMetadata(Repository repository) {
if (!repository.isPartial) {
RepoDb.deleteAllModules(repoId);
hasChanged.set(true);
}
}
@Override
public void onNewModule(Module module) {
RepoDb.insertModule(repoId, module);
hasChanged.set(true);
insertCounter.incrementAndGet();
}
@Override
public void onRemoveModule(String packageName) {
RepoDb.deleteModule(repoId, packageName);
hasChanged.set(true);
deleteCounter.decrementAndGet();
}
@Override
public void onCompleted(Repository repository) {
if (!repository.isPartial) {
RepoDb.updateRepository(repoId, repository);
repo.name = repository.name;
repo.partialUrl = repository.partialUrl;
repo.version = repository.version;
} else {
RepoDb.updateRepositoryVersion(repoId, repository.version);
repo.version = repository.version;
}
Log.i(XposedApp.TAG, String.format("Updated repository %s to version %s (%d new / %d removed modules)", repo.url, repo.version, insertCounter.get(), deleteCounter.get()));
}
});
RepoDb.setTransactionSuccessful();
} catch (Throwable t) {
Log.e(XposedApp.TAG, "Cannot load repository from " + url, t);
messages.add(sApp.getString(R.string.repo_load_failed, url, t.getMessage()));
DownloadsUtil.clearCache(url);
} finally {
if (in != null)
try {
in.close();
} catch (IOException ignored) {
}
cacheFile.delete();
RepoDb.endTransation();
}
}
// repositories
return hasChanged.get();
}
Aggregations