From f297af13d5d4cb0cb1b0069f1a3d00262622689b Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Sat, 30 Nov 2024 11:54:52 -0800 Subject: [PATCH 1/3] fix: Delete cached APK after patching Instead of deleting the cached APK from the file picker **before** patching, the manager will only delete it **after** patching --- lib/services/patcher_api.dart | 7 ------- lib/ui/views/installer/installer_viewmodel.dart | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/services/patcher_api.dart b/lib/services/patcher_api.dart index 6ac47d2f03..f40337e7c2 100644 --- a/lib/services/patcher_api.dart +++ b/lib/services/patcher_api.dart @@ -175,13 +175,6 @@ class PatcherAPI { final File inApkFile = File('${workDir.path}/in.apk'); await File(apkFilePath).copy(inApkFile.path); - if (isFromStorage) { - // The selected apk was copied to cacheDir by the file picker, so it's not needed anymore. - // rename() can't be used here, as Android system also counts the size of files moved out from cacheDir - // as part of the app's cache size. - File(apkFilePath).delete(); - } - outFile = File('${workDir.path}/out.apk'); final Directory tmpDir = diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 65cbf513ce..bc5ef8828d 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -1,4 +1,6 @@ // ignore_for_file: use_build_context_synchronously +import 'dart:io'; + import 'package:device_apps/device_apps.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -566,6 +568,9 @@ class InstallerViewModel extends BaseViewModel { Future cleanPatcher() async { try { _patcherAPI.cleanPatcher(); + if (_app.isFromStorage) { + File(_app.apkFilePath).delete(); + } locator().selectedApp = null; locator().selectedPatches.clear(); locator().notifyListeners(); From 5c8a8f81cd04ea152a0c90e7a525a7f6fa6df96d Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Sat, 30 Nov 2024 11:57:16 -0800 Subject: [PATCH 2/3] Update installer_viewmodel.dart --- lib/ui/views/installer/installer_viewmodel.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index bc5ef8828d..35695253c9 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -569,6 +569,9 @@ class InstallerViewModel extends BaseViewModel { try { _patcherAPI.cleanPatcher(); if (_app.isFromStorage) { + // The selected apk was copied to cacheDir by the file picker, so it's not needed anymore. + // rename() can't be used here, as Android system also counts the size of files moved out from cacheDir + // as part of the app's cache size. File(_app.apkFilePath).delete(); } locator().selectedApp = null; From 543fd530f33a1b23c395d6160b404dff18c67a4a Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Sat, 30 Nov 2024 12:04:54 -0800 Subject: [PATCH 3/3] Update installer_viewmodel.dart --- lib/ui/views/installer/installer_viewmodel.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 35695253c9..7e7cfdcf52 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -570,8 +570,6 @@ class InstallerViewModel extends BaseViewModel { _patcherAPI.cleanPatcher(); if (_app.isFromStorage) { // The selected apk was copied to cacheDir by the file picker, so it's not needed anymore. - // rename() can't be used here, as Android system also counts the size of files moved out from cacheDir - // as part of the app's cache size. File(_app.apkFilePath).delete(); } locator().selectedApp = null;