mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'pr1341'
This commit is contained in:
commit
dd3087fc3d
28
src/main.cpp
28
src/main.cpp
|
@ -39,6 +39,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define EXIT_UPDATE_MACX 218 //We track our state using unique exit codes when debugging
|
#define EXIT_UPDATE_MACX 218 //We track our state using unique exit codes when debugging
|
||||||
|
#define EXIT_UPDATE_MACX_FAIL 216
|
||||||
|
|
||||||
#ifdef LOG_TO_FILE
|
#ifdef LOG_TO_FILE
|
||||||
static QtMessageHandler dflt;
|
static QtMessageHandler dflt;
|
||||||
|
@ -154,22 +155,39 @@ int main(int argc, char *argv[])
|
||||||
int AskInstallAttempt = AskInstall.exec(); //Actually ask the user
|
int AskInstallAttempt = AskInstall.exec(); //Actually ask the user
|
||||||
|
|
||||||
if (AskInstallAttempt == QMessageBox::Yes) {
|
if (AskInstallAttempt == QMessageBox::Yes) {
|
||||||
qDebug() << "Installing";
|
|
||||||
QProcess *sudoprocess = new QProcess;
|
QProcess *sudoprocess = new QProcess;
|
||||||
QProcess *qtoxprocess = new QProcess;
|
QProcess *qtoxprocess = new QProcess;
|
||||||
|
|
||||||
QString bindir = qApp->applicationDirPath();
|
QString bindir = qApp->applicationDirPath();
|
||||||
QString appdir = bindir;
|
QString appdir = bindir;
|
||||||
appdir.chop(15);
|
appdir.chop(15);
|
||||||
QString sudo = bindir + "/qtox_sudo rsync -avzh --remove-source-file " + appdir + " /Applications/qtox.app";
|
QString sudo = bindir + "/qtox_sudo rsync -avzhpltK " + appdir + " /Applications";
|
||||||
QString qtox = "open /Applications/qtox.app";
|
QString qtox = "open /Applications/qtox.app";
|
||||||
|
|
||||||
if (fork() != 0) { //cheap hack
|
QString appdir_noqtox = appdir;
|
||||||
return EXIT_UPDATE_MACX; //Note that if we don't do this the update process will get killed. Also, errors just crash it
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
sudoprocess->start(sudo);
|
QDir old_app(appdir);
|
||||||
|
|
||||||
|
sudoprocess->start(sudo); //Where the magic actually happens, safety checks ^
|
||||||
sudoprocess->waitForFinished();
|
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);
|
qtoxprocess->start(qtox);
|
||||||
|
|
||||||
return 0; //Actually kills it
|
return 0; //Actually kills it
|
||||||
|
|
Loading…
Reference in New Issue
Block a user