X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fos.c;h=3370d513782af1193804e6e74f7c6c5df0d9d5f2;hb=21f2e59a76b5493cfb9284945777d7c4ffe310a5;hp=0e850ca456c13d1dccb329760f9df53203663351;hpb=80cc20b7784cccc9d8baf9839f9781db6bb6f539;p=swftools.git diff --git a/lib/os.c b/lib/os.c index 0e850ca..3370d51 100755 --- a/lib/os.c +++ b/lib/os.c @@ -45,18 +45,25 @@ char* getRegistryEntry(char*path) long size = 0; DWORD type; char*buf; - rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS/* KEY_READ*/, &key); + rc = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_ALL_ACCESS, &key); + if(rc != ERROR_SUCCESS) + rc = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_READ, &key); + if(rc != ERROR_SUCCESS) + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS, &key); + if(rc != ERROR_SUCCESS) + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &key); + if (rc != ERROR_SUCCESS) { fprintf(stderr, "RegOpenKeyEx failed\n"); return 0; } - rc = RegQueryValueEx(key, NULL, 0, 0, 0, &size) ; + rc = RegQueryValueEx(key, NULL, 0, 0, 0, (LPDWORD)&size) ; if(rc != ERROR_SUCCESS) { fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc); return 0; } - buf = malloc(size+1); - rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, &size); + buf = (char*)malloc(size+1); + rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, (LPDWORD)&size); if(rc != ERROR_SUCCESS) { fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc); return 0; @@ -74,15 +81,20 @@ char* getRegistryEntry(char*path) int setRegistryEntry(char*key,char*value) { - HKEY hkey; - int ret = 0; - ret = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey); - if(ret != ERROR_SUCCESS) { + HKEY hkey1; + HKEY hkey2; + int ret1 = 0, ret2=0; + ret1 = RegCreateKey(HKEY_CURRENT_USER, key, &hkey1); + ret2 = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey2); + if(ret1 != ERROR_SUCCESS && ret2 != ERROR_SUCESS) { fprintf(stderr, "registry: CreateKey %s failed\n", key); return 0; } - ret = RegSetValue(hkey, NULL, REG_SZ, value, strlen(value)+1); - if(ret != ERROR_SUCCESS) { + if(ret1==ERROR_SUCCESS) + ret1 = RegSetValue(hkey1, NULL, REG_SZ, value, strlen(value)+1); + if(ret2==ERROR_SUCCESS) + ret2 = RegSetValue(hkey2, NULL, REG_SZ, value, strlen(value)+1); + if(ret1 != ERROR_SUCCESS && ret2 != ERROR_SUCCESS) { fprintf(stderr, "registry: SetValue %s failed\n", key); return 0; } @@ -120,7 +132,7 @@ char* concatPaths(const char*base, const char*add) while(pos < l2 && add[pos] == seperator) pos++; - n = malloc(l1 + (l2-pos) + 2); + n = (char*)malloc(l1 + (l2-pos) + 2); memcpy(n,base,l1); n[l1]=seperator; strcpy(&n[l1+1],&add[pos]); @@ -161,7 +173,7 @@ static char* getTempDir() return dir; } -char* mktempname(const char*ptr) { +char* mktempname(char*ptr) { static char tmpbuf[128]; char*dir = getTempDir(); int l = strlen(dir);