2020-07-12 22:44:33 +02:00
|
|
|
#include "StreamerMode.hpp"
|
|
|
|
|
2020-10-11 13:52:14 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
|
|
|
|
2020-07-12 22:44:33 +02:00
|
|
|
#ifdef USEWINSDK
|
|
|
|
# include <Windows.h>
|
|
|
|
|
|
|
|
# include <VersionHelpers.h>
|
|
|
|
# include <WtsApi32.h>
|
|
|
|
# pragma comment(lib, "Wtsapi32.lib")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2020-08-22 15:27:42 +02:00
|
|
|
constexpr int cooldownInS = 10;
|
|
|
|
|
2020-07-12 22:44:33 +02:00
|
|
|
const QStringList &broadcastingBinaries()
|
|
|
|
{
|
|
|
|
#ifdef USEWINSDK
|
|
|
|
static QStringList bins = {"obs.exe", "obs64.exe"};
|
|
|
|
#else
|
|
|
|
static QStringList bins = {};
|
|
|
|
#endif
|
|
|
|
return bins;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInStreamerMode()
|
|
|
|
{
|
2020-10-11 13:52:14 +02:00
|
|
|
switch (getSettings()->enableStreamerMode.getEnum())
|
|
|
|
{
|
|
|
|
case StreamerModeSetting::Enabled:
|
|
|
|
return true;
|
|
|
|
case StreamerModeSetting::Disabled:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-12 22:44:33 +02:00
|
|
|
#ifdef USEWINSDK
|
2020-10-11 13:52:14 +02:00
|
|
|
if (!IsWindowsVistaOrGreater())
|
2020-07-12 22:44:33 +02:00
|
|
|
{
|
2020-10-11 13:52:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static bool cache = false;
|
|
|
|
static QDateTime time = QDateTime();
|
2020-08-22 15:27:42 +02:00
|
|
|
|
2020-10-11 13:52:14 +02:00
|
|
|
if (time.isValid() &&
|
|
|
|
time.addSecs(cooldownInS) > QDateTime::currentDateTime())
|
|
|
|
{
|
|
|
|
return cache;
|
|
|
|
}
|
2020-08-22 15:27:42 +02:00
|
|
|
|
2020-10-11 13:52:14 +02:00
|
|
|
time = QDateTime::currentDateTime();
|
2020-08-22 15:27:42 +02:00
|
|
|
|
2020-10-11 13:52:14 +02:00
|
|
|
WTS_PROCESS_INFO *pWPIs = nullptr;
|
|
|
|
DWORD dwProcCount = 0;
|
2020-07-12 22:44:33 +02:00
|
|
|
|
2020-10-11 13:52:14 +02:00
|
|
|
if (WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, NULL, 1, &pWPIs,
|
|
|
|
&dwProcCount))
|
|
|
|
{
|
|
|
|
//Go through all processes retrieved
|
|
|
|
for (DWORD i = 0; i < dwProcCount; i++)
|
2020-07-12 22:44:33 +02:00
|
|
|
{
|
2020-10-11 13:52:14 +02:00
|
|
|
QString processName = QString::fromUtf16(
|
|
|
|
reinterpret_cast<char16_t *>(pWPIs[i].pProcessName));
|
|
|
|
|
|
|
|
if (broadcastingBinaries().contains(processName))
|
2020-07-12 22:44:33 +02:00
|
|
|
{
|
2020-10-11 13:52:14 +02:00
|
|
|
cache = true;
|
|
|
|
return true;
|
2020-07-12 22:44:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-11 13:52:14 +02:00
|
|
|
}
|
2020-07-12 22:44:33 +02:00
|
|
|
|
2020-10-11 13:52:14 +02:00
|
|
|
if (pWPIs)
|
|
|
|
{
|
|
|
|
WTSFreeMemory(pWPIs);
|
2020-07-12 22:44:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-11 13:52:14 +02:00
|
|
|
cache = false;
|
|
|
|
#endif
|
2020-07-12 22:44:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|