2
0
mirror of https://github.com/Thracky/GlosSI.git synced 2024-11-03 09:40:18 +00:00

Support passing command line arguments to targets (closes #6)

This also refactors target configuration storage to reduce the redundancy in copying the same set of files for every target. Each configured entry now instead uses a .ini file with the name of the entry stored in ./targets. SteamTarget can accept the path to a .ini file as a command line argument.

This also fixes the UI so that inputs are ordered the same as the visual order so that tab behavior isn't confusing.
This commit is contained in:
Kyle Herock 2017-04-19 02:13:38 -04:00
parent 0e4f9545e7
commit 5b6ca16ffc
6 changed files with 189 additions and 202 deletions

View File

@ -18,6 +18,7 @@ limitations under the License.
GloSC::GloSC(QWidget *parent)
: QMainWindow(parent)
{
QDir::setCurrent(QCoreApplication::applicationDirPath());
ui.setupUi(this);
updateEntryList();
@ -26,7 +27,7 @@ GloSC::GloSC(QWidget *parent)
//Launch the gamelauncher here, just to be safe
//Don't need to check if the process already exists as it does it itself
QProcess proc;
proc.startDetached("GloSC_Gamelauncher.exe", QStringList(), QDir::toNativeSeparators(QApplication::applicationDirPath()), nullptr);
proc.startDetached("GloSC_Gamelauncher.exe", QStringList(), QApplication::applicationDirPath(), nullptr);
}
@ -34,13 +35,13 @@ void GloSC::updateEntryList()
{
ui.lwInstances->clear();
QDir dir(".\\");
QStringList dirNames = dir.entryList(QDir::Dirs);
QDir dir("./targets");
QStringList fileNames = dir.entryList(QDir::Files);
for (auto &dirName : dirNames)
for (auto &fileName : fileNames)
{
if (dirName != "." && dirName != ".." && dirName != "platforms")
ui.lwInstances->addItem(dirName);
if (fileName.endsWith(".ini"))
ui.lwInstances->addItem(fileName.left(fileName.length() - 4));
}
@ -48,7 +49,7 @@ void GloSC::updateEntryList()
void GloSC::writeIni(QString entryName)
{
QSettings settings(entryName + "\\TargetConfig.ini", QSettings::IniFormat);
QSettings settings("./targets/" + entryName + ".ini", QSettings::IniFormat);
settings.beginGroup("BaseConf");
@ -64,16 +65,12 @@ void GloSC::writeIni(QString entryName)
settings.beginGroup("LaunchGame");
settings.setValue("bLaunchGame", 0 + ui.cbLaunchGame->isChecked());
if (ui.cbLaunchGame->isChecked())
{
settings.setValue("Path", ui.lePath->text());
if (ui.lePath->text().contains("\\") || ui.lePath->text().contains("/"))
{
settings.setValue("Type", "Win32");
} else {
settings.setValue("Type", "UWP");
}
}
settings.setValue("Path", ui.lePath->text());
settings.setValue("Args", ui.leArguments->text());
if (ui.lePath->text().contains("\\") || ui.lePath->text().contains("/"))
settings.setValue("Type", "Win32");
else
settings.setValue("Type", "UWP");
settings.setValue("bCloseWhenDone", 0 + ui.cbCloseWhenDone->isChecked());
@ -89,17 +86,13 @@ void GloSC::updateTargetsToNewVersion()
on_lwInstances_currentRowChanged(i);
QString name = ui.leName->text();
QSettings settings(name + "\\TargetConfig.ini", QSettings::IniFormat);
QSettings settings("./targets/" + name + ".ini", QSettings::IniFormat);
settings.beginGroup("BaseConf");
unsigned int version = settings.value("version").toInt();
settings.endGroup();
if (version < GLOSC_VERSION)
{
QFile file(name + "\\" + name + ".exe");
file.remove();
on_pbSave_clicked();
}
}
}
@ -165,6 +158,7 @@ void GloSC::on_pbCreateNew_clicked()
ui.cbLaunchGame->setChecked(false);
ui.lePath->setText("");
ui.leArguments->setText("");
ui.cbCloseWhenDone->setChecked(false);
animate(wide_x);
@ -182,48 +176,10 @@ void GloSC::on_pbSave_clicked()
if (temp.remove(" ") == "")
return;
QDir dir(name);
QDir dir("targets");
if (!dir.exists())
dir.mkdir(".");
#ifdef NDEBUG
QString fileNames[] = {
"Qt5Core.dll",
"Qt5Gui.dll",
"Qt5Widgets.dll",
"sfml-system-2.dll",
"sfml-window-2.dll",
"sfml-graphics-2.dll",
"ViGEmUM.dll",
"TargetConfig.ini" };
#else
QString fileNames[] = {
"Qt5Cored.dll",
"Qt5Guid.dll",
"Qt5Widgetsd.dll",
"sfml-system-d-2.dll",
"sfml-window-d-2.dll",
"sfml-graphics-d-2.dll",
"ViGEmUM.dll",
"TargetConfig.ini"
};
#endif
for (auto &fileName : fileNames)
{
QFile::copy(fileName, dir.path() + "\\" + fileName);
}
QDir platformdir(name + "\\platforms");
if (!platformdir.exists())
platformdir.mkdir(".");
QFile file(dir.path() + "\\" + name + ".exe");
file.remove();
QFile::copy("platforms\\qwindows.dll", dir.path() + "\\" + "platforms\\qwindows.dll");
QFile::copy("SteamTarget.exe", dir.path() + "\\" + name + ".exe");
writeIni(name);
updateEntryList();
@ -235,19 +191,15 @@ void GloSC::on_pbSave_clicked()
void GloSC::on_pbDelete_clicked()
{
QString name = ui.leName->text();
name.remove("\\");
name.remove("/");
name.remove(":");
name.remove(".");
QString temp = name;
if (temp.remove(" ") == "")
return;
QDir dir(name);
if (dir.exists())
QFile file("./targets/" + name + ".ini");
if (file.exists())
{
dir.removeRecursively();
file.remove();
}
updateEntryList();
@ -290,11 +242,11 @@ void GloSC::on_pbAddToSteam_clicked()
int shortcutCount = QString(temp).toInt();
QString itemName;
QString appDir = QDir::toNativeSeparators(QCoreApplication::applicationFilePath().mid(0, QCoreApplication::applicationFilePath().lastIndexOf("/")));
QDir appDir = QDir::current();
for (int i = 0; i < ui.lwInstances->count(); i++)
{
itemName = ui.lwInstances->item(i)->text();
if (!shortcutsFileBytes.contains(QString(appDir + "\\" + itemName + "\\" + itemName + ".exe").toStdString().c_str()))
if (!shortcutsFileBytes.contains(("\"" + QDir::toNativeSeparators(appDir.absoluteFilePath("SteamTarget.exe")) + "\"" + " \"./targets/" + itemName + ".ini\"").toStdString().c_str()))
{
shortcutsFileBytes.chop(2); //chop of end bytes
shortcutCount++;
@ -310,12 +262,12 @@ void GloSC::on_pbAddToSteam_clicked()
shortcutsFileBytes.append('\x01');
shortcutsFileBytes.append("exe");
shortcutsFileBytes.append('\x00');
shortcutsFileBytes.append(QString("\"" + appDir + "\\" + itemName + "\\" + itemName + ".exe\""));
shortcutsFileBytes.append("\"" + QDir::toNativeSeparators(appDir.absoluteFilePath("SteamTarget.exe")) + "\"" + " \"./targets/" + itemName + ".ini\"");
shortcutsFileBytes.append('\x00');
shortcutsFileBytes.append('\x01');
shortcutsFileBytes.append("StartDir");
shortcutsFileBytes.append('\x00');
shortcutsFileBytes.append(QString("\"" + appDir + "\\" + itemName + "\\" + "\""));
shortcutsFileBytes.append("\"" + QDir::toNativeSeparators(appDir.absolutePath()) + "\"");
shortcutsFileBytes.append('\x00');
shortcutsFileBytes.append('\x01');
shortcutsFileBytes.append("icon");
@ -376,16 +328,14 @@ void GloSC::on_pbAddToSteam_clicked()
void GloSC::on_pbSearchPath_clicked()
{
QString filePath = QFileDialog::getOpenFileName(this, "Select Game", "", "*.exe");
ui.lePath->setText(filePath);
if (filePath.length() > 0)
if (!filePath.isEmpty())
{
QString name;
if (filePath.contains("\\"))
name = filePath.mid(filePath.lastIndexOf("\\") + 1, -1);
else
name = filePath.mid(filePath.lastIndexOf("/") + 1, -1);
QFileInfo fileInfo(filePath);
ui.lePath->setText(fileInfo.filePath());
QString name = fileInfo.fileName();
name.chop(4);
ui.leName->setText(name);
ui.cbLaunchGame->setChecked(true);
}
}
@ -488,6 +438,7 @@ void GloSC::on_pbUWP_clicked()
{
ui.lePath->setText(uwpPairs.at(selection).AppUMId);
ui.leName->setText(uwpPairs.at(selection).AppName);
ui.cbLaunchGame->setChecked(true);
}
}
@ -499,7 +450,7 @@ void GloSC::on_lwInstances_currentRowChanged(int row)
QString entryName = ui.lwInstances->item(row)->text();
ui.leName->setText(entryName);
QSettings settings(entryName + "\\TargetConfig.ini", QSettings::IniFormat);
QSettings settings("./targets/" + entryName + ".ini", QSettings::IniFormat);
settings.beginGroup("BaseConf");
@ -523,10 +474,8 @@ void GloSC::on_lwInstances_currentRowChanged(int row)
settings.beginGroup("LaunchGame");
ui.cbLaunchGame->setChecked(settings.value("bLaunchGame").toBool());
if (ui.cbLaunchGame->isChecked())
{
ui.lePath->setText(settings.value("Path").toString());
}
ui.lePath->setText(settings.value("Path").toString());
ui.leArguments->setText(settings.value("Args").toString());
ui.cbCloseWhenDone->setChecked(settings.value("bCloseWhenDone").toBool());
settings.endGroup();

View File

@ -103,41 +103,28 @@
<property name="title">
<string>Config</string>
</property>
<widget class="QLineEdit" name="lePath">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>
<y>251</y>
<width>261</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pbUWP">
<property name="geometry">
<rect>
<x>344</x>
<y>250</y>
<x>10</x>
<y>29</y>
<width>41</width>
<height>23</height>
<height>21</height>
</rect>
</property>
<property name="text">
<string>UWP</string>
<string>Name: </string>
</property>
</widget>
<widget class="QPushButton" name="pbSearchPath">
<widget class="QLineEdit" name="leName">
<property name="geometry">
<rect>
<x>300</x>
<y>250</y>
<width>41</width>
<height>23</height>
<x>50</x>
<y>29</y>
<width>331</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
<widget class="QCheckBox" name="cbOverlay">
<property name="geometry">
@ -171,11 +158,42 @@
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="cbUseDesktop">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Use Desktop-Config
Disables hooking, per application bindings won't work</string>
</property>
</widget>
<widget class="QCheckBox" name="cbHookSteam">
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Hook Steam
Enforces bindings reliably by hooking into Steam</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="cbLaunchGame">
<property name="geometry">
<rect>
<x>10</x>
<y>230</y>
<y>210</y>
<width>371</width>
<height>17</height>
</rect>
@ -184,11 +202,11 @@
<string>Launch game</string>
</property>
</widget>
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>251</y>
<y>231</y>
<width>31</width>
<height>20</height>
</rect>
@ -197,6 +215,79 @@
<string>Path: </string>
</property>
</widget>
<widget class="QLineEdit" name="lePath">
<property name="geometry">
<rect>
<x>40</x>
<y>231</y>
<width>271</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pbSearchPath">
<property name="geometry">
<rect>
<x>310</x>
<y>230</y>
<width>31</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
<widget class="QPushButton" name="pbUWP">
<property name="geometry">
<rect>
<x>340</x>
<y>230</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>UWP</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>255</y>
<width>61</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Arguments: </string>
</property>
</widget>
<widget class="QLineEdit" name="leArguments">
<property name="geometry">
<rect>
<x>70</x>
<y>255</y>
<width>310</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="cbCloseWhenDone">
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Close shortcut when launched Application closes
(Disable for Uplay-games!)</string>
</property>
</widget>
<widget class="QPushButton" name="pbSave">
<property name="geometry">
<rect>
@ -213,29 +304,6 @@
<string>Save</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>33</y>
<width>47</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>Name: </string>
</property>
</widget>
<widget class="QLineEdit" name="leName">
<property name="geometry">
<rect>
<x>50</x>
<y>30</y>
<width>331</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pbDelete">
<property name="geometry">
<rect>
@ -249,51 +317,6 @@
<string>Delete</string>
</property>
</widget>
<widget class="QCheckBox" name="cbCloseWhenDone">
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Close shortcut when launched Application closes
(Disable for Uplay-games!)</string>
</property>
</widget>
<widget class="QCheckBox" name="cbHookSteam">
<property name="geometry">
<rect>
<x>10</x>
<y>170</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Hook Steam
Enforces bindings reliably by hooking into Steam</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="cbUseDesktop">
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Use Desktop-Config
Disables hooking, per application bindings won't work</string>
</property>
</widget>
</widget>
</widget>
</widget>

View File

@ -75,7 +75,18 @@ void GloSC_GameLauncher::checkSharedMem()
{
if (stringList.at(i + 1) != "" && stringList.at(i + 2) != "")
{
launchGame(stringList.at(i + 1), stringList.at(i + 2));
QStringList args;
QRegularExpression re("([^\\s\"']+)|\"([^\"]*)\"|'([^']*)'");
QRegularExpressionMatchIterator ri = re.globalMatch(stringList.at(i + 3));
while (ri.hasNext())
{
QRegularExpressionMatch match = ri.next();
int mi = 1;
while (match.captured(mi).isEmpty())
mi++;
args += match.captured(mi);
}
launchGame(stringList.at(i + 1), stringList.at(i + 2), args);
stringList = defaultSharedMemData;
}
}
@ -117,7 +128,7 @@ void GloSC_GameLauncher::checkSharedMem()
}
}
void GloSC_GameLauncher::launchGame(QString type, QString path)
void GloSC_GameLauncher::launchGame(QString type, QString path, QStringList args)
{
if (type == LGT_Win32)
@ -125,11 +136,11 @@ void GloSC_GameLauncher::launchGame(QString type, QString path)
QProcess app;
if (path.contains("\\"))
{
app.startDetached(path, QStringList(), path.mid(0, path.lastIndexOf("\\")), &pid);
app.startDetached(path, args, path.mid(0, path.lastIndexOf("\\")), &pid);
}
else
{
app.startDetached(path, QStringList(), path.mid(0, path.lastIndexOf("/")), &pid);
app.startDetached(path, args, path.mid(0, path.lastIndexOf("/")), &pid);
}
} else if (type == LGT_UWP) {

View File

@ -28,6 +28,7 @@ limitations under the License.
#include <QTimer>
#include <QSharedmemory>
#include <QRegularExpression>
#include <QBuffer>
#include <qprocess.h>
@ -36,16 +37,16 @@ limitations under the License.
class GloSC_GameLauncher : public QMainWindow
{
Q_OBJECT
Q_OBJECT
public:
GloSC_GameLauncher(QWidget *parent = Q_NULLPTR);
GloSC_GameLauncher(QWidget *parent = Q_NULLPTR);
public slots:
void isAboutToBeKilled();
private:
Ui::GloSC_GameLauncherClass ui;
Ui::GloSC_GameLauncherClass ui;
const QString LaunchGame = "LaunchGame";
const QString LGT_UWP = "UWP";
@ -56,6 +57,7 @@ private:
<< LaunchGame
<< ""
<< ""
<< ""
<< LaunchedProcessFinished
<< "0"
<< IsSteamHooked
@ -70,7 +72,7 @@ private:
bool bHookedSteam = false;
void launchGame(QString type, QString path);
void launchGame(QString type, QString path, QStringList args);
HRESULT LaunchUWPApp(LPCWSTR packageFullName, PDWORD pdwProcessId);

View File

@ -26,7 +26,12 @@ SteamTargetRenderer::SteamTargetRenderer(int& argc, char** argv) : QApplication(
loadLogo();
SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(ConsoleCtrlCallback), true);
QSettings settings(".\\TargetConfig.ini", QSettings::IniFormat);
if (this->arguments().size() == 1)
{
std::cerr << "Target configuration file must be specified" << std::endl;
QApplication::exit(1);
}
QSettings settings(this->arguments().at(1), QSettings::IniFormat);
settings.beginGroup("BaseConf");
const QStringList childKeys = settings.childKeys();
for (auto &childkey : childKeys)
@ -38,7 +43,7 @@ SteamTargetRenderer::SteamTargetRenderer(int& argc, char** argv) : QApplication(
bDrawOverlay = settings.value(childkey).toBool();
} else if (childkey == "bEnableControllers") {
bEnableControllers = settings.value(childkey).toBool();
}else if (childkey == "bHookSteam") {
} else if (childkey == "bHookSteam") {
bHookSteam = settings.value(childkey).toBool();
}
else if (childkey == "bUseDesktopConfig") {
@ -126,11 +131,9 @@ void SteamTargetRenderer::RunSfWindowLoop()
bool focusSwitchNeeded = true;
if (bDrawOverlay)
{
SetWindowPos(sfWindow.getSystemHandle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_ASYNCWINDOWPOS);
} else {
else
ShowWindow(consoleHwnd, SW_SHOW);
}
while (sfWindow.isOpen() && bRunLoop)
@ -287,7 +290,7 @@ void SteamTargetRenderer::hookBindings()
QProcess proc;
proc.setNativeArguments(" --inject ");
proc.setWorkingDirectory(dir);
proc.start("..\\Injector.exe", QIODevice::ReadOnly);
proc.start("./Injector.exe", QIODevice::ReadOnly);
proc.waitForStarted();
proc.waitForFinished();
@ -402,24 +405,22 @@ void SteamTargetRenderer::launchApp()
bool closeWhenDone = false;
QString type = "Win32";
QString path = "";
QSettings settings(".\\TargetConfig.ini", QSettings::IniFormat);
QString args;
QSettings settings(this->arguments().at(1), QSettings::IniFormat);
settings.beginGroup("LaunchGame");
const QStringList childKeys = settings.childKeys();
for (auto &childkey : childKeys)
{
if (childkey == "bLaunchGame")
{
launchGame = settings.value(childkey).toBool();
}
else if (childkey == "Type") {
else if (childkey == "Type")
type = settings.value(childkey).toString();
}
else if (childkey == "Path") {
else if (childkey == "Path")
path = settings.value(childkey).toString();
}
else if (childkey == "bCloseWhenDone") {
else if (childkey == "Args")
args = settings.value(childkey).toString();
else if (childkey == "bCloseWhenDone")
closeWhenDone = settings.value("bCloseWhenDone").toBool();
}
}
settings.endGroup();
@ -445,7 +446,7 @@ void SteamTargetRenderer::launchApp()
int lgt_index = stringList.indexOf(LaunchGame);
stringList.replace(lgt_index + 1, type);
stringList.replace(lgt_index + 2, path);
stringList.replace(lgt_index + 3, args);
buffer.open(QBuffer::ReadWrite);

View File

@ -10,4 +10,5 @@ version=288
bLaunchGame=0
Type=Win32
Path=
Args=
bCloseWhenDone=1