Skip to content

Commit

Permalink
v3.1 Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayLimaye committed Feb 27, 2023
1 parent 36e044a commit 20a1ad8
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 1,623 deletions.
44 changes: 41 additions & 3 deletions drishti/launcher.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#include "launcher.h"
#include <QDir>

#ifdef Q_OS_WIN
#include <windows.h>
#include <shellapi.h>
#endif


Launcher::Launcher(QWidget *parent) :
QDialog(parent, Qt::WindowTitleHint|Qt::WindowCloseButtonHint)
{
ui.setupUi(this);



setStyleSheet("QWidget{background:black;}");
ui.drishti->setStyleSheet("QWidget{background:aliceblue;}");
ui.drishtiImport->setStyleSheet("QWidget{background:azure;}");
Expand Down Expand Up @@ -44,11 +50,33 @@ Launcher::drishti(bool b)
close();
}


//When running under Microsoft Windows with User Account Control (UAC) enabled,
//the following code always fails if starting a program that requires elevated
//privileges.
//The inner reason for this failure is that QProcess::startDetached method
//under Windows internally calls CreateProcess function. CreateProcess called
//from a non-elevated process fails with ERROR_ELEVATION_REQUIRED if it tries
//to start an executable that requires elevation.
//Corresponding error report in Qt Bug Tracker was rejected because it "sounds
//like a reasonable limitation of QProcess".
//Hence QProcess::startDetached is replaced with ShellExecute function.

void
Launcher::drishtiImport(bool b)
{
#if defined(Q_OS_WIN32)
QProcess::startDetached(qApp->applicationDirPath() + QDir::separator() + "drishtiimport.exe");
QString exeFileName = qApp->applicationDirPath() + QDir::separator() + "drishtiimport.exe";
int result = (int)::ShellExecuteA(0, "open", exeFileName.toUtf8().constData(), 0, 0, SW_SHOWNORMAL);
if (SE_ERR_ACCESSDENIED == result)
{
// Requesting elevation
result = (int)::ShellExecuteA(0, "runas", exeFileName.toUtf8().constData(), 0, 0, SW_SHOWNORMAL);
}
if (result <= 32)
{
// error handling
}
#else
QProcess::startDetached(qApp->applicationDirPath() + QDir::separator() + "drishtiimport");
#endif
Expand All @@ -59,7 +87,17 @@ void
Launcher::drishtiPaint(bool b)
{
#if defined(Q_OS_WIN32)
QProcess::startDetached(qApp->applicationDirPath() + QDir::separator() + "drishtipaint.exe");
QString exeFileName = qApp->applicationDirPath() + QDir::separator() + "drishtipaint.exe";
int result = (int)::ShellExecuteA(0, "open", exeFileName.toUtf8().constData(), 0, 0, SW_SHOWNORMAL);
if (SE_ERR_ACCESSDENIED == result)
{
// Requesting elevation
result = (int)::ShellExecuteA(0, "runas", exeFileName.toUtf8().constData(), 0, 0, SW_SHOWNORMAL);
}
if (result <= 32)
{
// error handling
}
#else
QProcess::startDetached(qApp->applicationDirPath() + QDir::separator() + "drishtipaint");
#endif
Expand Down
Loading

0 comments on commit 20a1ad8

Please sign in to comment.