From cfc046937132772c84b9cb07d89576e9ab82faa5 Mon Sep 17 00:00:00 2001 From: Alexander Gorishnyak Date: Mon, 18 Jun 2018 12:48:40 +0600 Subject: [PATCH] Add Apktool custom path fallback --- src/core/settings.cpp | 13 +++++++------ src/core/settings.h | 4 +++- src/dialogs/tooldialog.cpp | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 3754100..9d24fa3 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -71,15 +71,16 @@ QStringList Settings::get_recent() { return settings->value("Recent", 0).toStri QString Settings::get_temp(bool fallback) { - const QString TEMP = QDir::toNativeSeparators(Path::Data::temp()); - const QString PATH = settings->value("Temp", TEMP).toString(); - return (fallback && (!QDir(PATH).exists() || PATH.isEmpty())) ? TEMP : PATH; + const QString defaultPath = QDir::toNativeSeparators(Path::Data::temp()); + const QString currentPath = settings->value("Temp", defaultPath).toString(); + return (fallback && (!QDir(currentPath).exists() || currentPath.isEmpty())) ? defaultPath : currentPath; } -QString Settings::get_apktool() +QString Settings::get_apktool(bool fallback) { - const QString APKTOOL = QDir::toNativeSeparators(Path::Data::shared() + "apktool.jar"); - return settings->value("Paths/Apktool", APKTOOL).toString(); + const QString defaultPath = QDir::toNativeSeparators(Path::Data::shared() + "apktool.jar"); + const QString currentPath = settings->value("Paths/Apktool", defaultPath).toString(); + return (fallback && (!QFile::exists(currentPath))) ? defaultPath : currentPath; } bool Settings::get_use_apksigner() { return settings->value("APK/Apksigner", false).toBool(); } diff --git a/src/core/settings.h b/src/core/settings.h index 8a5db53..6d8281a 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -34,7 +34,9 @@ class Settings { static QByteArray get_splitter(); ///< Returns the position of the main window splitter. static QStringList get_recent(); ///< Returns the list of the recent APK files. - static QString get_apktool(); ///< Return the path to Apktool. + /// Returns the path to Apktool. + /// \param fallback If \c true, the default value will be returned instead of *nonexistent* Apktool path. + static QString get_apktool(bool fallback = true); static bool get_use_apksigner(); ///< Returns \c true if the apksigner is used instead of signapk / jarsigner. static bool get_smali(); ///< Returns \c true if smali/baksmali tool is used. static bool get_sign(); ///< Returns \c true if the signing of the APK files is turned on. diff --git a/src/dialogs/tooldialog.cpp b/src/dialogs/tooldialog.cpp index ce7756a..800fd58 100644 --- a/src/dialogs/tooldialog.cpp +++ b/src/dialogs/tooldialog.cpp @@ -66,7 +66,7 @@ void ToolDialog::reject() void ToolDialog::reset() { - apktoolPath->setValue(Settings::get_apktool()); + apktoolPath->setValue(Settings::get_apktool(false)); checkSmali->setChecked(Settings::get_smali()); groupSign->setChecked(Settings::get_sign()); checkOptimize->setChecked(Settings::get_zipalign());