3 operating system dependent functions
5 Part of the swftools package.
7 Copyright (c) 2005 Matthias Kramm <kramm@quiss.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
32 static char seperator = '/';
34 static char seperator = '\\';
36 static char seperator = '/';
40 char* getRegistryEntry(char*path)
48 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS/* KEY_READ*/, &key);
49 if (rc != ERROR_SUCCESS) {
50 fprintf(stderr, "RegOpenKeyEx failed\n");
53 rc = RegQueryValueEx(key, NULL, 0, 0, 0, &size) ;
54 if(rc != ERROR_SUCCESS) {
55 fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc);
59 rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, &size);
60 if(rc != ERROR_SUCCESS) {
61 fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc);
64 if(type == REG_SZ || type == REG_EXPAND_SZ) {
65 while(size && buf[size-1] == '\0')
70 } else if(type == REG_BINARY) {
75 int setRegistryEntry(char*key,char*value)
79 ret = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey);
80 if(ret != ERROR_SUCCESS) {
81 fprintf(stderr, "registry: CreateKey %s failed\n", key);
84 ret = RegSetValue(hkey, NULL, REG_SZ, value, strlen(value)+1);
85 if(ret != ERROR_SUCCESS) {
86 fprintf(stderr, "registry: SetValue %s failed\n", key);
95 //HINSTANCE me = GetModuleHandle(NULL);
97 char* getInstallationPath()
100 char* path = getRegistryEntry("Software\\quiss.org\\swftools\\InstallPath");
105 #elif defined(CYGWIN)
106 return SWFTOOLS_DATADIR;
108 return SWFTOOLS_DATADIR;
112 char* concatPaths(char*base, char*add)
114 int l1 = strlen(base);
115 int l2 = strlen(add);
118 while(l1 && base[l1-1] == seperator)
120 while(pos < l2 && add[pos] == seperator)
123 n = malloc(l1 + (l2-pos) + 2);
126 strcpy(&n[l1+1],&add[pos]);
130 char* stripFilename(char*filename, char*newext)
132 char*last1 = strrchr(filename, '/');
133 char*last2 = strrchr(filename, '\\');
137 if(last1>pos) pos = last1 + 1;
138 if(last2>pos) pos = last2 + 1;
139 name = (char*)malloc(strlen(pos)+2+(newext?strlen(newext):3));
141 dot = strrchr(name, '.');
146 strcat(name, newext);