feat: clean patcher cache folder on init

This commit is contained in:
Alberto Ponces 2022-08-30 02:18:20 +01:00
parent 5c657fbed5
commit 1920221b19

View File

@ -19,12 +19,21 @@ class PatcherAPI {
);
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final RootAPI _rootAPI = RootAPI();
late Directory _tmpDir;
List<Patch> _patches = [];
Directory? _tmpDir;
File? _outFile;
Future<void> initialize() async {
await _loadPatches();
Directory appCache = await getTemporaryDirectory();
_tmpDir = Directory('${appCache.path}/patcher');
cleanPatcher();
}
void cleanPatcher() {
if (_tmpDir.existsSync()) {
_tmpDir.deleteSync(recursive: true);
}
}
Future<void> _loadPatches() async {
@ -111,10 +120,8 @@ class PatcherAPI {
integrationsFile = await _managerAPI.downloadIntegrations('.apk');
}
if (patchBundleFile != null) {
Directory appCache = await getTemporaryDirectory();
_tmpDir = Directory('${appCache.path}/patcher');
_tmpDir!.createSync();
Directory workDir = _tmpDir!.createTempSync('tmp-');
_tmpDir.createSync();
Directory workDir = _tmpDir.createTempSync('tmp-');
File inputFile = File('${workDir.path}/base.apk');
File patchedFile = File('${workDir.path}/patched.apk');
_outFile = File('${workDir.path}/out.apk');
@ -158,13 +165,6 @@ class PatcherAPI {
return false;
}
void cleanPatcher() {
if (_tmpDir != null) {
_tmpDir!.deleteSync(recursive: true);
_tmpDir = null;
}
}
bool sharePatchedFile(String appName, String version) {
if (_outFile != null) {
String prefix = appName.toLowerCase().replaceAll(' ', '-');