annotate loader/registry.c @ 887:1e30c5b55cdb

prints kernel, gcc and binutils version
author arpi_esp
date Sat, 26 May 2001 21:26:03 +0000
parents 1f7c824033fb
children d8c1b0b38edc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 #include <config.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 #include <pwd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #include <sys/types.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #include <wine/winbase.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include <wine/winreg.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include <wine/winnt.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include <wine/winerror.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 #include <registry.h>
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
14 //#undef TRACE
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
15 //#define TRACE printf
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 struct reg_value
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 int type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 char* name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 char* value;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 static int reg_size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 static struct reg_value* regs=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 struct reg_handle_s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 typedef struct reg_handle_s
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 int handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 char* name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 struct reg_handle_s* next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 struct reg_handle_s* prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 } reg_handle_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 static reg_handle_t* head=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 #define DIR -25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40
178
55206b791586 get_path()
szabii
parents: 172
diff changeset
41 extern char *get_path(char *);
55206b791586 get_path()
szabii
parents: 172
diff changeset
42
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 static void create_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 static void open_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 static void save_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 static void create_registry(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 if(regs)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 printf("Logic error: create_registry() called with existing registry\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 save_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 regs=(struct reg_value*)malloc(3*sizeof(struct reg_value));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 regs[0].type=regs[1].type=DIR;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 regs[0].name=(char*)malloc(5);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 strcpy(regs[0].name, "HKLM");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 regs[1].name=(char*)malloc(5);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 strcpy(regs[1].name, "HKCU");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 regs[0].value=regs[1].value=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 regs[0].len=regs[1].len=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 reg_size=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 save_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 static void open_registry()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 int fd;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 int len;
178
55206b791586 get_path()
szabii
parents: 172
diff changeset
73 // struct passwd* pwent;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 char* pathname;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 if(regs)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 printf("Multiple open_registry(>\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }
178
55206b791586 get_path()
szabii
parents: 172
diff changeset
80 // pwent=getpwuid(getuid());
55206b791586 get_path()
szabii
parents: 172
diff changeset
81 // pathname=(char*)malloc(strlen(pwent->pw_dir)+20);
55206b791586 get_path()
szabii
parents: 172
diff changeset
82 // strcpy(pathname, pwent->pw_dir);
55206b791586 get_path()
szabii
parents: 172
diff changeset
83 // strcat(pathname, "/.mplayer/registry");
55206b791586 get_path()
szabii
parents: 172
diff changeset
84 pathname = get_path("registry");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 fd=open(pathname, O_RDONLY);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 free(pathname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 if(fd==-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 printf("Creating new registry\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 create_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 read(fd, &reg_size, 4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 for(i=0; i<reg_size; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 read(fd,&regs[i].type,4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 read(fd,&len,4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 regs[i].name=(char*)malloc(len+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 if(regs[i].name==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 reg_size=i+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 read(fd, regs[i].name, len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 regs[i].name[len]=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 read(fd,&regs[i].len,4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 regs[i].value=(char*)malloc(regs[i].len+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 if(regs[i].value==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 free(regs[i].name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 reg_size=i+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 read(fd, regs[i].value, regs[i].len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 regs[i].value[regs[i].len]=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 error:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 static void save_registry()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 int fd, i, len;
178
55206b791586 get_path()
szabii
parents: 172
diff changeset
126 // struct passwd* pwent;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 char* pathname;
178
55206b791586 get_path()
szabii
parents: 172
diff changeset
128 // pwent=getpwuid(getuid());
55206b791586 get_path()
szabii
parents: 172
diff changeset
129 // pathname=(char*)malloc(strlen(pwent->pw_dir)+20);
55206b791586 get_path()
szabii
parents: 172
diff changeset
130 // strcpy(pathname, pwent->pw_dir);
55206b791586 get_path()
szabii
parents: 172
diff changeset
131 // strcat(pathname, "/.mplayer/registry");
55206b791586 get_path()
szabii
parents: 172
diff changeset
132 pathname = get_path("registry");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 fd=open(pathname, O_WRONLY | O_CREAT, 00777);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 free(pathname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 if(fd==-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 printf("Failed to open registry file for writing.\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 write(fd, &reg_size, 4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 for(i=0; i<reg_size; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 write(fd, &regs[i].type, 4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 len=strlen(regs[i].name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 write(fd, &len, 4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 write(fd, regs[i].name, len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 write(fd, &regs[i].len, 4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 write(fd, regs[i].value, regs[i].len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 static reg_handle_t* find_handle_by_name(const char* name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 for(t=head; t; t=t->prev)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 if(!strcmp(t->name, name))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 return t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 static struct reg_value* find_value_by_name(const char* name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 for(i=0; i<reg_size; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 if(!strcmp(regs[i].name, name))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 return regs+i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 static reg_handle_t* find_handle(int handle)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 for(t=head; t; t=t->prev)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 if(t->handle==handle)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 return t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 static int generate_handle()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 static int zz=249;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 zz++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 while((zz==HKEY_LOCAL_MACHINE) || (zz==HKEY_CURRENT_USER))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 zz++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 return zz;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 static reg_handle_t* insert_handle(long handle, const char* name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 t=(reg_handle_t*)malloc(sizeof(reg_handle_t));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 if(head==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 t->prev=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 head->next=t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 t->prev=head;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 t->next=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 t->name=(char*)malloc(strlen(name)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 strcpy(t->name, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 t->handle=handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 head=t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 return t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 static char* build_keyname(long key, const char* subkey)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 char* full_name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 if((t=find_handle(key))==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 TRACE("Invalid key\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 if(subkey==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 subkey="<default>";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 strcpy(full_name, t->name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 strcat(full_name, "\\");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 strcat(full_name, subkey);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 return full_name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 struct reg_value* v;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 char* fullname;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 if((fullname=build_keyname(handle, name))==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 TRACE("Invalid handle\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 if((v=find_value_by_name(fullname))==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 //creating new value in registry
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 if(regs==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 create_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 v=regs+reg_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 reg_size++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 //replacing old one
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 free(v->value);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 free(v->name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 v->type=type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 v->len=len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 v->value=(char*)malloc(len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 memcpy(v->value, value, len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 v->name=(char*)malloc(strlen(fullname)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 strcpy(v->name, fullname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 save_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 return v;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 static void init_registry()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 {
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 178
diff changeset
268 #ifdef DETAILED_OUT
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
269 printf("Initializing registry\n");
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 178
diff changeset
270 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 open_registry();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 insert_handle(HKEY_LOCAL_MACHINE, "HKLM");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 insert_handle(HKEY_CURRENT_USER, "HKCU");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 static reg_handle_t* find_handle_2(long key, const char* subkey)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 char* full_name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 if((t=find_handle(key))==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 TRACE("Invalid key\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 return (reg_handle_t*)-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 if(subkey==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 return t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 strcpy(full_name, t->name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 strcat(full_name, "\\");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 strcat(full_name, subkey);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 t=find_handle_by_name(full_name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 free(full_name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 return t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 long RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 char* full_name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 struct reg_value* v;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 TRACE("Opening key %s\n", subkey);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 if(!regs)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 init_registry()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 /* t=find_handle_2(key, subkey);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 if(t==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 if(t==(reg_handle_t*)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 */ full_name=build_keyname(key, subkey);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314 if(!full_name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 v=find_value_by_name(full_name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 t=insert_handle(generate_handle(), full_name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 *newkey=t->handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 free(full_name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 long RegCloseKey(long key)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 reg_handle_t *handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 if(key==HKEY_LOCAL_MACHINE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 if(key==HKEY_CURRENT_USER)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 handle=find_handle(key);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 if(handle==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 if(handle->prev)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 handle->prev->next=handle->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 if(handle->next)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 handle->next->prev=handle->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 if(handle->name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 free(handle->name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 if(handle==head)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 head=head->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 free(handle);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 struct reg_value* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 char* c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 TRACE("Querying value %s\n", value);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 if(!regs)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 init_registry()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 c=build_keyname(key, value);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 if(c==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 if((t=find_value_by_name(c))==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 free(c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359 return 2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 free(c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 if(type)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 *type=t->type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 if(data)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 memcpy(data, t->value, (t->len<*count)?t->len:*count);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 TRACE("returning %d bytes: %d\n", t->len, *(int*)data);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 if(*count<t->len)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 *count=t->len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 return ERROR_MORE_DATA;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 *count=t->len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 long RegCreateKeyExA(long key, const char* name, long reserved,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 void* classs, long options, long security,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 void* sec_attr, int* newkey, int* status)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 reg_handle_t* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 char* fullname;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 struct reg_value* v;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 // TRACE("Creating/Opening key %s\n", name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 TRACE("Creating/Opening key %s\n", name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 if(!regs)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390 init_registry()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
392 fullname=build_keyname(key, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
393 if(fullname==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
394 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
395 v=find_value_by_name(fullname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
396 if(v==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
398 int qw=45708;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
399 v=insert_reg_value(key, name, DIR, &qw, 4);
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
400 if (status) *status=REG_CREATED_NEW_KEY;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
401 // return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
402 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
403 else
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
404 if (status) *status=REG_OPENED_EXISTING_KEY;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 t=insert_handle(generate_handle(), fullname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407 *newkey=t->handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 free(fullname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
409 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
410 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
411 long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
412 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
413 struct reg_value* t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 char* c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
415 TRACE("Request to set value %s\n", name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
416 if(!regs)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
417 init_registry()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
418 ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
419 c=build_keyname(key, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
420 if(c==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
421 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
422 insert_reg_value(key, name, v2, data, size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
423 free(c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
424 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
425 }