lokinet/contrib/macos/uninstaller/main.cpp

45 lines
1.1 KiB
C++
Raw Normal View History

#include <QApplication>
#include <QMessageBox>
2020-11-16 13:07:25 +00:00
#include <CoreFoundation/CoreFoundation.h>
2020-11-16 13:08:08 +00:00
#include <Security.h>
int uninstall();
int main(int argc, char * argv[])
{
QApplication app{argc, argv};
if(QMessageBox::question(nullptr, "Lokinet Uninstaller", "Do You want to uninstall Lokinet?",
QMessageBox::Yes|QMessageBox::No)
== QMessageBox::Yes)
{
QMessageBox msgBox;
const auto retcode = uninstall();
if(retcode == 0)
{
msgBox.setText("Lokinet has been successfully uninstalled, you may now remove the uninstaller if you wish.");
}
else
{
2020-11-16 13:07:25 +00:00
msgBox.setText("Failed to uninstall lokinet");
}
msgBox.exec();
}
return 0;
}
int uninstall()
{
AuthorizationRef authorizationRef;
OSStatus status;
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef);
char* tool = "/bin/bash";
char* args[] = { "-c" , "/opt/lokinet/bin/lokinet_uninstall.sh", nullptr};
FILE* pipe = NULL;
2020-11-16 13:07:25 +00:00
return AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
}