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_CURRENT_USER, path, 0, KEY_ALL_ACCESS, &key);
50 rc = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_READ, &key);
52 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS, &key);
54 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &key);
57 fprintf(stderr, "RegOpenKeyEx failed\n");
60 rc = RegQueryValueEx(key, NULL, 0, 0, 0, (LPDWORD)&size) ;
62 fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc);
65 buf = (char*)malloc(size+1);
66 rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, (LPDWORD)&size);
68 fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc);
71 if(type == REG_SZ || type == REG_EXPAND_SZ) {
72 while(size && buf[size-1] == '\0')
77 } else if(type == REG_BINARY) {
83 int setRegistryEntry(char*key,char*value)
88 ret1 = RegCreateKey(HKEY_CURRENT_USER, key, &hkey1);
89 ret2 = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey2);
91 fprintf(stderr, "registry: CreateKey %s failed\n", key);
95 ret1 = RegSetValue(hkey1, NULL, REG_SZ, value, strlen(value)+1);
97 ret2 = RegSetValue(hkey2, NULL, REG_SZ, value, strlen(value)+1);
99 fprintf(stderr, "registry: SetValue %s failed\n", key);
108 //HINSTANCE me = GetModuleHandle(NULL);
110 char* getInstallationPath()
113 char* path = getRegistryEntry("Software\\quiss.org\\swftools\\InstallPath");
118 #elif defined(CYGWIN)
119 return SWFTOOLS_DATADIR;
121 return SWFTOOLS_DATADIR;
125 char* concatPaths(const char*base, const char*add)
127 int l1 = strlen(base);
128 int l2 = strlen(add);
131 while(l1 && base[l1-1] == seperator)
133 while(pos < l2 && add[pos] == seperator)
136 n = (char*)malloc(l1 + (l2-pos) + 2);
139 strcpy(&n[l1+1],&add[pos]);
143 char* stripFilename(const char*filename, const char*newext)
145 char*last1 = strrchr(filename, '/');
146 char*last2 = strrchr(filename, '\\');
147 const char*pos = filename;
150 if(last1>pos) pos = last1 + 1;
151 if(last2>pos) pos = last2 + 1;
152 name = (char*)malloc(strlen(pos)+2+(newext?strlen(newext):3));
154 dot = strrchr(name, '.');
159 strcat(name, newext);
163 static char* getTempDir()
166 char*dir = getenv("TMP");
167 if(!dir) dir = getenv("TEMP");
168 if(!dir) dir = getenv("tmp");
169 if(!dir) dir = getenv("temp");
170 if(!dir) dir = "C:\\";
177 char* mktempname(char*ptr) {
178 static char tmpbuf[128];
179 char*dir = getTempDir();
184 if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
192 // used to be mktemp. This does remove the warnings, but
193 // It's not exactly an improvement.
195 sprintf(ptr, "%s%s%08x%08x",dir,sep,lrand48(),lrand48());
198 sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
200 static int count = 1;
201 sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);