2023-04-18 21:51:08 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
|
|
|
import 'package:revanced_manager/models/patch.dart';
|
|
|
|
import 'package:revanced_manager/models/patched_application.dart';
|
2023-10-12 02:00:39 +02:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2023-04-18 21:51:08 +02:00
|
|
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
|
|
|
|
|
|
|
bool isPatchSupported(Patch patch) {
|
|
|
|
final PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
|
|
|
|
return patch.compatiblePackages.isEmpty ||
|
|
|
|
patch.compatiblePackages.any(
|
|
|
|
(pack) =>
|
|
|
|
pack.name == app.packageName &&
|
|
|
|
(pack.versions.isEmpty || pack.versions.contains(app.version)),
|
|
|
|
);
|
|
|
|
}
|
2023-10-12 02:00:39 +02:00
|
|
|
|
|
|
|
bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
|
|
|
|
final List<String> requiredOptionsType = [];
|
|
|
|
final List<String> supportedOptionsType = [
|
2023-10-26 22:56:08 +02:00
|
|
|
'String',
|
|
|
|
'Boolean',
|
|
|
|
'Int',
|
|
|
|
'StringArray',
|
|
|
|
'IntArray',
|
|
|
|
'LongArray',
|
2023-10-12 02:00:39 +02:00
|
|
|
];
|
|
|
|
for (final Option option in options) {
|
|
|
|
if (option.required &&
|
|
|
|
option.value == null &&
|
2023-12-23 04:47:12 +01:00
|
|
|
locator<ManagerAPI>().getPatchOption(
|
|
|
|
locator<PatcherViewModel>().selectedApp!.packageName,
|
|
|
|
patch.name,
|
|
|
|
option.key,
|
|
|
|
) ==
|
|
|
|
null) {
|
2023-10-26 22:56:08 +02:00
|
|
|
requiredOptionsType.add(option.valueType);
|
2023-10-12 02:00:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (final String optionType in requiredOptionsType) {
|
|
|
|
if (!supportedOptionsType.contains(optionType)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Option> getNullRequiredOptions(List<Patch> patches, String packageName) {
|
|
|
|
final List<Option> requiredNullOptions = [];
|
|
|
|
for (final patch in patches) {
|
|
|
|
for (final patchOption in patch.options) {
|
|
|
|
if (!patch.excluded &&
|
|
|
|
patchOption.required &&
|
|
|
|
patchOption.value == null &&
|
|
|
|
locator<ManagerAPI>()
|
2023-12-23 04:47:12 +01:00
|
|
|
.getPatchOption(packageName, patch.name, patchOption.key) ==
|
|
|
|
null) {
|
2023-10-12 02:00:39 +02:00
|
|
|
requiredNullOptions.add(patchOption);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return requiredNullOptions;
|
|
|
|
}
|