[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51712] branches/asset-browser/source/ blender: == assetbrowser ==

Andrea Weikert elubie at gmx.net
Sun Oct 28 17:22:56 CET 2012


Revision: 51712
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51712
Author:   elubie
Date:     2012-10-28 16:22:56 +0000 (Sun, 28 Oct 2012)
Log Message:
-----------
== assetbrowser ==
Attempt to move the directory functions existing in trunk back to storage.c to hopefully get better merge results.

Modified Paths:
--------------
    branches/asset-browser/source/blender/blenlib/BLI_directory.h
    branches/asset-browser/source/blender/blenlib/BLI_fileops.h
    branches/asset-browser/source/blender/blenlib/intern/directory.c
    branches/asset-browser/source/blender/blenlib/intern/storage.c
    branches/asset-browser/source/blender/editors/space_buttons/buttons_ops.c
    branches/asset-browser/source/blender/editors/space_file/filelist.c

Modified: branches/asset-browser/source/blender/blenlib/BLI_directory.h
===================================================================
--- branches/asset-browser/source/blender/blenlib/BLI_directory.h	2012-10-28 16:17:20 UTC (rev 51711)
+++ branches/asset-browser/source/blender/blenlib/BLI_directory.h	2012-10-28 16:22:56 UTC (rev 51712)
@@ -60,23 +60,6 @@
 
 struct ContentList;
 
-/* Directories */
-
-/* returns 1 if the given path is a directory, 0 otherwise */
-int    BLI_is_dir(const char *path);
-
-/** returns 1 if the given path exists and is not a directiry */
-int    BLI_is_file(const char *path);
-
-/** recursively create all directories for the given path */
-void   BLI_dir_create_recursive(const char *dir);
-
-/** @return the amount of available space on disk */
-double BLI_dir_free_space(const char *dir);
-
-/** @return the current working dir of the user */
-char  *BLI_current_working_dir(char *dir, const size_t maxlen);
-
 /* --- directory reading ---  */
 
 
@@ -102,10 +85,6 @@
  */
 void BLI_dir_contents_ng(const char *path, struct ContentList *dirlist, dir_allocFunc f_alloc, dir_set_entryFunc f_set_entry, dir_sortFunc f_sort_dir);
 
-/* DEPRECATED - old functions */
-void BLI_dir_contents(const char *dirname, struct direntry **files, int *num_files);
-void BLI_dir_dispose(struct direntry *filelist, unsigned int num_files);
-
 #ifdef __cplusplus
 }
 #endif

Modified: branches/asset-browser/source/blender/blenlib/BLI_fileops.h
===================================================================
--- branches/asset-browser/source/blender/blenlib/BLI_fileops.h	2012-10-28 16:17:20 UTC (rev 51711)
+++ branches/asset-browser/source/blender/blenlib/BLI_fileops.h	2012-10-28 16:22:56 UTC (rev 51712)
@@ -60,8 +60,25 @@
 
 /* Directories */
 
-/* moved to BLI_directory.h ! */
+/* returns 1 if the given path is a directory, 0 otherwise */
+int    BLI_is_dir(const char *path);
 
+/** returns 1 if the given path exists and is not a directiry */
+int    BLI_is_file(const char *path);
+
+/** recursively create all directories for the given path */
+void   BLI_dir_create_recursive(const char *dir);
+
+/** @return the amount of available space on disk */
+double BLI_dir_free_space(const char *dir);
+
+/** @return the current working dir of the user */
+char  *BLI_current_working_dir(char *dir, const size_t maxlen);
+
+/* DEPRECATED - old functions */
+int BLI_dir_contents(const char *dirname, struct direntry **files);
+void BLI_dir_dispose(struct direntry *filelist, unsigned int num_files);
+
 /* Files */
 
 FILE  *BLI_fopen(const char *filename, const char *mode);

Modified: branches/asset-browser/source/blender/blenlib/intern/directory.c
===================================================================
--- branches/asset-browser/source/blender/blenlib/intern/directory.c	2012-10-28 16:17:20 UTC (rev 51711)
+++ branches/asset-browser/source/blender/blenlib/intern/directory.c	2012-10-28 16:22:56 UTC (rev 51712)
@@ -102,332 +102,7 @@
 /* vars: */
 
 
-/* can return NULL when the size is not big enough */
-char *BLI_current_working_dir(char *dir, const size_t maxncpy)
-{
-	const char *pwd = getenv("PWD");
-	if (pwd) {
-		BLI_strncpy(dir, pwd, maxncpy);
-		return dir;
-	}
 
-	return getcwd(dir, maxncpy);
-}
-
-
-double BLI_dir_free_space(const char *dir)
-{
-#ifdef WIN32
-	DWORD sectorspc, bytesps, freec, clusters;
-	char tmp[4];
-	
-	tmp[0] = '\\'; tmp[1] = 0; /* Just a failsafe */
-	if (dir[0] == '/' || dir[0] == '\\') {
-		tmp[0] = '\\';
-		tmp[1] = 0;
-	}
-	else if (dir[1] == ':') {
-		tmp[0] = dir[0];
-		tmp[1] = ':';
-		tmp[2] = '\\';
-		tmp[3] = 0;
-	}
-
-	GetDiskFreeSpace(tmp, &sectorspc, &bytesps, &freec, &clusters);
-
-	return (double) (freec * bytesps * sectorspc);
-#else
-
-#if defined(__sun__) || defined(__sun) || defined(__NetBSD__)
-	struct statvfs disk;
-#else
-	struct statfs disk;
-#endif
-	char name[FILE_MAXDIR], *slash;
-	int len = strlen(dir);
-	
-	if (len >= FILE_MAXDIR) /* path too long */
-		return -1;
-	
-	strcpy(name, dir);
-
-	if (len) {
-		slash = strrchr(name, '/');
-		if (slash) slash[1] = 0;
-	}
-	else strcpy(name, "/");
-
-#if defined(__FreeBSD__) || defined(linux) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__GNU__) || defined(__GLIBC__)
-	if (statfs(name, &disk)) return(-1);
-#endif
-
-#if defined(__sun__) || defined(__sun) || defined(__NetBSD__)
-	if (statvfs(name, &disk)) return(-1);	
-#elif !defined(__FreeBSD__) && !defined(linux) && (defined(__sparc) || defined(__sparc__))
-	/* WARNING - This may not be supported by geeneric unix os's - Campbell */
-	if (statfs(name, &disk, sizeof(struct statfs), 0)) return(-1);
-#endif
-
-	return ( ((double) disk.f_bsize) * ((double) disk.f_bfree));
-#endif
-}
-
-static int bli_compare(struct direntry *entry1, struct direntry *entry2)
-{
-	/* type is equal to stat.st_mode */
-
-	if (S_ISDIR(entry1->type)) {
-		if (S_ISDIR(entry2->type) == 0) return (-1);
-	}
-	else {
-		if (S_ISDIR(entry2->type)) return (1);
-	}
-	if (S_ISREG(entry1->type)) {
-		if (S_ISREG(entry2->type) == 0) return (-1);
-	}
-	else {
-		if (S_ISREG(entry2->type)) return (1);
-	}
-	if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
-	if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
-	
-	/* make sure "." and ".." are always first */
-	if (strcmp(entry1->relname, ".") == 0) return (-1);
-	if (strcmp(entry2->relname, ".") == 0) return (1);
-	if (strcmp(entry1->relname, "..") == 0) return (-1);
-	if (strcmp(entry2->relname, "..") == 0) return (1);
-
-	return (BLI_natstrcmp(entry1->relname, entry2->relname));
-}
-
-static void bli_adddirstrings(struct direntry* files, int num_files);
-
-void BLI_dir_contents(const char *dirname, struct direntry **files, int *num_files)
-{
-	int totnum= 0,actnum= 0;
-	struct ListBase dirbase_={NULL, NULL};
-	struct ListBase *dirbase = &dirbase_;
-	struct dirent *fname;
-	struct dirlink *dlink;
-	int newnum = 0;
-	char buf[256];
-	DIR *dir;
-
-#ifndef WIN32
-	if (chdir(dirname) == -1) {
-		perror(dirname);
-		return;
-	}
-#else
-	UTF16_ENCODE(dirname);
-	if (!SetCurrentDirectoryW(dirname_16)) {
-		perror(dirname);
-		free(dirname_16);
-		return;
-	}
-	UTF16_UN_ENCODE(dirname);
-
-#endif
-	if ((dir = (DIR *)opendir("."))) {
-		while ((fname = (struct dirent *) readdir(dir)) != NULL) {
-			dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
-			if (dlink) {
-				BLI_strncpy(buf, fname->d_name, sizeof(buf));
-				dlink->name = BLI_strdup(buf);
-				BLI_addhead(dirbase, dlink);
-				newnum++;
-			}
-		}
-		
-		if (newnum) {
-
-			(*files)=(struct direntry *)MEM_mallocN(newnum * sizeof(struct direntry), "directory files");
-
-			if (*files) {
-				dlink = (struct dirlink *) dirbase->first;
-				while (dlink) {
-					memset(&(*files)[actnum], 0 , sizeof(struct direntry));
-					(*files)[actnum].relname = dlink->name;
-					(*files)[actnum].path = BLI_strdupcat(dirname, dlink->name);
-// use 64 bit file size, only needed for WIN32 and WIN64. 
-// Excluding other than current MSVC compiler until able to test
-#ifdef WIN32
-					{wchar_t * name_16 = alloc_utf16_from_8(dlink->name,0);
-#if (defined(WIN32) || defined(WIN64)) && (_MSC_VER>=1500)
-					_wstat64(name_16,&(*files)[actnum].s);
-#elif defined(__MINGW32__)
-					_stati64(dlink->name,&(*files)[actnum].s);
-#endif
-						free(name_16);
-					}
-
-#else
-					stat(dlink->name,&(*files)[actnum].s);
-#endif
-					(*files)[actnum].type=(*files)[actnum].s.st_mode;
-					(*files)[actnum].flags = 0;
-					totnum++;
-					actnum++;
-					dlink = dlink->next;
-				}
-			}
-			else {
-				printf("Couldn't get memory for dir\n");
-				exit(1);
-			}
-
-			BLI_freelist(dirbase);
-			if ((*files)) qsort((*files), actnum, sizeof(struct direntry), (int (*)(const void *,const void*))bli_compare);
-		}
-		else {
-			printf("%s empty directory\n", dirname);
-		}
-
-		closedir(dir);
-	}
-	else {
-		printf("%s non-existant directory\n", dirname);
-	}
-	
-	bli_adddirstrings((*files), actnum);
-	*num_files= actnum;
-}
-
-static void bli_adddirstrings(struct direntry* files, int num_files)
-{
-	char datum[100];
-	char buf[512];
-	char size[250];
-	static const char *types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
-	int num, mode;
-#ifdef WIN32
-	__int64 st_size;
-#else
-	off_t st_size;
-#endif
-	
-	struct direntry *file;
-	struct tm *tm;
-	time_t zero = 0;
-	
-	for(num=0, file= files; num<num_files; num++, file++) {
-#ifdef WIN32
-		mode = 0;
-		BLI_strncpy(file->mode1, types[0], sizeof(file->mode1));
-		BLI_strncpy(file->mode2, types[0], sizeof(file->mode2));
-		BLI_strncpy(file->mode3, types[0], sizeof(file->mode3));
-#else
-		mode = file->s.st_mode;
-
-		BLI_strncpy(file->mode1, types[(mode & 0700) >> 6], sizeof(file->mode1));
-		BLI_strncpy(file->mode2, types[(mode & 0070) >> 3], sizeof(file->mode2));
-		BLI_strncpy(file->mode3, types[(mode & 0007)], sizeof(file->mode3));
-		
-		if (((mode & S_ISGID) == S_ISGID) && (file->mode2[2] == '-')) file->mode2[2] = 'l';
-
-		if (mode & (S_ISUID | S_ISGID)) {
-			if (file->mode1[2] == 'x') file->mode1[2] = 's';
-			else file->mode1[2] = 'S';
-
-			if (file->mode2[2] == 'x') file->mode2[2] = 's';
-		}
-
-		if (mode & S_ISVTX) {
-			if (file->mode3[2] == 'x') file->mode3[2] = 't';
-			else file->mode3[2] = 'T';
-		}
-#endif
-
-#ifdef WIN32
-		strcpy(file->owner, "user");
-#else
-		{
-			struct passwd *pwuser;
-			pwuser = getpwuid(file->s.st_uid);
-			if (pwuser) {
-				BLI_strncpy(file->owner, pwuser->pw_name, sizeof(file->owner));
-			}
-			else {
-				BLI_snprintf(file->owner, sizeof(file->owner), "%d", file->s.st_uid);
-			}
-		}
-#endif
-
-		tm = localtime(&file->s.st_mtime);
-		// prevent impossible dates in windows
-		if (tm == NULL) tm = localtime(&zero);
-		strftime(file->time, sizeof(file->time), "%H:%M", tm);
-		strftime(file->date, sizeof(file->date), "%d-%b-%y", tm);
-
-		/*
-		 * Seems st_size is signed 32-bit value in *nix and Windows.  This
-		 * will buy us some time until files get bigger than 4GB or until
-		 * everyone starts using __USE_FILE_OFFSET64 or equivalent.
-		 */
-		st_size = file->s.st_size;
-
-		if (st_size > 1024 * 1024 * 1024) {
-			BLI_snprintf(file->size, sizeof(file->size), "%.2f GB", ((double)st_size) / (1024 * 1024 * 1024));
-		}
-		else if (st_size > 1024 * 1024) {
-			BLI_snprintf(file->size, sizeof(file->size), "%.1f MB", ((double)st_size) / (1024 * 1024));
-		}
-		else if (st_size > 1024) {
-			BLI_snprintf(file->size, sizeof(file->size), "%d KB", (int)(st_size / 1024));
-		}
-		else {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list