diff --git a/qtox.pro b/qtox.pro index 8a6c5f132..dc17182a5 100644 --- a/qtox.pro +++ b/qtox.pro @@ -440,6 +440,14 @@ unix:!macx { src/platform/camera/v4l2.cpp } +macx { + SOURCES += \ + src/platform/install_osx.cpp + + HEADERS += \ + src/platform/install_osx.h +} + SOURCES += \ src/audio.cpp \ src/historykeeper.cpp \ diff --git a/src/main.cpp b/src/main.cpp index 24661b20f..834b609d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,6 @@ See the COPYING file for more details. */ -#include "toxme.h" #include "widget/widget.h" #include "misc/settings.h" #include "src/nexus.h" @@ -28,17 +27,15 @@ #include #include #include -#include #include #include #include -#include #include -#include -#define EXIT_UPDATE_MACX 218 //We track our state using unique exit codes when debugging -#define EXIT_UPDATE_MACX_FAIL 216 +#if defined(Q_OS_MACX) && defined(QT_RELEASE) +#include "platform/install_osx.h" +#endif #ifdef LOG_TO_FILE static QTextStream* logFile {nullptr}; @@ -118,7 +115,7 @@ int main(int argc, char *argv[]) if (parser.isSet("p")) { QString profileName = parser.value("p"); - if (QDir(Settings::getSettingsDirPath()).exists(profileName + ".tox")) + if (Profile::exists(profileName)) { qDebug() << "Setting profile to" << profileName; if (Profile::isEncrypted(profileName)) @@ -147,7 +144,7 @@ int main(int argc, char *argv[]) #ifdef LOG_TO_FILE logFile = new QTextStream; - QFile logfile(QDir(Settings::getSettingsDirPath()).filePath("qtox.log")); + QFile logfile(Settings::getSettingsDirPath()+"qtox.log"); if (logfile.open(QIODevice::Append)) { logFile->setDevice(&logfile); @@ -169,60 +166,7 @@ int main(int argc, char *argv[]) qDebug() << "commit: " << GIT_VERSION << "\n"; #if defined(Q_OS_MACX) && defined(QT_RELEASE) - if (qApp->applicationDirPath() != "/Applications/qtox.app/Contents/MacOS") { - qDebug() << "OS X: Not in Applications folder"; - - QMessageBox AskInstall; - AskInstall.setIcon(QMessageBox::Question); - AskInstall.setWindowModality(Qt::ApplicationModal); - AskInstall.setText("Move to Applications folder?"); - AskInstall.setInformativeText("I can move myself to the Applications folder, keeping your downloads folder less cluttered.\r\n"); - AskInstall.setStandardButtons(QMessageBox::Yes|QMessageBox::No); - AskInstall.setDefaultButton(QMessageBox::Yes); - - int AskInstallAttempt = AskInstall.exec(); //Actually ask the user - - if (AskInstallAttempt == QMessageBox::Yes) { - QProcess *sudoprocess = new QProcess; - QProcess *qtoxprocess = new QProcess; - - QString bindir = qApp->applicationDirPath(); - QString appdir = bindir; - appdir.chop(15); - QString sudo = bindir + "/qtox_sudo rsync -avzhpltK " + appdir + " /Applications"; - QString qtox = "open /Applications/qtox.app"; - - QString appdir_noqtox = appdir; - appdir_noqtox.chop(8); - - if ((appdir_noqtox + "qtox.app") != appdir) //quick safety check - { - qDebug() << "OS X: Attmepted to delete non qTox directory!"; - return EXIT_UPDATE_MACX_FAIL; - } - - QDir old_app(appdir); - - sudoprocess->start(sudo); //Where the magic actually happens, safety checks ^ - sudoprocess->waitForFinished(); - - if (old_app.removeRecursively()) //We've just deleted the running program - { - qDebug() << "OS X: Cleaned up old directory"; - } - else - { - qDebug() << "OS X: This should never happen, the directory failed to delete"; - } - - if (fork() != 0) //Forking is required otherwise it won't actually cleanly launch - return EXIT_UPDATE_MACX; - - qtoxprocess->start(qtox); - - return 0; //Actually kills it - } - } + osx::moveToAppFolder(); #endif // Install Unicode 6.1 supporting font diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index e9316920b..95c89f1a0 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -407,14 +407,15 @@ uint32_t Settings::makeProfileId(const QString& profile) QString Settings::getSettingsDirPath() { if (makeToxPortable) - return "."; + return QString(".")+QDir::separator(); // workaround for https://bugreports.qt-project.org/browse/QTBUG-38845 #ifdef Q_OS_WIN - return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) - + QDir::separator() + "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox"); + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator() + + "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox" + QDir::separator()); #else - return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() + "tox"); + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + + QDir::separator() + "tox" + QDir::separator()); #endif } diff --git a/src/misc/settings.h b/src/misc/settings.h index 29155aa16..44ada1c6f 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -36,7 +36,7 @@ public: void createPersonal(QString basename); ///< Write a default personnal settings file for a profile - static QString getSettingsDirPath(); + static QString getSettingsDirPath(); ///< The returned path ends with a directory separator struct DhtServer { diff --git a/src/platform/install_osx.cpp b/src/platform/install_osx.cpp new file mode 100644 index 000000000..1971fdb46 --- /dev/null +++ b/src/platform/install_osx.cpp @@ -0,0 +1,64 @@ +#include "install_osx.h" +#include +#include +#include +#include +#include + +#include + +void osx::moveToAppFolder() +{ + if (qApp->applicationDirPath() != "/Applications/qtox.app/Contents/MacOS") + { + qDebug() << "OS X: Not in Applications folder"; + + QMessageBox AskInstall; + AskInstall.setIcon(QMessageBox::Question); + AskInstall.setWindowModality(Qt::ApplicationModal); + AskInstall.setText("Move to Applications folder?"); + AskInstall.setInformativeText("I can move myself to the Applications folder, keeping your downloads folder less cluttered.\r\n"); + AskInstall.setStandardButtons(QMessageBox::Yes|QMessageBox::No); + AskInstall.setDefaultButton(QMessageBox::Yes); + + int AskInstallAttempt = AskInstall.exec(); //Actually ask the user + + if (AskInstallAttempt == QMessageBox::Yes) + { + QProcess *sudoprocess = new QProcess; + QProcess *qtoxprocess = new QProcess; + + QString bindir = qApp->applicationDirPath(); + QString appdir = bindir; + appdir.chop(15); + QString sudo = bindir + "/qtox_sudo rsync -avzhpltK " + appdir + " /Applications"; + QString qtox = "open /Applications/qtox.app"; + + QString appdir_noqtox = appdir; + appdir_noqtox.chop(8); + + if ((appdir_noqtox + "qtox.app") != appdir) //quick safety check + { + qDebug() << "OS X: Attmepted to delete non qTox directory!"; + exit(EXIT_UPDATE_MACX_FAIL); + } + + QDir old_app(appdir); + + sudoprocess->start(sudo); //Where the magic actually happens, safety checks ^ + sudoprocess->waitForFinished(); + + if (old_app.removeRecursively()) //We've just deleted the running program + qDebug() << "OS X: Cleaned up old directory"; + else + qDebug() << "OS X: This should never happen, the directory failed to delete"; + + if (fork() != 0) //Forking is required otherwise it won't actually cleanly launch + exit(EXIT_UPDATE_MACX); + + qtoxprocess->start(qtox); + + exit(0); //Actually kills it + } + } +} diff --git a/src/platform/install_osx.h b/src/platform/install_osx.h new file mode 100644 index 000000000..8c1e7643f --- /dev/null +++ b/src/platform/install_osx.h @@ -0,0 +1,16 @@ +#ifndef INSTALLOSX_H +#define INSTALLOSX_H + +#ifndef Q_OS_MACX +#error "This file is only meant to be compiled for Mac OSX targets" +#endif + +namespace osx +{ + static constexpr int EXIT_UPDATE_MACX = 218; // We track our state using unique exit codes when debugging + static constexpr int EXIT_UPDATE_MACX_FAIL = 216; + + void moveToAppFolder(); +} + +#endif // INSTALLOSX_H diff --git a/src/profile.cpp b/src/profile.cpp index 4987e0d94..04bf4ab38 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -54,7 +54,7 @@ Profile* Profile::createProfile(QString name, QString password) return nullptr; } - if (profileExists(name)) + if (exists(name)) { qCritical() << "Tried to create profile "< getProfiles(); - static bool profileExists(QString name); + static bool exists(QString name); static bool isEncrypted(QString name); ///< Returns false on error. Checks the actual file on disk. private: diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 252980a07..9788264aa 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -240,7 +240,7 @@ void ProfileForm::onRenameClicked() if (name.isEmpty()) break; name = Core::sanitize(name); - if (Profile::profileExists(name)) + if (Profile::exists(name)) GUI::showError(tr("Profile already exists", "rename failure title"), tr("A profile named \"%1\" already exists.", "rename confirm text").arg(name)); else if (!nexus.getProfile()->rename(name)) diff --git a/src/widget/loginscreen.cpp b/src/widget/loginscreen.cpp index cacfcecc5..e160b1541 100644 --- a/src/widget/loginscreen.cpp +++ b/src/widget/loginscreen.cpp @@ -92,7 +92,7 @@ void LoginScreen::onCreateNewProfile() return; } - if (Profile::profileExists(name)) + if (Profile::exists(name)) { QMessageBox::critical(this, tr("Couldn't create a new profile"), tr("This profile already exists.")); return;