aboutsummaryrefslogtreecommitdiffstats
path: root/utils/alsoft-config
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-11-20 14:22:04 -0800
committerChris Robinson <[email protected]>2019-11-20 14:22:04 -0800
commitf2eab3e919aa06b72ad467118db3269fe2571bbb (patch)
tree87a582fcd141885f27bfae61f3db37681fcc9b73 /utils/alsoft-config
parent6159b837cf1d5a2217962365db1354b2d7bad476 (diff)
Properly get the AppData path on Windows in alsoft-config
Diffstat (limited to 'utils/alsoft-config')
-rw-r--r--utils/alsoft-config/mainwindow.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp
index 7b1d8a91..fed9de59 100644
--- a/utils/alsoft-config/mainwindow.cpp
+++ b/utils/alsoft-config/mainwindow.cpp
@@ -14,6 +14,11 @@
#include "ui_mainwindow.h"
#include "verstr.h"
+#ifdef _WIN32
+#include <windows.h>
+#include <shlobj.h>
+#endif
+
namespace {
static const struct {
@@ -139,7 +144,14 @@ static QString getDefaultConfigName()
{
#ifdef Q_OS_WIN32
static const char fname[] = "alsoft.ini";
- QByteArray base = qgetenv("AppData");
+ auto get_appdata_path = []() noexcept -> QString
+ {
+ WCHAR buffer[MAX_PATH];
+ if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE)
+ return QString::fromWCharArray(buffer);
+ return QString();
+ };
+ QString base = get_appdata_path();
#else
static const char fname[] = "alsoft.conf";
QByteArray base = qgetenv("XDG_CONFIG_HOME");
@@ -158,7 +170,14 @@ static QString getDefaultConfigName()
static QString getBaseDataPath()
{
#ifdef Q_OS_WIN32
- QByteArray base = qgetenv("AppData");
+ auto get_appdata_path = []() noexcept -> QString
+ {
+ WCHAR buffer[MAX_PATH];
+ if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE)
+ return QString::fromWCharArray(buffer);
+ return QString();
+ };
+ QString base = get_appdata_path();
#else
QByteArray base = qgetenv("XDG_DATA_HOME");
if(base.isEmpty())