feat: successful process elevation and comunication!

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers
2023-02-08 00:35:03 -08:00
parent 32409a361b
commit 6d160a7b7e
9 changed files with 437 additions and 90 deletions

View File

@ -31,8 +31,6 @@
#include <QDebug>
#include <FileSystem.h>
#include <DesktopServices.h>
#include <sys.h>
@ -48,7 +46,7 @@
FileLinkApp::FileLinkApp(int &argc, char **argv) : QCoreApplication(argc, argv)
FileLinkApp::FileLinkApp(int &argc, char **argv) : QCoreApplication(argc, argv), socket(new QLocalSocket(this))
{
#if defined Q_OS_WIN32
// attach the parent console
@ -81,18 +79,116 @@ FileLinkApp::FileLinkApp(int &argc, char **argv) : QCoreApplication(argc, argv)
// Commandline parsing
QCommandLineParser parser;
parser.setApplicationDescription(QObject::tr("a batch MKLINK program for windows to be useed with prismlauncher"));
parser.setApplicationDescription(QObject::tr("a batch MKLINK program for windows to be used with prismlauncher"));
parser.addOptions({
{{"s", "server"}, "Join the specified server on launch", "pipe name"}
});
parser.addHelpOption();
parser.addVersionOption();
parser.process(arguments());
QString serverToJoin = parser.value("server");
qDebug() << "link program launched";
if (!serverToJoin.isEmpty()) {
qDebug() << "joining server" << serverToJoin;
joinServer(serverToJoin);
} else {
qDebug() << "no server to join";
exit();
}
}
void FileLinkApp::joinServer(QString server)
{
blockSize = 0;
in.setDevice(&socket);
in.setVersion(QDataStream::Qt_5_15);
connect(&socket, &QLocalSocket::connected, this, [&](){
qDebug() << "connected to server";
});
connect(&socket, &QLocalSocket::readyRead, this, &FileLinkApp::readPathPairs);
connect(&socket, &QLocalSocket::errorOccurred, this, [&](QLocalSocket::LocalSocketError socketError){
switch (socketError) {
case QLocalSocket::ServerNotFoundError:
qDebug() << tr("The host was not found. Please make sure "
"that the server is running and that the "
"server name is correct.");
break;
case QLocalSocket::ConnectionRefusedError:
qDebug() << tr("The connection was refused by the peer. "
"Make sure the server is running, "
"and check that the server name "
"is correct.");
break;
case QLocalSocket::PeerClosedError:
break;
default:
qDebug() << tr("The following error occurred: %1.").arg(socket.errorString());
}
});
connect(&socket, &QLocalSocket::disconnected, this, [&](){
qDebug() << "dissconnected from server";
});
socket.connectToServer(server);
}
void FileLinkApp::runLink()
{
qDebug() << "creating link";
FS::create_link lnk(m_path_pairs);
lnk.debug(true);
if (!lnk()) {
qDebug() << "Link Failed!" << lnk.getOSError().value() << lnk.getOSError().message().c_str();
}
//exit();
qDebug() << "done, should exit";
}
void FileLinkApp::readPathPairs()
{
m_path_pairs.clear();
qDebug() << "Reading path pairs from server";
qDebug() << "bytes avalible" << socket.bytesAvailable();
if (blockSize == 0) {
// Relies on the fact that QDataStream serializes a quint32 into
// sizeof(quint32) bytes
if (socket.bytesAvailable() < (int)sizeof(quint32))
return;
qDebug() << "reading block size";
in >> blockSize;
}
qDebug() << "blocksize is" << blockSize;
qDebug() << "bytes avalible" << socket.bytesAvailable();
if (socket.bytesAvailable() < blockSize || in.atEnd())
return;
quint32 numPairs;
in >> numPairs;
qDebug() << "numPairs" << numPairs;
for(int i = 0; i < numPairs; i++) {
FS::LinkPair pair;
in >> pair.src;
in >> pair.dst;
qDebug() << "link" << pair.src << "to" << pair.dst;
m_path_pairs.append(pair);
}
runLink();
}

View File

@ -32,6 +32,11 @@
#include <QDateTime>
#include <QUrl>
#include <QDateTime>
#include <QDataStream>
#include <QLocalSocket>
#define PRISM_EXTERNAL_EXE
#include "FileSystem.h"
class FileLinkApp : public QCoreApplication
{
@ -43,7 +48,17 @@ public:
virtual ~FileLinkApp();
private:
void joinServer(QString server);
void readPathPairs();
void runLink();
QDateTime m_startTime;
QLocalSocket socket;
QDataStream in;
quint32 blockSize;
QList<FS::LinkPair> m_path_pairs;
#if defined Q_OS_WIN32
// used on Windows to attach the standard IO streams