-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistryeditor.cpp
115 lines (94 loc) · 3.19 KB
/
registryeditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <QSettings>
#include <QStringList>
#include "registryeditor.h"
const QString RegistryEditor::registryAppPath = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths";
RegistryEditor::RegistryEditor(QObject *parent) :
QObject(parent)
{}
/*
Check if there is such a key in the "App Paths" key(a.k.a. group)
*/
bool RegistryEditor::isInRegistry(const QString& shortcut)
{
QSettings settings(registryAppPath , QSettings::NativeFormat);
QString shortcutExe = shortcut;
shortcutExe.append(".exe");
if (settings.childGroups().contains(shortcutExe,Qt::CaseInsensitive))
return true;
else
return false;
}
/*
Checks whether the shortcut was not overriden by other software.
*/
bool RegistryEditor::isMine(QString shortcut){
QString shortcutTemp = registryAppPath;
shortcutTemp.append("\\").append(shortcut).append(".exe");
QSettings settings(shortcutTemp, QSettings::NativeFormat);
QString string = settings.value("Default").toString();
if (string.startsWith("\""))
return true;
return false;
}
/*
Add a key with extension .exe to the registry under the key "App Paths".
This function also modifies the key if one exists.
*/
void RegistryEditor::addShortcut(const QString& shortcut, const QString& file){
QString AppPath = registryAppPath;
QSettings settings(AppPath.append("\\").append(shortcut).append(".exe"),
QSettings::NativeFormat);
settings.setValue("Default",file);
}
/*
Delete the shortcut's key from under the key "App Paths".
*/
void RegistryEditor::deleteShortcut(const QString& shortcut){
QString shortcutTemp = shortcut;
// return if the shortcut does not exist
if(!isInRegistry(shortcutTemp))
return;
QSettings settings(registryAppPath,
QSettings::NativeFormat);
settings.remove(shortcutTemp.append(".exe"));
}
/*
This is a safe function that removes only the shortcuts
which belong the this particular application (which were
not overriden by other software).
*/
void RegistryEditor::removeAll(QStringList shortcutList){
QString shortcutTemp = registryAppPath;
shortcutTemp.append("\\");
QSettings settings(registryAppPath,
QSettings::NativeFormat);
QString temp;
QString elem;
for (int i = shortcutList.size()-1 ; i >= 0 ; i--){
elem = shortcutList.at(i);
elem = elem.append(".exe");
temp = shortcutTemp + elem;
QSettings checker(temp,QSettings::NativeFormat);
QString string = checker.value("Default").toString();
if(string.startsWith("\"")){
// this shortcut belongs to me (starts with " sign)
// so I can delete it
settings.remove(elem);
}
}
}
/*
Update the changes to the registry.
*/
void RegistryEditor::synchronizeRegistry(){
QSettings settings(registryAppPath,
QSettings::NativeFormat);
settings.sync();
}
/*
Retrieves the path to the file where the shortcuts are stored.
*/
QString RegistryEditor::getShortcutAppPath(){
QSettings settings("Quick Shortcut","Shortcut Visual Editor");
return settings.value("Path").toString();
}