mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-13 12:12:14 +00:00
Compare commits
1 Commits
feature/op
...
feature/wi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d746deb35a |
@@ -4,7 +4,7 @@
|
||||
#include <QSaveFile>
|
||||
|
||||
namespace {
|
||||
bool load(const QString& path, RawGameOptions & contents)
|
||||
bool load(const QString& path, std::vector<GameOptionItem> &contents, int & version)
|
||||
{
|
||||
contents.clear();
|
||||
QFile file(path);
|
||||
@@ -13,6 +13,7 @@ bool load(const QString& path, RawGameOptions & contents)
|
||||
qWarning() << "Failed to read options file.";
|
||||
return false;
|
||||
}
|
||||
version = 0;
|
||||
while(!file.atEnd())
|
||||
{
|
||||
auto line = file.readLine();
|
||||
@@ -30,32 +31,32 @@ bool load(const QString& path, RawGameOptions & contents)
|
||||
qDebug() << "!!" << key << "!!";
|
||||
if(key == "version")
|
||||
{
|
||||
contents.version = value.toInt();
|
||||
version = value.toInt();
|
||||
continue;
|
||||
}
|
||||
contents.mapping[key] = value;
|
||||
contents.emplace_back(GameOptionItem{key, value});
|
||||
}
|
||||
qDebug() << "Loaded" << path << "with version:" << contents.version;
|
||||
qDebug() << "Loaded" << path << "with version:" << version;
|
||||
return true;
|
||||
}
|
||||
bool save(const QString& path, RawGameOptions& contents)
|
||||
bool save(const QString& path, std::vector<GameOptionItem> &mapping, int version)
|
||||
{
|
||||
QSaveFile out(path);
|
||||
if(!out.open(QIODevice::WriteOnly))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(contents.version != 0)
|
||||
if(version != 0)
|
||||
{
|
||||
QString versionLine = QString("version:%1\n").arg(contents.version);
|
||||
QString versionLine = QString("version:%1\n").arg(version);
|
||||
out.write(versionLine.toUtf8());
|
||||
}
|
||||
auto iter = contents.mapping.begin();
|
||||
while (iter != contents.mapping.end())
|
||||
auto iter = mapping.begin();
|
||||
while (iter != mapping.end())
|
||||
{
|
||||
out.write(iter->first.toUtf8());
|
||||
out.write(iter->key.toUtf8());
|
||||
out.write(":");
|
||||
out.write(iter->second.toUtf8());
|
||||
out.write(iter->value.toUtf8());
|
||||
out.write("\n");
|
||||
iter++;
|
||||
}
|
||||
@@ -94,7 +95,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
|
||||
int row = index.row();
|
||||
int column = index.column();
|
||||
|
||||
if (row < 0 || row >= rowCount())
|
||||
if (row < 0 || row >= int(contents.size()))
|
||||
return QVariant();
|
||||
|
||||
switch (role)
|
||||
@@ -102,11 +103,11 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
|
||||
case Qt::DisplayRole:
|
||||
if(column == 0)
|
||||
{
|
||||
return cookedOptions.items[row].id;
|
||||
return contents[row].key;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cookedOptions.items[row].default_value;
|
||||
return contents[row].value;
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
@@ -116,7 +117,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
|
||||
|
||||
int GameOptions::rowCount(const QModelIndex&) const
|
||||
{
|
||||
return cookedOptions.items.size();
|
||||
return contents.size();
|
||||
}
|
||||
|
||||
int GameOptions::columnCount(const QModelIndex&) const
|
||||
@@ -132,12 +133,12 @@ bool GameOptions::isLoaded() const
|
||||
bool GameOptions::reload()
|
||||
{
|
||||
beginResetModel();
|
||||
loaded = load(path, rawOptions);
|
||||
loaded = load(path, contents, version);
|
||||
endResetModel();
|
||||
return loaded;
|
||||
}
|
||||
|
||||
bool GameOptions::save()
|
||||
{
|
||||
return ::save(path, rawOptions);
|
||||
return ::save(path, contents, version);
|
||||
}
|
||||
|
||||
@@ -4,46 +4,12 @@
|
||||
#include <QString>
|
||||
#include <QAbstractListModel>
|
||||
|
||||
struct RawGameOptions
|
||||
{
|
||||
void clear()
|
||||
{
|
||||
version = 0;
|
||||
mapping.clear();
|
||||
}
|
||||
std::map<QString, QString> mapping;
|
||||
int version = 0;
|
||||
};
|
||||
|
||||
struct GameOptionItem
|
||||
{
|
||||
QString id;
|
||||
enum ValueType
|
||||
{
|
||||
INT,
|
||||
FLOAT,
|
||||
BOOL,
|
||||
FOV_MADNESS,
|
||||
FPS_MADNESS
|
||||
} value_type;
|
||||
enum VisualType
|
||||
{
|
||||
|
||||
} visual_type;
|
||||
QVariant null_value;
|
||||
QVariant default_value;
|
||||
QVariant min_value;
|
||||
QVariant max_value;
|
||||
QString key;
|
||||
QString value;
|
||||
};
|
||||
|
||||
struct CookedGameOptions
|
||||
{
|
||||
std::vector<GameOptionItem> items;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class GameOptions : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -61,8 +27,7 @@ public:
|
||||
bool save();
|
||||
|
||||
private:
|
||||
RawGameOptions rawOptions;
|
||||
CookedGameOptions cookedOptions;
|
||||
std::vector<GameOptionItem> contents;
|
||||
bool loaded = false;
|
||||
QString path;
|
||||
int version = 0;
|
||||
|
||||
@@ -89,6 +89,56 @@ void runGlxinfo(QStringList & log)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#include <windows.h>
|
||||
|
||||
namespace {
|
||||
void printDisplayFlags(QStringList & log, const DWORD flags, const char * spacing)
|
||||
{
|
||||
QStringList flagStrings;
|
||||
if(flags & DISPLAY_DEVICE_ACTIVE)
|
||||
{
|
||||
flags << "Active";
|
||||
}
|
||||
if(flags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
||||
{
|
||||
flags << "Primary";
|
||||
}
|
||||
if(flags & DISPLAY_DEVICE_MIRRORING_DRIVER)
|
||||
{
|
||||
flags << "Mirroring";
|
||||
}
|
||||
if(flagStrings.size())
|
||||
{
|
||||
log << QString("%1%2").arg(spacing, flagStrings.join(','));
|
||||
}
|
||||
}
|
||||
|
||||
void probeWinAPIForDevices(QStringList & log)
|
||||
{
|
||||
DISPLAY_DEVICEW dd;
|
||||
memset(&dd, 0, sizeof(DISPLAY_DEVICEW));
|
||||
int i = 0;
|
||||
|
||||
// enumerate devices
|
||||
while(EnumDisplayDevicesW(NULL, i, &dd, 0))
|
||||
{
|
||||
log << "Display devices:";
|
||||
log << QString("Device Name: %1 | Device String: %2").arg(QString::fromWCharArray(dd.DeviceName), QString::fromWCharArray(dd.DeviceString));
|
||||
printDisplayFlags(log, dd.StateFlags, " ");
|
||||
|
||||
// enumerate monitors
|
||||
if(EnumDisplayDevicesW(dd.DeviceName, 0, &dd, 0))
|
||||
{
|
||||
log << QString(" Monitor Name: %1 | Monitor String: %2").arg(QString::fromWCharArray(dd.DeviceName), QString::fromWCharArray(dd.DeviceString));
|
||||
printDisplayFlags(log, dd.StateFlags, " ");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void PrintInstanceInfo::executeTask()
|
||||
{
|
||||
auto instance = m_parent->instance();
|
||||
@@ -100,6 +150,10 @@ void PrintInstanceInfo::executeTask()
|
||||
::runGlxinfo(log);
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
::probeWinAPIForDevices(log);
|
||||
#endif
|
||||
|
||||
logLines(log, MessageLevel::MultiMC);
|
||||
logLines(instance->verboseDescription(m_session), MessageLevel::MultiMC);
|
||||
emitSucceeded();
|
||||
|
||||
Reference in New Issue
Block a user