Mercurial > mplayer.hg
annotate TOOLS/modify_reg.c @ 27654:a246ee34231b
Filter out xpm files from the list of dependencies to check for recursive
dependencies. This avoids a ton of spurious warnings when generating
dependency information in the gui subdirectory.
author | diego |
---|---|
date | Fri, 03 Oct 2008 09:56:37 +0000 |
parents | 0f42fb42843c |
children | 0f1b5b68af32 |
rev | line source |
---|---|
23996 | 1 /* |
2 * A program to modify a registry file. | |
3 * | |
4 * Copyright (C) 2007 Alan Nisota | |
5 * | |
26743
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
6 * This file is part of MPlayer. |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
7 * |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
11 * (at your option) any later version. |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
12 * |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
16 * GNU General Public License for more details. |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
17 * |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26575
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
23996 | 21 */ |
22 | |
23 #include <unistd.h> | |
24 #include <getopt.h> | |
25 #include "loader/registry.c" | |
26 | |
27 #include "mp_msg.h" | |
28 #ifdef __GNUC__ | |
29 #define mp_msg(t, l, m, args...) fprintf(stderr, m, ##args) | |
30 #else | |
31 #define mp_msg(t, l, ...) fprintf(stderr, __VA_ARGS__) | |
32 #endif | |
33 | |
34 #include "get_path.c" | |
35 | |
36 static void remove_key(long handle, const char* name) { | |
37 int i, len; | |
24180 | 38 char *fullname; |
23996 | 39 |
40 fullname = build_keyname(handle, name); | |
41 len = strlen(fullname); | |
42 for (i=0; i < reg_size;) { | |
43 if (!strncmp(regs[i].name, fullname, len)) { | |
44 free(regs[i].value); | |
45 free(regs[i].name); | |
46 memmove(®s[i], ®s[i+1], --reg_size*sizeof(struct reg_value)); | |
47 } else { | |
48 i++; | |
49 } | |
50 } | |
51 free(fullname); | |
52 save_registry(); | |
53 } | |
54 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
24180
diff
changeset
|
55 static void parse_key(char *raw, HKEY *root, char *path, char *key) { |
23996 | 56 char *tmpkey, *start; |
57 tmpkey = strrchr(raw, '\\'); | |
58 if (tmpkey == raw || tmpkey == NULL) { | |
59 printf("Couldn't process key \"%s\"\n", raw); | |
60 return; | |
61 } | |
62 start = strchr(raw, '\\'); | |
63 if (start == raw || start == NULL) { | |
64 printf("Couldn't process key \"%s\"\n", raw); | |
65 return; | |
66 } | |
67 if (strncmp(raw, "HKEY_CURRENT_USER\\", 18) == 0 || | |
68 strncmp(raw, "HKCU\\", 5) == 0) { | |
69 *root = HKEY_CURRENT_USER; | |
70 } else if (strncmp(raw, "HKEY_LOCAL_MACHINE\\", 19) == 0 || | |
71 strncmp(raw, "HKLM\\", 5) == 0) { | |
72 *root = HKEY_LOCAL_MACHINE; | |
73 } else { | |
74 printf("Couldn't process key \"%s\"\n", raw); | |
75 return; | |
76 } | |
77 strncpy(key, tmpkey + 1, strlen(tmpkey)-1); | |
78 key[strlen(tmpkey)-1] = 0; | |
79 while(*start == '\\') | |
80 start++; | |
81 while(*(tmpkey-1) == '\\') | |
82 tmpkey--; | |
83 strncpy(path, start, tmpkey - start); | |
84 path[tmpkey - start] = 0; | |
85 } | |
86 | |
87 int main(int argc, char *argv[]) { | |
88 int i; | |
89 long type = REG_SZ; | |
90 char c, path[256], key[256], *value = NULL; | |
91 HKEY root = 0; | |
92 int Option_Index; | |
93 int list = 0, del = 0; | |
94 int newkey, status; | |
95 static struct option Long_Options[] = { | |
96 {"registry", 1, 0, 'r'}, | |
97 {"list", 0, 0, 'l'}, | |
98 {"key", 1, 0, 'k'}, | |
99 {"value", 1, 0, 'v'}, | |
100 {"type", 1, 0, 't'}, | |
101 {"del", 0, 0, 'd'}, | |
102 }; | |
103 while(1) { | |
104 c = getopt_long(argc, argv, "r:lk:v:t:id", Long_Options, &Option_Index); | |
105 if (c == EOF) | |
106 break; | |
107 switch(c) { | |
108 case 'r': | |
109 localregpathname = optarg; | |
110 break; | |
111 case 'l': | |
112 list = 1; | |
113 break; | |
114 case 'k': | |
115 parse_key(optarg, &root, path, key); | |
116 break; | |
117 case 'v': | |
118 value = optarg; | |
119 break; | |
120 case 't': | |
121 if (!strcmp(optarg, "string")) | |
122 type = REG_SZ; | |
123 else if (!strcmp(optarg, "dword")) | |
124 type = REG_DWORD; | |
125 break; | |
126 case 'd': | |
127 del = 1; | |
128 break; | |
129 } | |
130 } | |
131 if (localregpathname == NULL || (! list && ! root)) { | |
132 printf("Must specify '-r' and either '-k' or '-l'\n"); | |
133 return 1; | |
134 } | |
135 if (del && (list || value)) { | |
136 printf("Can't specify '-d' along with '-l' or '-v'\n"); | |
137 return 1; | |
138 } | |
139 open_registry(); | |
140 insert_handle(HKEY_LOCAL_MACHINE, "HKLM"); | |
141 insert_handle(HKEY_CURRENT_USER, "HKCU"); | |
142 | |
143 if (del) { | |
144 char tmpname[256]; | |
145 sprintf(tmpname, "%s\\%s", path, key); | |
146 remove_key(root, tmpname); | |
147 return 0; | |
148 } | |
149 | |
150 if (list) { | |
151 for (i=0; i < reg_size; i++) { | |
152 if (regs[i].type == DIR) { | |
153 printf("Directory: %s\n", regs[i].name); | |
154 } else if (regs[i].type == REG_DWORD) { | |
155 DWORD v = *(DWORD *)regs[i].value; | |
156 printf("%s :: %08x type: DWORD\n", regs[i].name, v); | |
157 } else if (regs[i].type == REG_SZ) { | |
158 printf("%s :: '%s' len: %d type: String\n", | |
159 regs[i].name, regs[i].value, regs[i].len); | |
160 } else { | |
161 printf("%s :: '%s' len: %d type: %08x\n", | |
162 regs[i].name, regs[i].value, regs[i].len, regs[i].type); | |
163 } | |
164 } | |
165 } | |
166 if (root) { | |
167 RegCreateKeyExA(root, path, 0, 0, 0, 0, 0, &newkey, &status); | |
168 if (value != NULL) { | |
169 int len; | |
170 DWORD v; | |
171 if (type == REG_DWORD) { | |
172 len = sizeof(DWORD); | |
173 v = strtoul(value, NULL, 0); | |
174 value = (char *)&v; | |
175 } else | |
176 len = strlen(value)+1; | |
177 printf("%08x -- %d\n", *value, len); | |
178 RegSetValueExA(newkey, key, 0, type, value, len); | |
179 } | |
180 } | |
181 return 0; | |
182 } | |
183 |