From fbd0cc59b6791a202b5998143393f9cdaeefb96f Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 3 Mar 2015 19:23:54 -0800 Subject: [PATCH 1/3] OS X applications folder support --- src/main.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ec7a3c1d2..664888665 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,11 +29,16 @@ #include #include #include +#include #include #include "toxme.h" +#include + +#define EXIT_UPDATE_MACX 218 //We track our state using unique exit codes when debugging + #ifdef LOG_TO_FILE static QtMessageHandler dflt; static QTextStream* logFile {nullptr}; @@ -106,7 +111,7 @@ int main(int argc, char *argv[]) } else { - fprintf(stderr, "Couldn't open log file!!!\n"); + fprintf(stderr, "Couldn't open log file!\n"); delete logFile; logFile = nullptr; } @@ -119,6 +124,46 @@ int main(int argc, char *argv[]) qDebug() << "built on: " << __TIME__ << __DATE__ << "(" << TIMESTAMP << ")"; qDebug() << "commit: " << GIT_VERSION << "\n"; +#ifdef Q_OS_MACX + 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(); //Check if user sucks + + if (AskInstallAttempt == QMessageBox::Yes) { + qDebug() << "Installing"; + QProcess *sudoprocess = new QProcess; + QProcess *qtoxprocess = new QProcess; + + QString bindir = qApp->applicationDirPath(); + QString appdir = bindir; + appdir.chop(15); + QString sudo = bindir + "/qtox_sudo mv " + appdir + " /Applications/qtox.app"; + QString qtox = "open /Applications/qtox.app"; + + if (fork() != 0) { //uTox grade cheap hack + return EXIT_UPDATE_MACX; + } + + sudoprocess->start(sudo); + sudoprocess->waitForFinished(); + qtoxprocess->start(qtox); + + qApp->quit(); //stop it from exiting by crashing rofl + qApp->exit(); + return 0; + } + } +#endif + // Install Unicode 6.1 supporting font QFontDatabase::addApplicationFont("://DejaVuSans.ttf"); From f51cd63cffa67d18dc35fa8ed3beb64bf17e8049 Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 3 Mar 2015 19:50:30 -0800 Subject: [PATCH 2/3] Almost forgot mv is harmful Note that this is required because Qt applications cannot run under setuid(0) as qtox_sudo sets . Fix quitting --- src/main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 664888665..49e62ee63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) 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.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); @@ -146,20 +146,18 @@ int main(int argc, char *argv[]) QString bindir = qApp->applicationDirPath(); QString appdir = bindir; appdir.chop(15); - QString sudo = bindir + "/qtox_sudo mv " + appdir + " /Applications/qtox.app"; + QString sudo = bindir + "/qtox_sudo rsync -avzh --remove-source-file " + appdir + " /Applications/qtox.app"; QString qtox = "open /Applications/qtox.app"; if (fork() != 0) { //uTox grade cheap hack - return EXIT_UPDATE_MACX; + return EXIT_UPDATE_MACX; //Note that if we don't do this the update process will get killed. Also, errors just crash it } sudoprocess->start(sudo); sudoprocess->waitForFinished(); qtoxprocess->start(qtox); - qApp->quit(); //stop it from exiting by crashing rofl - qApp->exit(); - return 0; + return 0; //Actually kills it } } #endif From dddf5b73d40b867e91f40c8e08f9669283af7425 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 4 Mar 2015 12:29:12 -0800 Subject: [PATCH 3/3] Political correctness --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 49e62ee63..40446eccf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) AskInstall.setStandardButtons(QMessageBox::Yes|QMessageBox::No); AskInstall.setDefaultButton(QMessageBox::Yes); - int AskInstallAttempt = AskInstall.exec(); //Check if user sucks + int AskInstallAttempt = AskInstall.exec(); //Actually ask the user if (AskInstallAttempt == QMessageBox::Yes) { qDebug() << "Installing"; @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) QString sudo = bindir + "/qtox_sudo rsync -avzh --remove-source-file " + appdir + " /Applications/qtox.app"; QString qtox = "open /Applications/qtox.app"; - if (fork() != 0) { //uTox grade cheap hack + if (fork() != 0) { //cheap hack return EXIT_UPDATE_MACX; //Note that if we don't do this the update process will get killed. Also, errors just crash it }