From 9b98e0a2f5b28279fa4cbe37be44f4866360a17d Mon Sep 17 00:00:00 2001 From: xiphon Date: Thu, 23 Apr 2020 14:19:20 +0000 Subject: checkUpates: installer support (Win), use GUI buildTag and version --- src/main/oshelper.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/main/oshelper.h | 5 +++++ 2 files changed, 50 insertions(+) (limited to 'src/main') diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp index 75c668f5..c4923f35 100644 --- a/src/main/oshelper.cpp +++ b/src/main/oshelper.cpp @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "oshelper.h" +#include #include #include #include @@ -164,3 +165,47 @@ QString OSHelper::temporaryPath() const { return QDir::tempPath(); } + +bool OSHelper::installed() const +{ +#ifdef Q_OS_WIN + static constexpr const wchar_t installKey[] = + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Monero GUI Wallet_is1"; + static constexpr const wchar_t installValue[] = L"InstallLocation"; + + DWORD size; + LSTATUS status = + ::RegGetValueW(HKEY_LOCAL_MACHINE, installKey, installValue, RRF_RT_REG_SZ, nullptr, nullptr, &size); + if (status == ERROR_FILE_NOT_FOUND) + { + return false; + } + if (status != ERROR_SUCCESS) + { + qCritical() << "RegGetValueW failed (get size)" << status; + return false; + } + + std::wstring installLocation; + installLocation.resize(size / sizeof(std::wstring::value_type)); + size = installLocation.size() * sizeof(std::wstring::value_type); + status = ::RegGetValueW( + HKEY_LOCAL_MACHINE, + installKey, + installValue, + RRF_RT_REG_SZ, + nullptr, + &installLocation[0], + &size); + if (status != ERROR_SUCCESS) + { + qCritical() << "RegGetValueW Failed (read)" << status; + return false; + } + + const QDir installDir(QString(reinterpret_cast(&installLocation[0]))); + return installDir == QDir(QCoreApplication::applicationDirPath()); +#else + return false; +#endif +} diff --git a/src/main/oshelper.h b/src/main/oshelper.h index ba498554..f3bc4c04 100644 --- a/src/main/oshelper.h +++ b/src/main/oshelper.h @@ -36,6 +36,8 @@ class OSHelper : public QObject { Q_OBJECT + Q_PROPERTY(bool installed READ installed CONSTANT); + public: explicit OSHelper(QObject *parent = 0); @@ -47,6 +49,9 @@ public: Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const; Q_INVOKABLE bool isCapsLock() const; +private: + bool installed() const; + signals: public slots: -- cgit v1.2.3