Skip to content

Commit

Permalink
Forbid Run as admin usage by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
moonshadow565 committed May 21, 2023
1 parent 317ea04 commit 726f473
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/CSLOLToolsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ void CSLOLToolsImpl::doReportError(QString name, QString message, QString trace)
if (!trace.isEmpty()) {
logFile_->write(trace.toUtf8() + "\n");
}
if (message.contains("OpenProcess: ") || trace.contains("OpenProcess: ")) {
QFile file(prog_ + "/allow_admin.txt");
file.open(QIODevice::WriteOnly);
file.close();
trace += '\n';
trace += ">>Run as administrator<< is now enabled!";
}
emit reportError(name, message, trace);
}

Expand Down
22 changes: 22 additions & 0 deletions src/CSLOLUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QFileInfo>
#include <QSysInfo>
Expand Down Expand Up @@ -99,7 +100,28 @@ QString CSLOLUtils::detectGamePath() {
CloseHandle(snapshot);
return "";
}


bool CSLOLUtils::isUnnecessaryAdmin() {
if (QFileInfo info(QCoreApplication::applicationDirPath() + "/allow_admin.txt"); info.exists()) {
return false;
}
bool result = 0;
HANDLE token = {};
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) {
TOKEN_ELEVATION elevation = {};
DWORD size = sizeof(TOKEN_ELEVATION);
if (GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &size)) {
result = elevation.TokenIsElevated;
}
CloseHandle(token);
}
return result;
}
#else
// TODO: macos implementation
QString CSLOLUtils::detectGamePath() { return ""; }

// TODO: macos implementation
bool CSLOLUtils::isUnnecessaryAdmin() { return false; }
#endif
1 change: 1 addition & 0 deletions src/CSLOLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CSLOLUtils : public QObject {
Q_INVOKABLE QString toFile(QString file);
Q_INVOKABLE QString checkGamePath(QString path);
Q_INVOKABLE QString detectGamePath();
Q_INVOKABLE bool isUnnecessaryAdmin();

private:
};
Expand Down
2 changes: 1 addition & 1 deletion src/qml/CSLOLToolBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ToolBar {
text: "\uf004"
font.family: "FontAwesome"
onClicked: {
Qt.openUrlExternally("https://github.com/morilli")
Qt.openUrlExternally("https://github.com/LeagueToolkit/cslol-manager/graphs/contributors")
}
}
ToolButton {
Expand Down
6 changes: 5 additions & 1 deletion src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ ApplicationWindow {
}
}
firstTick = true;
cslolTools.init()
if (CSLOLUtils.isUnnecessaryAdmin()) {
window.showUserError("Unnecessary admin", "Running as admin is disabled by default.\nTry running without admin at least once.")
} else {
cslolTools.init()
}
cslolDialogUpdate.checkForUpdates()
}
}

0 comments on commit 726f473

Please sign in to comment.