From 8444c609936606a361dd2681a6e2356e0d5ee81c Mon Sep 17 00:00:00 2001 From: Russell Sim Date: Sun, 14 Jun 2020 09:07:27 +0200 Subject: Implement error handling --- proto-wine/ftnoir_protocol_wine.cpp | 11 ++++++++--- proto-wine/proton.cpp | 39 ++++++++++++++++++++++--------------- proto-wine/proton.h | 23 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 proto-wine/proton.h (limited to 'proto-wine') diff --git a/proto-wine/ftnoir_protocol_wine.cpp b/proto-wine/ftnoir_protocol_wine.cpp index 63308e9f..7052ea41 100644 --- a/proto-wine/ftnoir_protocol_wine.cpp +++ b/proto-wine/ftnoir_protocol_wine.cpp @@ -1,4 +1,5 @@ #include "ftnoir_protocol_wine.h" +#include "proton.h" #ifndef OTR_WINE_NO_WRAPPER # include "csv/csv.h" #endif @@ -74,9 +75,13 @@ module_status wine::initialize() QString proton_path(const QString& proton_path); wine_path = proton_path(s.proton_path().toString()); - env = make_steam_environ(s.proton_path().toString(), s.proton_appid); + try { + env = make_steam_environ(s.proton_path().toString(), s.proton_appid); + } catch(const ProtonException &e) { + return error(e.getMessage()); + } } - else + { QString wineprefix = "~/.wine"; if (!s.wineprefix->isEmpty()) @@ -85,7 +90,7 @@ module_status wine::initialize() wineprefix = qgetenv("HOME") + wineprefix.mid(1); if (wineprefix[0] != '/') - error(tr("Wine prefix must be an absolute path (given '%1')").arg(wineprefix)); + return error(tr("Wine prefix must be an absolute path (given '%1')").arg(wineprefix)); env.insert("WINEPREFIX", wineprefix); } diff --git a/proto-wine/proton.cpp b/proto-wine/proton.cpp index f2b0269e..b1eb8b9e 100644 --- a/proto-wine/proton.cpp +++ b/proto-wine/proton.cpp @@ -7,12 +7,13 @@ #ifndef OTR_WINE_NO_WRAPPER +#include "proton.h" + #include -#include -#include -#include #include #include +#include +#include static const char* steam_paths[] = { @@ -30,7 +31,14 @@ QProcessEnvironment make_steam_environ(const QString& proton_path, int appid) { auto ret = QProcessEnvironment::systemEnvironment(); QString home = qgetenv("HOME"); - QString runtime_path; + QString runtime_path, app_wineprefix; + + auto expand = [&](QString x) { + x.replace("HOME", home); + x.replace("PROTON_PATH", proton_path); + x.replace("RUNTIME_PATH", runtime_path); + return x; + }; for (const char* path : runtime_paths) { QDir dir(QDir::homePath() + path); @@ -38,12 +46,16 @@ QProcessEnvironment make_steam_environ(const QString& proton_path, int appid) runtime_path = dir.absolutePath(); } - auto expand = [&](QString x) { - x.replace("HOME", home); - x.replace("PROTON_PATH", proton_path); - x.replace("RUNTIME_PATH", runtime_path); - return x; - }; + if (runtime_path.isEmpty()) + ProtonException(QString("Couldn't find a Steam runtime.")).raise(); + + for (const char* path : steam_paths) { + QDir dir(QDir::homePath() + path + expand("/%1/pfx").arg(appid)); + if (dir.exists()) + app_wineprefix = dir.absolutePath(); + } + if (app_wineprefix.isEmpty()) + ProtonException(QString("Couldn't find a Wineprefix for AppId %1").arg(appid)).raise(); QString path = expand( ":PROTON_PATH/dist/bin" @@ -67,12 +79,7 @@ QProcessEnvironment make_steam_environ(const QString& proton_path, int appid) ); library_path += ':'; library_path += qgetenv("LD_LIBRARY_PATH"); ret.insert("LD_LIBRARY_PATH", library_path); - - for (const char* path : steam_paths) { - QDir dir(QDir::homePath() + path + expand("/%1/pfx").arg(appid)); - if (dir.exists()) - ret.insert("WINEPREFIX", dir.absolutePath()); - } + ret.insert("WINEPREFIX", app_wineprefix); return ret; } diff --git a/proto-wine/proton.h b/proto-wine/proton.h new file mode 100644 index 00000000..08179c3d --- /dev/null +++ b/proto-wine/proton.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +class ProtonException : public QException +{ +public: + ProtonException(const QString& message) + : message(message) {} + + virtual ~ProtonException() + {} + + void raise() const { throw *this; } + ProtonException *clone() const { return new ProtonException(*this); } + + QString getMessage() const { + return message; + } +private: + QString message; +}; -- cgit v1.2.3