From b7ccf3fa4976a0e13e0d120046edc70f295245cf Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Thu, 10 Nov 2022 12:55:04 -0500 Subject: [PATCH] Fixed App import and legacy Apps upgrade (#103) --- lib/providers/apps_provider.dart | 7 ++++++- lib/providers/source_provider.dart | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index 8bf0e27..13e3fa8 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -139,12 +139,17 @@ class AppsProvider with ChangeNotifier { // The former case should be handled (give the App its real ID), the latter is a security issue var newInfo = await PackageArchiveInfo.fromPath(downloadedFile.path); if (app.id != newInfo.packageName) { - if (apps[app.id] != null) { + if (apps[app.id] != null && !SourceProvider().isTempId(app.id)) { throw IDChangedError(); } + var originalAppId = app.id; app.id = newInfo.packageName; downloadedFile = downloadedFile.renameSync( '${downloadedFile.parent.path}/${app.id}-${app.latestVersion}-${app.preferredApkIndex}.apk'); + if (apps[originalAppId] != null) { + await removeApps([originalAppId]); + await saveApps([app]); + } } return DownloadedApk(app.id, downloadedFile); } diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 2741b19..aec6c70 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -191,6 +191,19 @@ class SourceProvider { String generateTempID(AppNames names, AppSource source) => '${names.author.toLowerCase()}_${names.name.toLowerCase()}_${source.host}'; + bool isTempId(String id) { + List parts = id.split('_'); + if (parts.length < 3) { + return false; + } + for (int i = 0; i < parts.length - 1; i++) { + if (RegExp('.*[A-Z].*').hasMatch(parts[i])) { + return false; + } + } + return getSourceHosts().contains(parts.last); + } + Future getApp(AppSource source, String url, List additionalData, {String name = '', String? id}) async { String standardUrl = source.standardizeURL(preStandardizeUrl(url));