Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34123837
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
11 KB
Subscribers
None
View Options
diff --git a/src/gpgolconfig/gpgolconfig.cpp b/src/gpgolconfig/gpgolconfig.cpp
index 17dd7bd..e22ee8a 100644
--- a/src/gpgolconfig/gpgolconfig.cpp
+++ b/src/gpgolconfig/gpgolconfig.cpp
@@ -1,118 +1,116 @@
/* Copyright (C) 2018 by Intevation GmbH <info@intevation.de>
*
* This file is Free Software under the GNU GPL (v>=2)
* and comes with ABSOLUTELY NO WARRANTY!
* See LICENSE.txt for details.
*/
#include "gpgolconfig.h"
#include "w32-gettext.h"
#include "w32-util.h"
#include "gpgolconfigpage.h"
#include "gpgoldebugpage.h"
#include "cryptoconfigpage.h"
#include <QLabel>
#include <QWidget>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QCommandLineParser>
#include <QDebug>
#include <KPageDialog>
#include <KGuiItem>
#include <KStandardGuiItem>
GpgOLConfig::GpgOLConfig(const QCommandLineParser &parser):
KPageDialog(nullptr)
{
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
setWindowTitle(_("Configure GpgOL"));
setWindowIcon(QIcon(":/gpgol-icon.svg"));
const auto hwnd = parser.value(QStringLiteral("hwnd"));
if (!hwnd.isEmpty()) {
bool ok;
WId id = (WId) hwnd.toInt(&ok);
if (!ok) {
qDebug() << "invalid hwnd value";
} else {
W32::setupForeignParent(id, this, true);
setModal(true);
}
}
if (parser.isSet("gpgol-version")) {
mVersion = parser.value("gpgol-version");
} else {
mVersion = QStringLiteral("unknown version");
}
- W32::setW64RegistryMode(parser.isSet("w64"));
-
setupGUI();
resize(800, 500);
}
void GpgOLConfig::setupGUI()
{
setFaceType(KPageDialog::List);
QDialogButtonBox *buttonBox = new QDialogButtonBox();
buttonBox->setStandardButtons(QDialogButtonBox::RestoreDefaults |
QDialogButtonBox::Cancel |
QDialogButtonBox::Ok);
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
KGuiItem::assign(buttonBox->button(QDialogButtonBox::RestoreDefaults),
KStandardGuiItem::defaults());
setButtonBox(buttonBox);
auto cryptoConfWidget = new CryptoConfigPage;
auto gpgolConfWidget = new GpgOLConfigPage;
auto gpgolDbgWidget = new GpgOLDebugPage;
connect(buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked,
this, [this, cryptoConfWidget, gpgolConfWidget, gpgolDbgWidget] () {
cryptoConfWidget->save();
gpgolConfWidget->save();
gpgolDbgWidget->save();
close();
});
connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked,
this, [this, cryptoConfWidget, gpgolConfWidget, gpgolDbgWidget] () {
if (currentPage()->widget() == cryptoConfWidget) {
cryptoConfWidget->defaults();
} else if (currentPage()->widget() == gpgolConfWidget){
gpgolConfWidget->defaults();
} else if (currentPage()->widget() == gpgolDbgWidget){
gpgolDbgWidget->defaults();
}
});
connect(buttonBox->button(QDialogButtonBox::Cancel), &QAbstractButton::clicked,
this, [this] () {
close();
});
KPageWidgetItem *page = new KPageWidgetItem(gpgolConfWidget, _("GpgOL"));
page->setHeader(QStringLiteral("%1 - %2%3").arg(_("Configure GpgOL")).arg(
_("Version ")).arg(mVersion));
page->setIcon(QIcon(":/gpgol-icon.svg"));
addPage(page);
page = new KPageWidgetItem(cryptoConfWidget, QStringLiteral("%1\n%2").arg(_("GnuPG System")).arg(_("(Technical)")));
page->setHeader(_("Configuration of GnuPG System options"));
page->setIcon(QIcon::fromTheme("document-encrypt"));
addPage(page);
page = new KPageWidgetItem(gpgolDbgWidget, _("Debug"));
page->setHeader(_("Configuration of debug options"));
page->setIcon(QIcon::fromTheme("tools-report-bug"));
addPage(page);
}
diff --git a/src/util/w32-util.cpp b/src/util/w32-util.cpp
index 2a1a02b..2744511 100644
--- a/src/util/w32-util.cpp
+++ b/src/util/w32-util.cpp
@@ -1,229 +1,230 @@
/* Copyright (C) 2018 by Intevation GmbH <info@intevation.de>
*
* This file is Free Software under the GNU GPL (v>=2)
* and comes with ABSOLUTELY NO WARRANTY!
* See LICENSE.txt for details.
*/
#include <stdio.h>
#include "w32-util.h"
#include <unistd.h>
#ifdef _WIN32
# include <windows.h>
#endif
#include <QWindow>
+#include <QDebug>
#define SLDIR "\\share\\locale"
namespace W32 {
static bool s_use_w64_registry;
std::string getGpg4winLocaleDir()
{
const auto instdir = getGpg4winDir();
if (instdir.empty()) {
return std::string();
}
return instdir + SLDIR;
}
std::string getGpg4winDir()
{
const auto tmp = readRegStr(nullptr, GPG4WIN_REGKEY_3,
"Install Directory");
if (tmp.empty()) {
return std::string();
}
if (!access(tmp.c_str(), R_OK)) {
return tmp;
} else {
fprintf (stderr, "Failed to access: %s\n", tmp.c_str());
}
return std::string();
}
/* Helper for read_w32_registry_string(). */
#ifdef _WIN32
static HKEY
get_root_key(const char *root)
{
HKEY root_key;
if( !root )
root_key = HKEY_CURRENT_USER;
else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) )
root_key = HKEY_CLASSES_ROOT;
else if( !strcmp( root, "HKEY_CURRENT_USER" ) )
root_key = HKEY_CURRENT_USER;
else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) )
root_key = HKEY_LOCAL_MACHINE;
else if( !strcmp( root, "HKEY_USERS" ) )
root_key = HKEY_USERS;
else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) )
root_key = HKEY_PERFORMANCE_DATA;
else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) )
root_key = HKEY_CURRENT_CONFIG;
else
return nullptr;
return root_key;
}
#endif
+#if defined(_WIN64)
+#define CROSS_ACCESS KEY_WOW64_32KEY
+#else
+#define CROSS_ACCESS KEY_WOW64_64KEY
+#endif
+
std::string
-readRegStr (const char *root, const char *dir, const char *name)
+_readRegStr (HKEY root_key, const char *dir,
+ const char *name, bool alternate)
{
#ifndef _WIN32
- (void)root; (void)dir; (void)name;
+ (void) root_key; (void)alternate; (void)dir; (void)name;
return std::string();
#else
-
- HKEY root_key, key_handle;
+ HKEY key_handle;
DWORD n1, nbytes, type;
std::string ret;
- if (!(root_key = get_root_key(root))) {
- return ret;
- }
-
DWORD flags = KEY_READ;
- if (s_use_w64_registry) {
- flags |= KEY_WOW64_64KEY;
- } else {
- flags |= KEY_WOW64_32KEY;
+ if (alternate) {
+ flags |= CROSS_ACCESS;
}
if (RegOpenKeyExA(root_key, dir, 0, flags, &key_handle)) {
- if (root) {
- /* no need for a RegClose, so return direct */
- return ret;
- }
- /* Fallback to HKLM */
-
- if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, dir, 0, flags, &key_handle)) {
- return ret;
- }
+ return ret;
}
nbytes = 1;
if (RegQueryValueExA(key_handle, name, 0, nullptr, nullptr, &nbytes)) {
- if (root) {
- RegCloseKey (key_handle);
- return ret;
- }
- /* Try to fallback to HKLM also vor a missing value. */
RegCloseKey (key_handle);
- if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, dir, 0, flags, &key_handle)) {
- return ret;
- }
- if (RegQueryValueExA(key_handle, name, 0, nullptr, nullptr, &nbytes)) {
- RegCloseKey(key_handle);
- return ret;
- }
+ return ret;
}
n1 = nbytes+1;
char result[n1];
if (RegQueryValueExA(key_handle, name, 0, &type, (LPBYTE)result, &n1)) {
RegCloseKey(key_handle);
return ret;
}
RegCloseKey(key_handle);
result[nbytes] = 0; /* make sure it is really a string */
ret = result;
if (type == REG_EXPAND_SZ && strchr (result, '%')) {
n1 += 1000;
char tmp[n1 +1];
nbytes = ExpandEnvironmentStringsA(ret.c_str(), tmp, n1);
if (nbytes && nbytes > n1) {
n1 = nbytes;
char tmp2[n1 +1];
nbytes = ExpandEnvironmentStringsA(result, tmp2, n1);
if (nbytes && nbytes > n1) {
/* oops - truncated, better don't expand at all */
return ret;
}
tmp2[nbytes] = 0;
ret = tmp2;
} else if (nbytes) { /* okay, reduce the length */
tmp[nbytes] = 0;
ret = tmp;
}
}
return ret;
+
+#endif
+}
+
+std::string
+readRegStr (const char *root, const char *dir, const char *name)
+{
+#ifndef _WIN32
+ (void)root; (void)dir; (void)name;
+ return std::string();
+#else
+ HKEY root_key;
+ std::string ret;
+ if (!(root_key = get_root_key(root))) {
+ return ret;
+ }
+ ret = _readRegStr (root_key, dir, name, false);
+
+ if (ret.empty()) {
+ // Try local machine as fallback.
+ qDebug() << "Fallback to HKLM for" << dir << name;
+ ret = _readRegStr (HKEY_LOCAL_MACHINE, dir, name, false);
+ if (ret.empty()) {
+ // Try alternative registry view as fallback
+ qDebug() << "Fallback to HKLM alternative for" << dir << name;
+ ret = _readRegStr (HKEY_LOCAL_MACHINE, dir, name, true);
+ }
+ }
+ qDebug() << "Returning:" << (ret.empty() ? "empty" : ret.c_str());
+ return ret;
#endif
}
bool writeRegStr(const char *root, const char *path, const char *key,
const char *val)
{
#ifndef _WIN32
(void) root; (void) path; (void) key; (void) val;
return false;
#else
HKEY h, hk;
int type;
int ec;
hk = get_root_key (root);
if (!hk) {
fprintf(stderr, "Failed to find root key.\n");
}
DWORD flags = KEY_ALL_ACCESS;
- if (s_use_w64_registry) {
- flags |= KEY_WOW64_64KEY;
- } else {
- flags |= KEY_WOW64_32KEY;
- }
-
ec = RegCreateKeyExA(hk, path, 0, NULL, REG_OPTION_NON_VOLATILE,
flags, NULL, &h, NULL);
if (ec != ERROR_SUCCESS)
{
fprintf (stderr, "creating/opening registry key `%s' failed\n", path);
return false;
}
type = strchr (val, '%')? REG_EXPAND_SZ : REG_SZ;
ec = RegSetValueExA(h, key, 0, type, (const BYTE*)val, strlen (val));
if (ec != ERROR_SUCCESS)
{
fprintf (stderr, "saving registry key `%s'->`%s' failed\n", path, key);
RegCloseKey(h);
return false;
}
RegCloseKey(h);
return true;
#endif
}
void setupForeignParent(WId id, QWidget *widget, bool modal)
{
if (!widget || !id) {
return;
}
auto foreignWindow = QWindow::fromWinId(id);
widget->winId();
auto parentHandle = widget->windowHandle();
if (parentHandle && foreignWindow) {
parentHandle->setTransientParent(foreignWindow);
if (modal) {
widget->setWindowModality(Qt::WindowModal);
}
}
}
-
-void setW64RegistryMode (bool value)
-{
- s_use_w64_registry = value;
-}
}// namespace
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Dec 7, 12:00 AM (1 d, 5 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8b/79/f9f78497764d2cf4d9fae65e7201
Attached To
rGTO Gpg4win-Tools
Event Timeline
Log In to Comment