doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / blenlib / intern / winstuff.c
index 34b9d9c..71eac3c 100644 (file)
@@ -1,15 +1,12 @@
-/**
+/*
  * $Id$
  *
- * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. The Blender
- * Foundation also sells licenses for use in proprietary software under
- * the Blender License.  See http://www.blender.org/BL/ for information
- * about this.
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * ***** END GPL LICENSE BLOCK *****
  * Windows-posix compatibility layer, windows-specific functions.
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifdef WIN32
 
 #include <stdlib.h>
 #include <stdio.h>
 
 #include "MEM_guardedalloc.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "BKE_utildefines.h"
 
-#include "BLI_blenlib.h"
-#include "BLI_util.h"
 #define WIN32_SKIP_HKEY_PROTECTION             // need to use HKEY
 #include "BLI_winstuff.h"
 
-#include "BKE_utildefines.h" /* FILE_MAXDIR + FILE_MAXFILE */
+ /* FILE_MAXDIR + FILE_MAXFILE */
 
 int BLI_getInstallationDir( char * str ) {
        char dir[FILE_MAXDIR];
@@ -55,7 +50,7 @@ int BLI_getInstallationDir( char * str ) {
        int a;
        
        GetModuleFileName(NULL,str,FILE_MAXDIR+FILE_MAXFILE);
-       BLI_split_dirfile(str,dir,file);
+       BLI_split_dirfile(str,dir,file); /* shouldn't be relative */
        a = strlen(dir);
        if(dir[a-1] == '\\') dir[a-1]=0;
        
@@ -104,7 +99,7 @@ DIR *opendir (const char *path) {
                DIR *newd= MEM_mallocN(sizeof(DIR), "opendir");
 
                newd->handle = INVALID_HANDLE_VALUE;
-               sprintf(newd->path, "%s/*.*",path);
+               sprintf(newd->path, "%s\\*",path);
                
                newd->direntry.d_ino= 0;
                newd->direntry.d_off= 0;
@@ -149,11 +144,105 @@ int closedir (DIR *dp) {
        return 0;
 }
 
-#else
+void get_default_root(char* root) {
+       char str[MAX_PATH+1];
+       
+       /* the default drive to resolve a directory without a specified drive 
+          should be the Windows installation drive, since this was what the OS
+          assumes. */
+       if (GetWindowsDirectory(str,MAX_PATH+1)) {
+               root[0] = str[0];
+               root[1] = ':';
+               root[2] = '\\';
+               root[3] = '\0';
+       } else {                
+               /* if GetWindowsDirectory fails, something has probably gone wrong, 
+                  we are trying the blender install dir though */
+               if (GetModuleFileName(NULL,str,MAX_PATH+1)) {
+                       printf("Error! Could not get the Windows Directory - Defaulting to Blender installation Dir!");
+                       root[0] = str[0];
+                       root[1] = ':';
+                       root[2] = '\\';
+                       root[3] = '\0';
+               } else {
+                       DWORD tmp;
+                       int i;
+                       int rc = 0;
+                       /* now something has gone really wrong - still trying our best guess */
+                       printf("Error! Could not get the Windows Directory - Defaulting to first valid drive! Path might be invalid!");
+                       tmp= GetLogicalDrives();
+                       for (i=2; i < 26; i++) {
+                               if ((tmp>>i) & 1) {
+                                       root[0] = 'a'+i;
+                                       root[1] = ':';
+                                       root[2] = '\\';
+                                       root[3] = '\0';
+                                       if (GetFileAttributes(root) != 0xFFFFFFFF) {
+                                               rc = i;
+                                               break;                  
+                                       }
+                               }
+                       }
+                       if (0 == rc) {
+                               printf("ERROR in 'get_default_root': can't find a valid drive!");
+                               root[0] = 'C';
+                               root[1] = ':';
+                               root[2] = '\\';
+                               root[3] = '\0';
+                       }
+               }               
+       }
+}
+
+int check_file_chars(char *filename)
+{
+       char *p = filename;
+       while (*p) {
+               switch (*p) {
+                       case ':':
+                       case '?':
+                       case '*':
+                       case '|':
+                       case '\\':
+                       case '/':
+                       case '\"':
+                               return 0;
+                               break;
+               }
+
+               p++;
+       }
+       return 1;
+}
 
-static void BLI_WINSTUFF_C_IS_EMPTY_FOR_UNIX(void) 
+/* Copied from http://sourceware.org/ml/newlib/2005/msg00248.html */
+/* Copyright 2005 Shaun Jackman
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+#include <string.h>
+char* dirname(char *path)
 {
-  /*intentionally empty*/
+          char *p;
+          if( path == NULL || *path == '\0' )
+                          return ".";
+          p = path + strlen(path) - 1;
+          while( *p == '/' ) {
+                          if( p == path )
+                                          return path;
+                          *p-- = '\0';
+          }
+          while( p >= path && *p != '/' )
+                          p--;
+          return
+                          p < path ? "." :
+                          p == path ? "/" :
+                          (*p = '\0', path);
 }
+/* End of copied part */
+
+#else
+
+/* intentionally empty for UNIX */
 
 #endif