X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fos.c;h=c76851345ca2d9602cbdd7b5d56513cfc77cc2e0;hb=860eb8fcabf038906e2038a914a643ce35eb6a52;hp=207c3c164be6971413dfee45645d3c2700972a0c;hpb=267fbed207d24342f1117f83c944553c2360652b;p=swftools.git diff --git a/lib/os.c b/lib/os.c index 207c3c1..c768513 100755 --- a/lib/os.c +++ b/lib/os.c @@ -45,19 +45,26 @@ char* getRegistryEntry(char*path) long size = 0; DWORD type; char*buf; - rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS/* KEY_READ*/, &key); - if (rc != ERROR_SUCCESS) { + rc = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_ALL_ACCESS, &key); + if(rc) + rc = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_READ, &key); + if(rc) + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS, &key); + if(rc) + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &key); + + if (rc) { fprintf(stderr, "RegOpenKeyEx failed\n"); return 0; } - rc = RegQueryValueEx(key, NULL, 0, 0, 0, &size) ; - if(rc != ERROR_SUCCESS) { + rc = RegQueryValueEx(key, NULL, 0, 0, 0, (LPDWORD)&size) ; + if(rc) { fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc); return 0; } - buf = malloc(size+1); - rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, &size); - if(rc != ERROR_SUCCESS) { + buf = (char*)malloc(size+1); + rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, (LPDWORD)&size); + if(rc) { fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc); return 0; } @@ -70,19 +77,25 @@ char* getRegistryEntry(char*path) } else if(type == REG_BINARY) { return buf; } + return 0; } 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 && ret2) { 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) + ret1 = RegSetValue(hkey1, NULL, REG_SZ, value, strlen(value)+1); + if(!ret2) + ret2 = RegSetValue(hkey2, NULL, REG_SZ, value, strlen(value)+1); + if(ret1 && ret2) { fprintf(stderr, "registry: SetValue %s failed\n", key); return 0; } @@ -109,7 +122,7 @@ char* getInstallationPath() #endif } -char* concatPaths(char*base, char*add) +char* concatPaths(const char*base, const char*add) { int l1 = strlen(base); int l2 = strlen(add); @@ -120,18 +133,18 @@ char* concatPaths(char*base, 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]); return n; } -char* stripFilename(char*filename, char*newext) +char* stripFilename(const char*filename, const char*newext) { char*last1 = strrchr(filename, '/'); char*last2 = strrchr(filename, '\\'); - char*pos = filename; + const char*pos = filename; char*name; char*dot; if(last1>pos) pos = last1 + 1;