Page MenuHome GnuPG

No OneTemporary

diff --git a/src/util/w32-util.cpp b/src/util/w32-util.cpp
index 2744511..b93afaa 100644
--- a/src/util/w32-util.cpp
+++ b/src/util/w32-util.cpp
@@ -1,230 +1,234 @@
/* 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
+#define REAL_ACCESS KEY_WOW64_64KEY
#else
#define CROSS_ACCESS KEY_WOW64_64KEY
+#define REAL_ACCESS KEY_WOW32_64KEY
#endif
std::string
_readRegStr (HKEY root_key, const char *dir,
const char *name, bool alternate)
{
#ifndef _WIN32
(void) root_key; (void)alternate; (void)dir; (void)name;
return std::string();
#else
HKEY key_handle;
DWORD n1, nbytes, type;
std::string ret;
DWORD flags = KEY_READ;
if (alternate) {
flags |= CROSS_ACCESS;
+ } else {
+ flags |= REAL_ACCESS;
}
if (RegOpenKeyExA(root_key, dir, 0, flags, &key_handle)) {
return ret;
}
nbytes = 1;
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
}
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;
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);
}
}
}
}// namespace

File Metadata

Mime Type
text/x-diff
Expires
Sat, Dec 6, 11:49 PM (1 d, 10 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d7/d2/8a70f2e4a1d71569dd0f004fa940

Event Timeline