4 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
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 Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
31 * Windows-posix compatibility layer, windows-specific functions.
43 #include "MEM_guardedalloc.h"
45 #include "BLI_blenlib.h"
47 #include "BLI_winstuff.h"
49 #include "BKE_utildefines.h" /* FILE_MAXDIR + FILE_MAXFILE */
51 int BLI_getInstallationDir( char * str ) {
55 char buffer[FILE_MAXDIR+FILE_MAXFILE];
58 size = sizeof(buffer);
60 lresult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\BlenderFoundation", 0,
61 KEY_ALL_ACCESS, &hkey);
63 if (lresult == ERROR_SUCCESS) {
64 lresult = RegQueryValueEx(hkey, "Install_Dir", 0, NULL, (LPBYTE)buffer, &size);
74 void RegisterBlendExtension(char * str) {
81 /* Add installation dir to registry --aphex */
83 strncpy(dir, str, strlen(str)-11);
85 lresult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\BlenderFoundation", 0,
86 "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
88 if (lresult == ERROR_SUCCESS) {
89 if (dwd != REG_OPENED_EXISTING_KEY)
90 lresult = RegSetValueEx(hkey, "Install_Dir", 0, REG_SZ, dir, strlen(dir)+1);
94 lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\shell\\open\\command", 0,
95 "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
97 if (lresult == ERROR_SUCCESS) {
98 sprintf(buffer, "\"%s\" \"%%1\"", str);
99 lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
103 lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\DefaultIcon", 0,
104 "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
106 if (lresult == ERROR_SUCCESS) {
107 sprintf(buffer, "\"%s\",1", str);
108 lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
112 lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".blend", 0,
113 "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
115 if (lresult == ERROR_SUCCESS) {
116 sprintf(buffer, "%s", "blendfile");
117 lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
122 static void strlower (char *str) {
129 static void strnlower (char *str, int n) {
130 while (n>0 && *str) {
137 int strcasecmp (char *s1, char *s2) {
141 st1= MEM_mallocN(strlen(s1)+1, "temp string");
144 st2= MEM_mallocN(strlen(s2)+1, "temp string");
149 r= strcmp (st1, st2);
157 int strncasecmp (char *s1, char *s2, int n) {
161 st1= MEM_mallocN(n, "temp string");
164 st2= MEM_mallocN(n, "temp string");
170 r= strncmp (st1, st2, n);
178 DIR *opendir (const char *path) {
179 if (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) {
180 DIR *newd= MEM_mallocN(sizeof(DIR), "opendir");
182 newd->handle = INVALID_HANDLE_VALUE;
183 sprintf(newd->path, "%s/*.*",path);
185 newd->direntry.d_ino= 0;
186 newd->direntry.d_off= 0;
187 newd->direntry.d_reclen= 0;
188 newd->direntry.d_name= NULL;
196 struct dirent *readdir(DIR *dp) {
197 if (dp->direntry.d_name) {
198 MEM_freeN(dp->direntry.d_name);
199 dp->direntry.d_name= NULL;
202 if (dp->handle==INVALID_HANDLE_VALUE) {
203 dp->handle= FindFirstFile(dp->path, &(dp->data));
204 if (dp->handle==INVALID_HANDLE_VALUE)
207 dp->direntry.d_name= BLI_strdup(dp->data.cFileName);
209 return &dp->direntry;
210 } else if (FindNextFile (dp->handle, &(dp->data))) {
211 dp->direntry.d_name= BLI_strdup(dp->data.cFileName);
213 return &dp->direntry;
219 int closedir (DIR *dp) {
220 if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name);
221 if (dp->handle!=INVALID_HANDLE_VALUE) FindClose(dp->handle);
230 void BLI_WINSTUFF_C_IS_EMPTY_FOR_UNIX(void)
232 /*intentionally empty*/