setting to close GloSC-SteamTarget when launched game closes

UWP_Overlay
Peter Repukat 8 years ago
parent 6eda0595e3
commit fa4a6a439d

@ -46,7 +46,6 @@ void GloSC::writeIni(QString entryName)
settings.beginGroup("BaseConf");
settings.setValue("bShowDebugConsole", 0 + ui.cbDebug->isChecked());
settings.setValue("bShowOverlay", 0 + ui.cbOverlay->isChecked());
settings.setValue("bEnableControllers", 0 + ui.cbControllers->isChecked());
@ -67,6 +66,8 @@ void GloSC::writeIni(QString entryName)
}
}
settings.setValue("bCloseWhenDone", 0 + ui.cbCloseWhenDone->isChecked());
settings.endGroup();
}
@ -239,7 +240,6 @@ void GloSC::on_lwInstances_currentRowChanged(int row)
settings.beginGroup("BaseConf");
ui.cbDebug->setChecked(settings.value("bShowDebugConsole").toBool());
ui.cbOverlay->setChecked(settings.value("bShowOverlay").toBool());
ui.cbControllers->setChecked(settings.value("bEnableControllers").toBool());
@ -253,6 +253,7 @@ void GloSC::on_lwInstances_currentRowChanged(int row)
{
ui.lePath->setText(settings.value("Path").toString());
}
ui.cbCloseWhenDone->setChecked(settings.value("bCloseWhenDone").toBool());
settings.endGroup();

@ -69,7 +69,7 @@
<property name="geometry">
<rect>
<x>40</x>
<y>281</y>
<y>231</y>
<width>261</width>
<height>20</height>
</rect>
@ -79,7 +79,7 @@
<property name="geometry">
<rect>
<x>344</x>
<y>280</y>
<y>230</y>
<width>41</width>
<height>23</height>
</rect>
@ -92,7 +92,7 @@
<property name="geometry">
<rect>
<x>300</x>
<y>280</y>
<y>230</y>
<width>41</width>
<height>23</height>
</rect>
@ -101,24 +101,11 @@
<string>...</string>
</property>
</widget>
<widget class="QCheckBox" name="cbDebug">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>121</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Show debug console</string>
</property>
</widget>
<widget class="QCheckBox" name="cbOverlay">
<property name="geometry">
<rect>
<x>10</x>
<y>110</y>
<y>70</y>
<width>111</width>
<height>17</height>
</rect>
@ -134,7 +121,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<y>100</y>
<width>151</width>
<height>17</height>
</rect>
@ -150,7 +137,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>260</y>
<y>210</y>
<width>91</width>
<height>17</height>
</rect>
@ -163,7 +150,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>281</y>
<y>231</y>
<width>31</width>
<height>20</height>
</rect>
@ -246,6 +233,20 @@
<string>Delete</string>
</property>
</widget>
<widget class="QCheckBox" name="cbCloseWhenDone">
<property name="geometry">
<rect>
<x>10</x>
<y>260</y>
<width>371</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Close shortcut when launched Application closes
(Disable for Uplay-games!)</string>
</property>
</widget>
</widget>
</widget>
</widget>

@ -37,7 +37,7 @@ GloSC_GameLauncher::GloSC_GameLauncher(QWidget *parent)
memset(sharedMemInstance.data(), NULL, 1024);
sharedMemInstance.unlock();
//connect(&qApp, SIGNAL(aboutToQuit()), this SLOT(isAboutToBeKilled()));
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(isAboutToBeKilled()));
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(checkSharedMem()));
updateTimer.setInterval(1000);
@ -56,14 +56,35 @@ void GloSC_GameLauncher::checkSharedMem()
QStringList stringList;
sharedMemInstance.lock();
buffer.setData((char*)sharedMemInstance.constData(), sharedMemInstance.size());
buffer.open(QBuffer::ReadOnly);
in >> stringList;
stringListFromShared = stringList;
memset(sharedMemInstance.data(), NULL, 1024);
sharedMemInstance.unlock();
launchGameIfRequired();
if (pid != NULL)
{
memset(sharedMemInstance.data(), NULL, 1024);
if (!IsProcessRunning(pid))
{
pid = NULL;
stringListFromShared = stringList;
stringList << "LaunchedProcessFinished";
buffer.open(QBuffer::ReadWrite);
QDataStream out(&buffer);
out << stringList;
int size = buffer.size();
char *to = (char*)sharedMemInstance.data();
const char *from = buffer.data().data();
memcpy(to, from, qMin(sharedMemInstance.size(), size));
sharedMemInstance.unlock();
}
} else {
buffer.setData((char*)sharedMemInstance.constData(), sharedMemInstance.size());
buffer.open(QBuffer::ReadOnly);
in >> stringList;
stringListFromShared = stringList;
memset(sharedMemInstance.data(), NULL, 1024);
sharedMemInstance.unlock();
launchGameIfRequired();
}
}
@ -73,25 +94,27 @@ void GloSC_GameLauncher::launchGameIfRequired()
{
if (stringListFromShared.at(0) == "LaunchWin32Game")
{
//At this point, we start detached
//Listening while an app is alive and the reporting back? Naah, too much work.
QProcess app;
if (stringListFromShared.at(1).contains("\\"))
{
app.startDetached(stringListFromShared.at(1), QStringList(), stringListFromShared.at(1).mid(0, stringListFromShared.at(1).lastIndexOf("\\")));
app.startDetached(stringListFromShared.at(1), QStringList(), stringListFromShared.at(1).mid(0, stringListFromShared.at(1).lastIndexOf("\\")), &pid);
}
else
{
app.startDetached(stringListFromShared.at(1), QStringList(), stringListFromShared.at(1).mid(0, stringListFromShared.at(1).lastIndexOf("/")));
app.startDetached(stringListFromShared.at(1), QStringList(), stringListFromShared.at(1).mid(0, stringListFromShared.at(1).lastIndexOf("/")), &pid);
}
} else if (stringListFromShared.at(0) == "LaunchUWPGame") {
//UWP Games cannot be opened twice. No further checking at this point
DWORD pid = 0;
HRESULT hr = CoInitialize(nullptr);
std::wstring appUMId = stringListFromShared.at(1).toStdWString();
if (SUCCEEDED(hr)) {
HRESULT result = LaunchUWPApp(appUMId.c_str(), &pid);
if (SUCCEEDED(result))
{
this->pid = pid;
}
}
CoUninitialize();
@ -112,8 +135,6 @@ HRESULT GloSC_GameLauncher::LaunchUWPApp(LPCWSTR packageFullName, PDWORD pdwProc
return result;
//This call causes troubles; especially with our always in foreground overlay-window
//I was way to lazy to patch the Steamtarget... Ouh well...
/*
// This call ensures that the app is launched as the foreground window
result = CoAllowSetForegroundWindow(spAppActivationManager, NULL);

@ -49,10 +49,19 @@ private:
QTimer updateTimer;
QStringList stringListFromShared;
qint64 pid = NULL;
void launchGameIfRequired();
HRESULT LaunchUWPApp(LPCWSTR packageFullName, PDWORD pdwProcessId);
bool IsProcessRunning(DWORD pid)
{
HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid);
DWORD ret = WaitForSingleObject(process, 1);
CloseHandle(process);
return ret == WAIT_TIMEOUT;
}
private slots:
void checkSharedMem();

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http ://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@ -261,6 +261,7 @@ void SteamTargetRenderer::launchApp()
{
bool launchGame = false;
bool closeWhenDone = false;
QString type = "Win32";
QString path = "";
QSettings settings(".\\TargetConfig.ini", QSettings::IniFormat);
@ -278,6 +279,9 @@ void SteamTargetRenderer::launchApp()
else if (childkey == "Path") {
path = settings.value(childkey).toString();
}
else if (childkey == "bCloseWhenDone") {
closeWhenDone = settings.value("bCloseWhenDone").toBool();
}
}
settings.endGroup();
@ -307,6 +311,42 @@ void SteamTargetRenderer::launchApp()
memcpy(to, from, qMin(sharedMemInstance.size(), size));
sharedMemInstance.unlock();
sharedMemInstance.detach();
if (closeWhenDone)
{
updateTimer.setInterval(1111);
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(checkSharedMem()));
updateTimer.start();
}
}
}
}
void SteamTargetRenderer::checkSharedMem()
{
QSharedMemory sharedMemInstance("GloSC_GameLauncher");
if (!sharedMemInstance.create(1024) && sharedMemInstance.error() == QSharedMemory::AlreadyExists)
{
QBuffer buffer;
QDataStream in(&buffer);
QStringList stringList;
sharedMemInstance.attach();
sharedMemInstance.lock();
buffer.setData((char*)sharedMemInstance.constData(), sharedMemInstance.size());
buffer.open(QBuffer::ReadOnly);
in >> stringList;
memset(sharedMemInstance.data(), NULL, 1024);
sharedMemInstance.unlock();
sharedMemInstance.detach();
if (stringList.size() > 0 && stringList.at(0) == "LaunchedProcessFinished")
{
bRunLoop = false;
renderThread.join();
if (controllerThread.isRunning())
controllerThread.stop();
exit(0);
}
}
}

@ -74,11 +74,14 @@ private:
void makeSfWindowTransparent(sf::RenderWindow& window);
void drawDebugEdges();
QTimer updateTimer;
//void openUserWindow();
private slots:
//void userWindowFinished();
void launchApp();
void checkSharedMem();
//void readChildProcess();
};

@ -1,10 +1,10 @@
[BaseConf]
bDrawDebugEdges=0
bShowDebugConsole=0
bEnableOverlay=1
bEnableControllers=1
[LaunchGame]
bLaunchGame=0
Type=Win32
Path=
Path=
bCloseWhenDone=1
Loading…
Cancel
Save