Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34070498
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
13 KB
Subscribers
None
View Options
diff --git a/src/gpgolconfig/gpgolconfig-options.h b/src/gpgolconfig/gpgolconfig-options.h
index 645c1bb..6cf371f 100644
--- a/src/gpgolconfig/gpgolconfig-options.h
+++ b/src/gpgolconfig/gpgolconfig-options.h
@@ -1,39 +1,41 @@
#ifndef GPGOLCONFIG_OPTIONS
#define GPGOLCONFIG_OPTIONS
/* 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 <QCommandLineParser>
#include <QList>
/** @file Commandline options*/
static void options(QCommandLineParser &parser)
{
QList<QCommandLineOption> options;
options
<< QCommandLineOption(QStringList() << QStringLiteral("debug"),
QStringLiteral("Print debug output."))
+ << QCommandLineOption(QStringList() << QStringLiteral("w64"),
+ QStringLiteral("GpgOL is a 64bit application."))
<< QCommandLineOption(QStringLiteral("hwnd"),
QStringLiteral("Parent Window"),
QStringLiteral("windows window handle"))
<< QCommandLineOption(QStringLiteral("lang"),
QStringLiteral("Language"),
QStringLiteral("Language to be used e.g. de_DE"))
<< QCommandLineOption(QStringLiteral("gpgol-version"),
QStringLiteral("Version string"),
QStringLiteral("GpgOL's Version"))
<< QCommandLineOption(QStringLiteral("alwaysShow"),
QStringLiteral("Should always be shown"));
for (const auto &opt: options) {
parser.addOption(opt);
}
parser.addVersionOption();
parser.addHelpOption();
}
#endif
diff --git a/src/gpgolconfig/gpgolconfig.cpp b/src/gpgolconfig/gpgolconfig.cpp
index e22ee8a..17dd7bd 100644
--- a/src/gpgolconfig/gpgolconfig.cpp
+++ b/src/gpgolconfig/gpgolconfig.cpp
@@ -1,116 +1,118 @@
/* 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 a0814a3..2a1a02b 100644
--- a/src/util/w32-util.cpp
+++ b/src/util/w32-util.cpp
@@ -1,204 +1,229 @@
/* 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>
#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
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, key_handle;
DWORD n1, nbytes, type;
std::string ret;
if (!(root_key = get_root_key(root))) {
return ret;
}
- if (RegOpenKeyExA(root_key, dir, 0, KEY_READ, &key_handle)) {
+ DWORD flags = KEY_READ;
+
+ if (s_use_w64_registry) {
+ flags |= KEY_WOW64_64KEY;
+ } else {
+ flags |= KEY_WOW64_32KEY;
+ }
+
+ 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, KEY_READ, &key_handle)) {
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, dir, 0, flags, &key_handle)) {
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, KEY_READ, &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;
}
}
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
}
-bool writeRegStr(const char *root, const char *path, const char *key, const char *val)
+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,
- KEY_ALL_ACCESS, NULL, &h, NULL);
+ 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
diff --git a/src/util/w32-util.h b/src/util/w32-util.h
index 3dd2eed..02d47bc 100644
--- a/src/util/w32-util.h
+++ b/src/util/w32-util.h
@@ -1,56 +1,59 @@
/* 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 <string>
#include <QWidget>
/* The Registry key used by Gpg4win. */
#ifdef _WIN64
# define GPG4WIN_REGKEY_2 "Software\\Wow6432Node\\GNU\\GnuPG"
#else
# define GPG4WIN_REGKEY_2 "Software\\GNU\\GnuPG"
#endif
#ifdef _WIN64
# define GPG4WIN_REGKEY_3 "Software\\Wow6432Node\\Gpg4win"
#else
# define GPG4WIN_REGKEY_3 "Software\\Gpg4win"
#endif
#define GPGOL_REG_PATH "Software\\GNU\\GpgOL"
namespace W32
{
/* Get the locale dir of Gpg4win. */
std::string getGpg4winLocaleDir();
/** Get the Gpg4win Install directory.
*
* Looks for the Gpg4win 3.x registry key.
* And checks that the directory can be read.
*
* @returns an empty string if no dir could be found.
*
**/
std::string getGpg4winDir();
/** Read a registry string value. If root is null first
* HKEY_CURRENT_USER is searched and then it falls back
* to HKEY_LOCAL_MACHINE . */
std::string readRegStr(const char *root,
const char *path,
const char *key);
bool writeRegStr(const char *root,
const char *path,
const char *key,
const char *val);
void setupForeignParent(WId id, QWidget *widget, bool modal);
+/** Call this to switch to the W64 registry. */
+void setW64RegistryMode(bool value);
+
} // namespace W32
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Dec 1, 10:20 PM (1 d, 22 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
28/52/01974e10413d57aff4af67f9e3e5
Attached To
rGTO Gpg4win-Tools
Event Timeline
Log In to Comment