2
* Inkscape Registry Tool
4
* This simple tool is intended for allowing Inkscape to append subdirectories
5
* to its path. This will allow extensions and other files to be accesses
6
* without explicit user intervention.
11
* Copyright (C) 2005-2008 Bob Jamison
13
* This library is free software; you can redistribute it and/or
14
* modify it under the terms of the GNU Lesser General Public
15
* License as published by the Free Software Foundation; either
16
* version 2.1 of the License, or (at your option) any later version.
18
* This library is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
* Lesser General Public License for more details.
23
* You should have received a copy of the GNU Lesser General Public
24
* License along with this library; if not, write to the Free Software
25
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
#include "registrytool.h"
43
KeyTableEntry keyTable[] =
45
{ HKEY_CLASSES_ROOT, 18, "HKEY_CLASSES_ROOT\\" },
46
{ HKEY_CURRENT_CONFIG, 20, "HKEY_CURRENT_CONFIG\\" },
47
{ HKEY_CURRENT_USER, 18, "HKEY_CURRENT_USER\\" },
48
{ HKEY_LOCAL_MACHINE, 19, "HKEY_LOCAL_MACHINE\\" },
49
{ HKEY_USERS, 11, "HKEY_USERS\\" },
55
* Set the string value of a key/name registry entry
57
bool RegistryTool::setStringValue(const Glib::ustring &keyNameArg,
58
const Glib::ustring &valueName,
59
const Glib::ustring &value)
61
Glib::ustring keyName = keyNameArg;
63
HKEY rootKey = HKEY_LOCAL_MACHINE; //default root
64
//Trim out the root key if necessary
65
for (KeyTableEntry *entry = keyTable; entry->key; entry++)
67
if (keyName.compare(0, entry->strlen, entry->str)==0)
70
keyName = keyName.substr(entry->strlen);
73
//printf("trimmed string: '%s'\n", keyName.c_str());
75
//Get or create the key
77
if (RegCreateKeyEx(rootKey, keyName.c_str(),
78
0, NULL, REG_OPTION_NON_VOLATILE,
79
KEY_WRITE, NULL, &key, NULL))
81
fprintf(stderr, "RegistryTool: Could not create the registry key '%s'\n", keyName.c_str());
86
if (RegSetValueEx(key, valueName.c_str(),
87
0, REG_SZ, (LPBYTE) value.c_str(), (DWORD) value.size()))
89
fprintf(stderr, "RegistryTool: Could not set the value '%s'\n", value.c_str());
103
* Get the full path, directory, and base file name of this running executable
105
bool RegistryTool::getExeInfo(Glib::ustring &fullPath,
107
Glib::ustring &exeName)
110
char buf[MAX_PATH+1];
111
if (!GetModuleFileName(NULL, buf, MAX_PATH))
113
fprintf(stderr, "Could not fetch executable file name\n");
118
//printf("Executable file name: '%s'\n", buf);
124
Glib::ustring::size_type pos = fullPath.rfind('\\');
125
if (pos != fullPath.npos)
127
path = fullPath.substr(0, pos);
128
exeName = fullPath.substr(pos+1);
137
* Append our subdirectories to the Application Path for this
140
bool RegistryTool::setPathInfo()
142
Glib::ustring fullPath;
144
Glib::ustring exeName;
146
if (!getExeInfo(fullPath, path, exeName))
149
//printf("full:'%s' path:'%s' exe:'%s'\n",
150
// fullPath.c_str(), path.c_str(), exeName.c_str());
152
Glib::ustring keyName =
153
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
154
keyName.append(exeName);
156
Glib::ustring valueName = "";
157
Glib::ustring value = fullPath;
159
if (!setStringValue(keyName, valueName, value))
162
//add our subdirectories
163
Glib::ustring appPath = path;
164
appPath.append("\\python;");
165
appPath.append(path);
166
appPath.append("\\perl");
170
if (!setStringValue(keyName, valueName, value))
181
* Compile this file with
182
* g++ -DTESTREG registrytool.cpp -o registrytool
183
* to run these tests.
192
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\inkscape.exe";
193
char const *name = "";
194
char const *value = "c:\\inkscape\\inkscape.exe";
195
if (!rt.setStringValue(key, name, value))
197
printf("Test failed\n");
201
printf("Test succeeded\n");
204
value = "c:\\inkscape\\python";
205
if (!rt.setStringValue(key, name, value))
207
printf("Test failed\n");
211
printf("Test succeeded\n");
223
int main(int argc, char **argv)
232
//########################################################################
233
//# E N D O F F I L E
234
//########################################################################