Skip to content

Commit

Permalink
Add Apktool custom path fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kefir500 committed Jun 18, 2018
1 parent a372d87 commit cfc0469
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
4 changes: 3 additions & 1 deletion src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/tooldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit cfc0469

Please sign in to comment.