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 ) {
52 char dir[FILE_MAXDIR];
53 char file[FILE_MAXFILE];
56 GetModuleFileName(NULL,str,FILE_MAXDIR+FILE_MAXFILE);
57 BLI_split_dirfile(str,dir,file);
59 if(dir[a-1] == '\\') dir[a-1]=0;
67 void RegisterBlendExtension(char * str) {
73 lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\shell\\open\\command", 0,
74 "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
76 if (lresult == ERROR_SUCCESS) {
77 sprintf(buffer, "\"%s\" \"%%1\"", str);
78 lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
82 lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\DefaultIcon", 0,
83 "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
85 if (lresult == ERROR_SUCCESS) {
86 sprintf(buffer, "\"%s\",1", str);
87 lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
91 lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".blend", 0,
92 "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
94 if (lresult == ERROR_SUCCESS) {
95 sprintf(buffer, "%s", "blendfile");
96 lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
101 static void strlower (char *str) {
108 static void strnlower (char *str, int n) {
109 while (n>0 && *str) {
117 int strcasecmp (char *s1, char *s2) {
121 st1= MEM_mallocN(strlen(s1)+1, "temp string");
124 st2= MEM_mallocN(strlen(s2)+1, "temp string");
129 r= strcmp (st1, st2);
137 int strncasecmp (char *s1, char *s2, int n) {
141 st1= MEM_mallocN(n, "temp string");
144 st2= MEM_mallocN(n, "temp string");
150 r= strncmp (st1, st2, n);
159 DIR *opendir (const char *path) {
160 if (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) {
161 DIR *newd= MEM_mallocN(sizeof(DIR), "opendir");
163 newd->handle = INVALID_HANDLE_VALUE;
164 sprintf(newd->path, "%s/*.*",path);
166 newd->direntry.d_ino= 0;
167 newd->direntry.d_off= 0;
168 newd->direntry.d_reclen= 0;
169 newd->direntry.d_name= NULL;
177 struct dirent *readdir(DIR *dp) {
178 if (dp->direntry.d_name) {
179 MEM_freeN(dp->direntry.d_name);
180 dp->direntry.d_name= NULL;
183 if (dp->handle==INVALID_HANDLE_VALUE) {
184 dp->handle= FindFirstFile(dp->path, &(dp->data));
185 if (dp->handle==INVALID_HANDLE_VALUE)
188 dp->direntry.d_name= BLI_strdup(dp->data.cFileName);
190 return &dp->direntry;
191 } else if (FindNextFile (dp->handle, &(dp->data))) {
192 dp->direntry.d_name= BLI_strdup(dp->data.cFileName);
194 return &dp->direntry;
200 int closedir (DIR *dp) {
201 if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name);
202 if (dp->handle!=INVALID_HANDLE_VALUE) FindClose(dp->handle);
211 void BLI_WINSTUFF_C_IS_EMPTY_FOR_UNIX(void)
213 /*intentionally empty*/