-- API Brief (how it would be used) --
_watch_all = RegistryWatcher(HKEY_LOCAL_MACHINE, "Software/Microsoft/Windows-NT/CurrentVersion/Fonts", [=]() {
... My font refresh code ...
});
_watch_user = RegistryWatcher(HKEY_CURRENT_USER, "Software/Microsoft/Windows-NT/CurrentVersion/Fonts", [=]() {
... My font refresh code ...
});
-- CPP FILE BEGINS --
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Monitor the windows registry for changes and other windows registry utilities.
*
* Authors:
* Martin Owens <doctormo@geek-2.com>
*
* The contents of this file may be used under the GNU General Public License Version 2 or later.
*
*/
#ifdef _WIN32
#include <util/win32-registry.h>
namespace Inkscape {
namespace Util {
RegistryWatcher::RegistryWatcher(HKEY rootkey, std::string subkey, std::function<bool ()> &callback)
: _callback(callback)
{
// Get the HKEY from the string
char *key = g_locale_from_utf8(subkey.c_str(), -1, NULL, NULL, NULL);
if (RegOpenKeyExA(rootkey, key, 0, KEY_NOTIFY, &_regkey) != ERROR_SUCCESS) {
char *errmsg = g_win32_error_message(GetLastError());
g_warning("Unable to open registery key: %s", errmsg);
g_free(errmsg);
return;
}
g_free(key);
// Create an event object
if (!(_change_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
char *errmsg = g_win32_error_message(GetLastError());
g_warning("Unable to create registery event: %s", errmsg);
g_free(errmsg);
return;
}
// Create a notification
DWORD filter = REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET;
if (RegNotifyChangeKeyValue(_regkey, TRUE, filter, _change_event, TRUE) != ERROR_SUCCESS) {
g_warning("Unable to watch windows registery");
CloseHandle(_change_event);
_change_event = nullptr;
}
// Watch for changes
_poll = Glib::signal_timeout().connect_seconds(sigc::mem_fun(*this, &RegistryWatcher::on_poll), 3000);
}
RegistryWatcher::~RegistryWatcher()
{
_poll.disconnect();
if (_change_event) {
CloseHandle(_change_event);
_change_event = nullptr;
}
}
bool RegisteryWatch::on_poll()
{
if (_change_event) {
// XXX Check _change_event here somehow without blocking
}
}
} // namespace Util
} // namespace Inkscape
#endif // WIN32
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
-- HEADER BEGINS --
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Monitor the windows registery for changes and other windows registry utilities.
*
* Authors:
* Martin Owens <doctormo@geek-2.com>
*
* The contents of this file may be used under the GNU General Public License Version 2 or later.
*
*/
#ifdef _WIN32
#ifndef UTILS_WINREG_H
#define UTILS_WINREG_H
#include <string>
#include <functional>
#include <glib.h>
#include "win32dep.h"
namespace Inkscape {
namespace Util {
class RegistryWatcher
{
public:
RegistryWatcher(HKEY rootkey, std::string hkey, std::function<bool ()> &callback);
~RegistryWatcher();
private:
std::function<bool ()> _callback;
HKEY _regkey = NULL;
// These could be made static in the future to improve performance
sigc::connection _poll;
HANDLE _change_event = NULL;
};
} // namespace Util
} // namespace Inkscape
#endif // UTILS_WINREG_H
#endif // WIN32
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
-
Por favor faça seu login para deixar um comentário!