Skip to content

Commit

Permalink
fix: Retrieve app information from patched app
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 30, 2023
1 parent c4a7954 commit 2b4b3ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PatcherAPI {
List<Patch> _universalPatches = [];
List<String> _compatiblePackages = [];
Map filteredPatches = <String, List<Patch>>{};
File? _outFile;
File? outFile;

Future<void> initialize() async {
await _loadPatches();
Expand Down Expand Up @@ -162,7 +162,7 @@ class PatcherAPI {
final Directory workDir = _tmpDir.createTempSync('tmp-');
final File inputFile = File('${workDir.path}/base.apk');
final File patchedFile = File('${workDir.path}/patched.apk');
_outFile = File('${workDir.path}/out.apk');
outFile = File('${workDir.path}/out.apk');
final Directory cacheDir = Directory('${workDir.path}/cache');
cacheDir.createSync();
final String originalFilePath = apkFilePath;
Expand All @@ -174,7 +174,7 @@ class PatcherAPI {
'originalFilePath': originalFilePath,
'inputFilePath': inputFile.path,
'patchedFilePath': patchedFile.path,
'outFilePath': _outFile!.path,
'outFilePath': outFile!.path,
'integrationsPath': integrationsFile!.path,
'selectedPatches': selectedPatches.map((p) => p.name).toList(),
'cacheDirPath': cacheDir.path,
Expand All @@ -201,19 +201,19 @@ class PatcherAPI {
}

Future<bool> installPatchedFile(PatchedApplication patchedApp) async {
if (_outFile != null) {
if (outFile != null) {
try {
if (patchedApp.isRooted) {
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
return _rootAPI.installApp(
patchedApp.packageName,
patchedApp.apkFilePath,
_outFile!.path,
outFile!.path,
);
}
} else {
final install = await InstallPlugin.installApk(_outFile!.path);
final install = await InstallPlugin.installApk(outFile!.path);
return install['isSuccess'];
}
} on Exception catch (e) {
Expand All @@ -228,11 +228,11 @@ class PatcherAPI {

void exportPatchedFile(String appName, String version) {
try {
if (_outFile != null) {
if (outFile != null) {
final String newName = _getFileName(appName, version);
CRFileSaver.saveFileWithDialog(
SaveFileDialogParams(
sourceFilePath: _outFile!.path,
sourceFilePath: outFile!.path,
destinationFileName: newName,
),
);
Expand All @@ -246,12 +246,12 @@ class PatcherAPI {

void sharePatchedFile(String appName, String version) {
try {
if (_outFile != null) {
if (outFile != null) {
final String newName = _getFileName(appName, version);
final int lastSeparator = _outFile!.path.lastIndexOf('/');
final int lastSeparator = outFile!.path.lastIndexOf('/');
final String newPath =
_outFile!.path.substring(0, lastSeparator + 1) + newName;
final File shareFile = _outFile!.copySync(newPath);
outFile!.path.substring(0, lastSeparator + 1) + newName;
final File shareFile = outFile!.copySync(newPath);
ShareExtend.share(shareFile.path, 'file');
}
} on Exception catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class InstallerViewModel extends BaseViewModel {

// In case a patch changed the app name or package name,
// update the app info.
final app = await DeviceApps.getAppFromStorage(_app.apkFilePath);
final app = await DeviceApps.getAppFromStorage(_patcherAPI.outFile!.path);
if (app != null) {
_app.name = app.appName;
_app.packageName = app.packageName;
Expand Down

0 comments on commit 2b4b3ca

Please sign in to comment.