2021-10-24 19:50:35 +00:00
|
|
|
/*
|
2022-01-06 23:38:21 +00:00
|
|
|
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
|
2021-10-24 19:50:35 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2021-10-24 02:07:56 +00:00
|
|
|
#include "UIModel.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
2021-10-25 16:00:34 +00:00
|
|
|
#include <QGuiApplication>
|
2021-10-28 09:41:27 +00:00
|
|
|
#include <QJsonDocument>
|
2021-10-25 16:00:34 +00:00
|
|
|
|
2021-10-25 20:00:20 +00:00
|
|
|
#include <WinReg/WinReg.hpp>
|
|
|
|
|
2021-10-28 09:41:27 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "UWPFetch.h"
|
2022-01-04 14:38:28 +00:00
|
|
|
#include <Windows.h>
|
2021-10-24 23:14:34 +00:00
|
|
|
#endif
|
2021-10-24 02:07:56 +00:00
|
|
|
|
2021-10-24 19:50:35 +00:00
|
|
|
UIModel::UIModel() : QObject(nullptr)
|
2021-10-24 02:07:56 +00:00
|
|
|
{
|
|
|
|
auto path = std::filesystem::temp_directory_path()
|
2021-10-28 09:41:27 +00:00
|
|
|
.parent_path()
|
|
|
|
.parent_path()
|
|
|
|
.parent_path();
|
2021-10-24 02:07:56 +00:00
|
|
|
|
|
|
|
path /= "Roaming";
|
|
|
|
path /= "GlosSI";
|
|
|
|
if (!std::filesystem::exists(path))
|
|
|
|
std::filesystem::create_directories(path);
|
|
|
|
|
|
|
|
config_path_ = path;
|
|
|
|
config_dir_name_ = (path /= "Targets").string().data();
|
2021-10-24 20:21:27 +00:00
|
|
|
|
|
|
|
if (!std::filesystem::exists(path))
|
|
|
|
std::filesystem::create_directories(path);
|
|
|
|
|
2021-10-25 20:00:20 +00:00
|
|
|
parseShortcutVDF();
|
2021-10-24 20:21:27 +00:00
|
|
|
readConfigs();
|
2021-10-24 02:07:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-24 19:50:35 +00:00
|
|
|
void UIModel::readConfigs()
|
2021-10-24 02:07:56 +00:00
|
|
|
{
|
|
|
|
QDir dir(config_dir_name_);
|
|
|
|
auto entries = dir.entryList(QDir::Files, QDir::SortFlag::Name);
|
|
|
|
entries.removeIf([](const auto& entry) {
|
2021-10-24 20:21:27 +00:00
|
|
|
return !entry.endsWith(".json");
|
2021-10-28 09:41:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
std::for_each(entries.begin(), entries.end(), [this](const auto& name) {
|
|
|
|
auto path = config_path_;
|
|
|
|
path /= config_dir_name_.toStdString();
|
2021-11-19 12:30:26 +00:00
|
|
|
path /= name.toStdWString();
|
2021-10-28 09:41:27 +00:00
|
|
|
QFile file(path);
|
|
|
|
if (!file.open(QIODevice::Text | QIODevice::ReadOnly)) {
|
|
|
|
// meh
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto data = file.readAll();
|
|
|
|
file.close();
|
|
|
|
const auto jsondoc = QJsonDocument::fromJson(data);
|
|
|
|
const auto filejson = jsondoc.object();
|
|
|
|
|
|
|
|
QJsonObject json;
|
|
|
|
json["version"] = filejson["version"];
|
|
|
|
json["icon"] = filejson["icon"];
|
|
|
|
json["launch"] = filejson["launch"]["launch"];
|
|
|
|
json["launchPath"] = filejson["launch"]["launchPath"];
|
|
|
|
json["launchAppArgs"] = filejson["launch"]["launchAppArgs"];
|
|
|
|
json["closeOnExit"] = filejson["launch"]["closeOnExit"];
|
2021-11-12 14:31:36 +00:00
|
|
|
json["waitForChildProcs"] = filejson["launch"]["waitForChildProcs"];
|
2021-10-28 09:41:27 +00:00
|
|
|
json["hideDevices"] = filejson["devices"]["hideDevices"];
|
2022-03-07 14:22:03 +00:00
|
|
|
json["realDeviceIds"] = filejson["devices"]["realDeviceIds"];
|
2021-10-28 09:41:27 +00:00
|
|
|
json["windowMode"] = filejson["window"]["windowMode"];
|
|
|
|
json["maxFps"] = filejson["window"]["maxFps"];
|
|
|
|
json["scale"] = filejson["window"]["scale"];
|
2022-03-05 15:33:12 +00:00
|
|
|
json["disableOverlay"] = filejson["window"]["disableOverlay"];
|
2022-03-14 19:13:27 +00:00
|
|
|
json["maxControllers"] = filejson["controller"]["allowDesktopConfig"];
|
|
|
|
json["allowDesktopConfig"] = filejson["controller"]["allowDesktopConfig"];
|
2021-10-28 09:41:27 +00:00
|
|
|
|
2022-01-10 16:13:56 +00:00
|
|
|
json["name"] = filejson.contains("name") ? filejson["name"] : QString(name).replace(QRegularExpression("\\.json"), "");
|
2021-10-28 09:41:27 +00:00
|
|
|
|
|
|
|
targets_.append(json.toVariantMap());
|
|
|
|
});
|
2021-10-24 19:50:35 +00:00
|
|
|
|
|
|
|
emit targetListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantList UIModel::getTargetList() const
|
|
|
|
{
|
|
|
|
return targets_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIModel::addTarget(QVariant shortcut)
|
|
|
|
{
|
2021-10-24 20:21:27 +00:00
|
|
|
const auto map = shortcut.toMap();
|
2021-10-27 18:32:41 +00:00
|
|
|
const auto json = QJsonObject::fromVariantMap(map);
|
|
|
|
writeTarget(json, map["name"].toString());
|
|
|
|
targets_.append(QJsonDocument(json).toVariant());
|
2021-10-24 19:50:35 +00:00
|
|
|
emit targetListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIModel::updateTarget(int index, QVariant shortcut)
|
|
|
|
{
|
2021-10-24 20:21:27 +00:00
|
|
|
const auto map = shortcut.toMap();
|
2021-10-27 18:32:41 +00:00
|
|
|
const auto json = QJsonObject::fromVariantMap(map);
|
2021-10-24 19:50:35 +00:00
|
|
|
|
2022-01-10 16:13:56 +00:00
|
|
|
auto oldName = targets_[index].toMap()["name"].toString().replace(QRegularExpression("[\\\\/:*?\"<>|]"), "") + ".json";
|
2021-10-24 20:27:20 +00:00
|
|
|
auto path = config_path_;
|
|
|
|
path /= config_dir_name_.toStdString();
|
|
|
|
path /= (oldName).toStdString();
|
|
|
|
std::filesystem::remove(path);
|
|
|
|
|
2021-10-27 18:32:41 +00:00
|
|
|
writeTarget(json, map["name"].toString());
|
2021-10-24 23:14:34 +00:00
|
|
|
|
2021-10-27 18:32:41 +00:00
|
|
|
targets_.replace(index, QJsonDocument(json).toVariant());
|
2021-10-24 19:50:35 +00:00
|
|
|
emit targetListChanged();
|
2021-10-24 02:07:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-24 23:14:34 +00:00
|
|
|
void UIModel::deleteTarget(int index)
|
|
|
|
{
|
2022-01-10 16:13:56 +00:00
|
|
|
auto oldName = targets_[index].toMap()["name"].toString().replace(QRegularExpression("[\\\\/:*?\"<>|]"), "") + ".json";
|
2021-10-24 23:14:34 +00:00
|
|
|
auto path = config_path_;
|
|
|
|
path /= config_dir_name_.toStdString();
|
|
|
|
path /= (oldName).toStdString();
|
|
|
|
std::filesystem::remove(path);
|
|
|
|
targets_.remove(index);
|
|
|
|
emit targetListChanged();
|
|
|
|
}
|
|
|
|
|
2021-10-27 18:32:41 +00:00
|
|
|
bool UIModel::isInSteam(QVariant shortcut)
|
|
|
|
{
|
|
|
|
const auto map = shortcut.toMap();
|
2021-10-28 09:41:27 +00:00
|
|
|
for (auto& steam_shortcut : shortcuts_vdf_.shortcuts) {
|
|
|
|
if (map["name"].toString() == QString::fromStdString(steam_shortcut.appName.value)) {
|
|
|
|
if (QString::fromStdString(steam_shortcut.exe.value).toLower().contains("glossitarget.exe")) {
|
2021-10-27 18:32:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-04 14:38:28 +00:00
|
|
|
bool UIModel::addToSteam(QVariant shortcut, const QString& shortcutspath, bool from_cmd)
|
2021-10-27 18:32:41 +00:00
|
|
|
{
|
2021-10-28 18:33:59 +00:00
|
|
|
QDir appDir = QGuiApplication::applicationDirPath();
|
2021-10-27 18:32:41 +00:00
|
|
|
const auto map = shortcut.toMap();
|
|
|
|
const auto name = map["name"].toString();
|
|
|
|
const auto maybeLaunchPath = map["launchPath"].toString();
|
|
|
|
const auto launch = map["launch"].toBool();
|
|
|
|
|
|
|
|
VDFParser::Shortcut vdfshortcut;
|
|
|
|
vdfshortcut.idx = shortcuts_vdf_.shortcuts.size();
|
|
|
|
vdfshortcut.appName.value = name.toStdString();
|
|
|
|
vdfshortcut.exe.value = ("\"" + appDir.absolutePath() + "/GlosSITarget.exe" + "\"").toStdString();
|
2021-10-28 09:41:27 +00:00
|
|
|
vdfshortcut.StartDir.value = (launch && !maybeLaunchPath.isEmpty()
|
|
|
|
? (std::string("\"") + std::filesystem::path(maybeLaunchPath.toStdString()).parent_path().string() + "\"")
|
|
|
|
: ("\"" + appDir.absolutePath() + "\"").toStdString());
|
2021-10-27 18:32:41 +00:00
|
|
|
vdfshortcut.appId.value = VDFParser::Parser::calculateAppId(vdfshortcut);
|
|
|
|
// ShortcutPath; default
|
|
|
|
vdfshortcut.LaunchOptions.value = (name + ".json").toStdString();
|
|
|
|
// IsHidden; default
|
|
|
|
// AllowDesktopConfig; default
|
|
|
|
// AllowOverlay; default
|
|
|
|
// openvr; default
|
|
|
|
// Devkit; default
|
|
|
|
// DevkitGameID; default
|
|
|
|
// DevkitOverrideAppID; default
|
|
|
|
// LastPlayTime; default
|
|
|
|
auto maybeIcon = map["icon"].toString();
|
2021-10-28 09:41:27 +00:00
|
|
|
if (maybeIcon.isEmpty()) {
|
2021-10-27 18:32:41 +00:00
|
|
|
if (launch && !maybeLaunchPath.isEmpty())
|
2021-10-28 18:33:59 +00:00
|
|
|
vdfshortcut.icon.value =
|
2022-03-05 15:27:32 +00:00
|
|
|
"\"" + (is_windows_ ? QString(maybeLaunchPath).replace(QRegularExpression("\\/"), "\\").toStdString() : maybeLaunchPath.toStdString()) + "\"";
|
2021-10-28 09:41:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-10-28 18:33:59 +00:00
|
|
|
vdfshortcut.icon.value =
|
2022-03-05 15:27:32 +00:00
|
|
|
"\"" + (is_windows_ ? QString(maybeIcon).replace(QRegularExpression("\\/"), "\\").toStdString() : maybeIcon.toStdString()) + "\"";
|
2021-10-27 18:32:41 +00:00
|
|
|
}
|
|
|
|
// Add installed locally and GlosSI tag
|
|
|
|
VDFParser::ShortcutTag locallyTag;
|
|
|
|
locallyTag.idx = 0;
|
|
|
|
locallyTag.value = "Installed locally";
|
|
|
|
vdfshortcut.tags.value.push_back(locallyTag);
|
|
|
|
|
|
|
|
VDFParser::ShortcutTag glossitag;
|
|
|
|
glossitag.idx = 1;
|
|
|
|
glossitag.value = "GlosSI";
|
|
|
|
vdfshortcut.tags.value.push_back(glossitag);
|
|
|
|
|
|
|
|
shortcuts_vdf_.shortcuts.push_back(vdfshortcut);
|
|
|
|
|
2022-01-04 14:38:28 +00:00
|
|
|
return writeShortcutsVDF(L"add", name.toStdWString(), shortcutspath.toStdWString(), from_cmd);
|
|
|
|
}
|
|
|
|
bool UIModel::addToSteam(const QString& name, const QString& shortcutspath, bool from_cmd)
|
|
|
|
{
|
|
|
|
qDebug() << "trying to add " << name << " to steam";
|
|
|
|
const auto target = std::find_if(targets_.begin(), targets_.end(), [&name](const auto& target) {
|
|
|
|
const auto map = target.toMap();
|
2022-01-10 16:13:56 +00:00
|
|
|
const auto target_name = map["name"].toString().replace(QRegularExpression("[\\\\/:*?\"<>|]"), "");
|
2022-01-04 14:38:28 +00:00
|
|
|
return name == target_name;
|
|
|
|
});
|
|
|
|
if (target != targets_.end()) {
|
|
|
|
return addToSteam(*target, shortcutspath, from_cmd);
|
|
|
|
}
|
|
|
|
qDebug() << name << " not found!";
|
|
|
|
return false;
|
2021-10-27 18:32:41 +00:00
|
|
|
}
|
2022-01-04 14:38:28 +00:00
|
|
|
bool UIModel::removeFromSteam(const QString& name, const QString& shortcutspath, bool from_cmd)
|
2021-10-27 18:32:41 +00:00
|
|
|
{
|
2022-01-04 14:38:28 +00:00
|
|
|
qDebug() << "trying to remove " << name << " from steam";
|
2021-10-27 18:32:41 +00:00
|
|
|
auto& scuts = shortcuts_vdf_.shortcuts;
|
2021-10-28 09:41:27 +00:00
|
|
|
scuts.erase(std::remove_if(scuts.begin(), scuts.end(), [&name](const auto& shortcut) {
|
|
|
|
return shortcut.appName.value == name.toStdString();
|
|
|
|
}),
|
|
|
|
scuts.end());
|
|
|
|
for (int i = 0; i < scuts.size(); i++) {
|
|
|
|
if (scuts[i].idx != i) {
|
2021-10-27 18:32:41 +00:00
|
|
|
scuts[i].idx = i;
|
|
|
|
}
|
|
|
|
}
|
2022-01-04 14:38:28 +00:00
|
|
|
return writeShortcutsVDF(L"remove", name.toStdWString(), shortcutspath.toStdWString(), from_cmd);
|
2021-10-27 18:32:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 15:51:43 +00:00
|
|
|
QVariantMap UIModel::manualProps(QVariant shortcut)
|
|
|
|
{
|
|
|
|
QDir appDir = QGuiApplication::applicationDirPath();
|
|
|
|
const auto map = shortcut.toMap();
|
2022-01-10 16:13:56 +00:00
|
|
|
const auto name = map["name"].toString().replace(QRegularExpression("[\\\\/:*?\"<>|]"), "");
|
2022-01-04 15:51:43 +00:00
|
|
|
const auto maybeLaunchPath = map["launchPath"].toString();
|
|
|
|
const auto launch = map["launch"].toBool();
|
|
|
|
|
|
|
|
QVariantMap res;
|
|
|
|
res.insert("name", name);
|
|
|
|
res.insert("config", name + ".json");
|
|
|
|
res.insert("launch", ("\"" + appDir.absolutePath() + "/GlosSITarget.exe" + "\""));
|
|
|
|
res.insert("launchDir", (
|
2022-03-05 15:27:32 +00:00
|
|
|
launch && !maybeLaunchPath.isEmpty()
|
|
|
|
? (QString("\"") + QString::fromStdString(std::filesystem::path(maybeLaunchPath.toStdString()).parent_path().string()) + "\"")
|
|
|
|
: ("\"" + appDir.absolutePath() + "\"")));
|
2022-01-04 15:51:43 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-10-24 23:14:34 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
QVariantList UIModel::uwpApps()
|
|
|
|
{
|
2021-10-28 09:41:27 +00:00
|
|
|
return UWPFetch::UWPAppList();
|
2021-10-24 23:14:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-04 14:38:28 +00:00
|
|
|
bool UIModel::writeShortcutsVDF(const std::wstring& mode, const std::wstring& name, const std::wstring& shortcutspath, bool is_admin_try) const
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
const std::filesystem::path config_path = is_admin_try
|
|
|
|
? shortcutspath
|
2022-03-05 15:27:32 +00:00
|
|
|
: std::wstring(getSteamPath()) + user_data_path_.toStdWString() + getSteamUserId() + shortcutsfile_.toStdWString();
|
2022-01-04 14:38:28 +00:00
|
|
|
|
|
|
|
qDebug() << "Steam config Path: " << config_path;
|
|
|
|
qDebug() << "Trying to write config as admin: " << is_admin_try;
|
|
|
|
|
|
|
|
auto write_res = VDFParser::Parser::writeShortcuts(config_path, shortcuts_vdf_);
|
|
|
|
|
|
|
|
if (!write_res && !is_admin_try) {
|
|
|
|
wchar_t szPath[MAX_PATH];
|
|
|
|
if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath))) {
|
|
|
|
// Launch itself as admin
|
|
|
|
SHELLEXECUTEINFO sei = {sizeof(sei)};
|
|
|
|
sei.lpVerb = L"runas";
|
|
|
|
qDebug() << QString("exepath: %1").arg(szPath);
|
|
|
|
sei.lpFile = szPath;
|
|
|
|
const std::wstring paramstr = mode + L" " + name + L" \"" + config_path.wstring() + L"\"";
|
|
|
|
sei.lpParameters = paramstr.c_str();
|
|
|
|
sei.hwnd = NULL;
|
|
|
|
sei.nShow = SW_NORMAL;
|
|
|
|
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
|
|
if (!ShellExecuteEx(&sei)) {
|
|
|
|
DWORD dwError = GetLastError();
|
|
|
|
if (dwError == ERROR_CANCELLED) {
|
|
|
|
qDebug() << "User cancelled UAC Prompt";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qDebug() << QString("HProc: %1").arg((int)sei.hProcess);
|
|
|
|
|
|
|
|
if (sei.hProcess && WAIT_OBJECT_0 == WaitForSingleObject(sei.hProcess, INFINITE)) {
|
|
|
|
DWORD exitcode = 1;
|
|
|
|
GetExitCodeProcess(sei.hProcess, &exitcode);
|
|
|
|
qDebug() << QString("Exitcode: %1").arg((int)exitcode);
|
|
|
|
if (exitcode == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-05 15:27:32 +00:00
|
|
|
}
|
2022-01-04 14:38:28 +00:00
|
|
|
}
|
|
|
|
return write_res;
|
|
|
|
#else
|
|
|
|
return VDFParser::Parser::writeShortcuts(config_path, shortcuts_vdf_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-10-24 02:07:56 +00:00
|
|
|
bool UIModel::getIsWindows() const
|
|
|
|
{
|
|
|
|
return is_windows_;
|
|
|
|
}
|
2021-10-24 10:17:38 +00:00
|
|
|
|
|
|
|
bool UIModel::hasAcrylicEffect() const
|
|
|
|
{
|
|
|
|
return has_acrylic_affect_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIModel::setAcrylicEffect(bool has_acrylic_affect)
|
|
|
|
{
|
|
|
|
has_acrylic_affect_ = has_acrylic_affect;
|
|
|
|
emit acrylicChanged();
|
|
|
|
}
|
2021-10-24 20:21:27 +00:00
|
|
|
|
2021-10-27 18:32:41 +00:00
|
|
|
void UIModel::writeTarget(const QJsonObject& json, const QString& name)
|
2021-10-24 20:21:27 +00:00
|
|
|
{
|
|
|
|
auto path = config_path_;
|
2021-11-19 12:30:26 +00:00
|
|
|
path /= config_dir_name_.toStdWString();
|
2022-01-10 16:13:56 +00:00
|
|
|
path /= (QString(name).replace(QRegularExpression("[\\\\/:*?\"<>|]"), "") + ".json").toStdWString();
|
2021-10-24 20:21:27 +00:00
|
|
|
QFile file(path);
|
2021-10-28 09:41:27 +00:00
|
|
|
if (!file.open(QIODevice::Text | QIODevice::ReadWrite)) {
|
2021-10-24 20:21:27 +00:00
|
|
|
// meh
|
|
|
|
return;
|
|
|
|
}
|
2021-10-27 18:32:41 +00:00
|
|
|
QJsonObject fileJson;
|
|
|
|
fileJson["version"] = json["version"];
|
|
|
|
fileJson["icon"] = json["icon"];
|
2022-01-10 16:13:56 +00:00
|
|
|
fileJson["name"] = json["name"];
|
2021-10-27 18:32:41 +00:00
|
|
|
|
|
|
|
QJsonObject launchObject;
|
|
|
|
launchObject["launch"] = json["launch"];
|
|
|
|
launchObject["launchPath"] = json["launchPath"];
|
|
|
|
launchObject["launchAppArgs"] = json["launchAppArgs"];
|
|
|
|
launchObject["closeOnExit"] = json["closeOnExit"];
|
2021-11-12 14:31:36 +00:00
|
|
|
launchObject["waitForChildProcs"] = json["waitForChildProcs"];
|
2021-10-27 18:32:41 +00:00
|
|
|
fileJson["launch"] = launchObject;
|
|
|
|
|
|
|
|
QJsonObject devicesObject;
|
|
|
|
devicesObject["hideDevices"] = json["hideDevices"];
|
2022-03-07 14:22:03 +00:00
|
|
|
devicesObject["realDeviceIds"] = json["realDeviceIds"];
|
2021-10-27 18:32:41 +00:00
|
|
|
fileJson["devices"] = devicesObject;
|
|
|
|
|
|
|
|
QJsonObject windowObject;
|
|
|
|
windowObject["windowMode"] = json["windowMode"];
|
|
|
|
windowObject["maxFps"] = json["maxFps"];
|
|
|
|
windowObject["scale"] = json["scale"];
|
2022-03-05 15:33:12 +00:00
|
|
|
windowObject["disableOverlay"] = json["disableOverlay"];
|
2021-10-27 18:32:41 +00:00
|
|
|
fileJson["window"] = windowObject;
|
|
|
|
|
2022-03-05 15:27:32 +00:00
|
|
|
QJsonObject controllerObject;
|
|
|
|
controllerObject["maxControllers"] = json["maxControllers"];
|
2022-03-14 19:13:27 +00:00
|
|
|
controllerObject["allowDesktopConfig"] = json["allowDesktopConfig"];
|
2022-03-05 15:27:32 +00:00
|
|
|
fileJson["controller"] = controllerObject;
|
|
|
|
|
2021-10-27 18:32:41 +00:00
|
|
|
auto wtf = QString(QJsonDocument(fileJson).toJson(QJsonDocument::Indented)).toStdString();
|
|
|
|
file.write(wtf.data());
|
2021-10-24 20:21:27 +00:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:00:20 +00:00
|
|
|
std::filesystem::path UIModel::getSteamPath() const
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
// TODO: check if keys/value exist
|
|
|
|
// steam should always be open and have written reg values...
|
2021-10-28 09:41:27 +00:00
|
|
|
winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam"};
|
2021-10-25 20:00:20 +00:00
|
|
|
const auto res = key.GetStringValue(L"SteamPath");
|
|
|
|
return res;
|
|
|
|
#else
|
2021-10-27 18:32:41 +00:00
|
|
|
return L""; // TODO LINUX
|
2021-10-25 20:00:20 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring UIModel::getSteamUserId() const
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
// TODO: check if keys/value exist
|
|
|
|
// steam should always be open and have written reg values...
|
2021-10-28 09:41:27 +00:00
|
|
|
winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam\\ActiveProcess"};
|
2021-10-25 20:00:20 +00:00
|
|
|
const auto res = std::to_wstring(key.GetDwordValue(L"ActiveUser"));
|
2022-01-04 14:38:28 +00:00
|
|
|
if (res == L"0") {
|
|
|
|
qDebug() << "Steam not open?";
|
|
|
|
}
|
2021-10-25 20:00:20 +00:00
|
|
|
return res;
|
|
|
|
#else
|
2021-10-27 18:32:41 +00:00
|
|
|
return L""; // TODO LINUX
|
2021-10-25 20:00:20 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIModel::parseShortcutVDF()
|
|
|
|
{
|
2021-10-27 18:32:41 +00:00
|
|
|
const std::filesystem::path config_path = std::wstring(getSteamPath()) + user_data_path_.toStdWString() + getSteamUserId() + shortcutsfile_.toStdWString();
|
|
|
|
shortcuts_vdf_ = VDFParser::Parser::parseShortcuts(config_path);
|
2021-10-25 20:00:20 +00:00
|
|
|
}
|