Exemplo n.º 1
0
/** is file1 older then file2 */
bool BLI_file_older(const char *file1, const char *file2)
{
#ifdef WIN32
#ifndef __MINGW32__
	struct _stat st1, st2;
#else
	struct _stati64 st1, st2;
#endif

	UTF16_ENCODE(file1);
	UTF16_ENCODE(file2);
	
#ifndef __MINGW32__
	if (_wstat(file1_16, &st1)) return false;
	if (_wstat(file2_16, &st2)) return false;
#else
	if (_wstati64(file1_16, &st1)) return false;
	if (_wstati64(file2_16, &st2)) return false;
#endif


	UTF16_UN_ENCODE(file2);
	UTF16_UN_ENCODE(file1);
#else
	struct stat st1, st2;

	if (stat(file1, &st1)) return false;
	if (stat(file2, &st2)) return false;
#endif
	return (st1.st_mtime < st2.st_mtime);
}
Exemplo n.º 2
0
int uputenv(const char *name, const char *value)
{
	int r = -1;
	UTF16_ENCODE(name);

	if (value) {
		/* set */
		UTF16_ENCODE(value);

		if (name_16 && value_16) {
			r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
		}
		UTF16_UN_ENCODE(value);
	}
	else {
		/* clear */
		if (name_16) {
			r = (SetEnvironmentVariableW(name_16,NULL)!= 0) ? 0 : -1;
		}
	}

	UTF16_UN_ENCODE(name);

	return r;
}
Exemplo n.º 3
0
int BLI_copy(const char *file, const char *to)
{
	int err;

	/* windows doesn't support copying to a directory
	 * it has to be 'cp filename filename' and not
	 * 'cp filename destdir' */

	BLI_strncpy(str, to, sizeof(str));
	/* points 'to' to a directory ? */
	if (BLI_last_slash(str) == (str + strlen(str) - 1)) {
		if (BLI_last_slash(file) != NULL) {
			strcat(str, BLI_last_slash(file) + 1);
		}
	}

	UTF16_ENCODE(file);
	UTF16_ENCODE(str);
	err = !CopyFileW(file_16, str_16, false);
	UTF16_UN_ENCODE(str);
	UTF16_UN_ENCODE(file);

	if (err) {
		callLocalErrorCallBack("Unable to copy file!");
		printf(" Copy from '%s' to '%s' failed\n", file, str);
	}

	return err;
}
Exemplo n.º 4
0
int urename(const char *oldname, const char *newname )
{
    int r = -1;
    UTF16_ENCODE(oldname);
    UTF16_ENCODE (newname);

    if(oldname_16 && newname_16) r = _wrename(oldname_16, newname_16);

    UTF16_UN_ENCODE(newname);
    UTF16_UN_ENCODE(oldname);
    return r;
}
Exemplo n.º 5
0
int uputenv(const char *name, const char *value)
{
    int r = -1;
    UTF16_ENCODE(name);
    UTF16_ENCODE(value);
    if(name_16 && value_16) {
        r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
    }
    UTF16_UN_ENCODE(value);
    UTF16_UN_ENCODE(name);

    return r;
}
Exemplo n.º 6
0
void *BLI_gzopen(const char *filename, const char *mode)
{
	gzFile gzfile;

	if (!filename || !mode) {
		return 0;
	}
	else {
		/* xxx Creates file before transcribing the path */
		if (mode[0] == 'w')
			fclose(ufopen(filename, "a"));

		/* temporary #if until we update all libraries to 1.2.7
		 * for correct wide char path handling */
#if ZLIB_VERNUM >= 0x1270 && !defined(FREE_WINDOWS)
		UTF16_ENCODE(filename);

		gzfile = gzopen_w(filename_16, mode);

		UTF16_UN_ENCODE(filename);
#else
		{
			char short_name[256];
			BLI_get_short_name(short_name, filename);
			gzfile = gzopen(short_name, mode);
		}
#endif
	}

	return gzfile;
}
Exemplo n.º 7
0
void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char *filename) const
{
	/* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */
	UTF16_ENCODE(filename);
	SHAddToRecentDocs(SHARD_PATHW, filename_16);
	UTF16_UN_ENCODE(filename);
}
Exemplo n.º 8
0
int BLI_stat(const char *path, struct stat *buffer)
{
	int r;
	UTF16_ENCODE(path);
	r=_wstat(path_16,buffer);
	UTF16_UN_ENCODE(path);
	return r;
}
Exemplo n.º 9
0
int umkdir(const char *pathname)
{

    BOOL r = 0;
    UTF16_ENCODE(pathname);

    if(pathname_16) r = CreateDirectoryW(pathname_16, NULL);

    UTF16_UN_ENCODE(pathname);

    return r ? 0 : -1;
}
Exemplo n.º 10
0
FILE * ufopen(const char * filename, const char * mode)
{
    FILE *f = NULL;
    UTF16_ENCODE(filename);
    UTF16_ENCODE (mode);

    if(filename_16 && mode_16) {
        f = _wfopen(filename_16, mode_16);
    }

    UTF16_UN_ENCODE(mode);
    UTF16_UN_ENCODE(filename);

    if (!f) {
        if ((f = fopen(filename, mode))) {
            printf("WARNING: %s is not utf path. Please update it.\n",filename);
        }
    }

    return f;
}
Exemplo n.º 11
0
/** is file1 older then file2 */
int BLI_file_older(const char *file1, const char *file2)
{
#ifdef WIN32
	struct _stat st1, st2;

	UTF16_ENCODE(file1);
	UTF16_ENCODE(file2);
	
	if (_wstat(file1_16, &st1)) return 0;
	if (_wstat(file2_16, &st2)) return 0;

	UTF16_UN_ENCODE(file2);
	UTF16_UN_ENCODE(file1);
#else
	struct stat st1, st2;

	if (stat(file1, &st1)) return 0;
	if (stat(file2, &st2)) return 0;
#endif
	return (st1.st_mtime < st2.st_mtime);
}
Exemplo n.º 12
0
char * u_alloc_getenv(const char *varname)
{
    char * r = 0;
    wchar_t * str;
    UTF16_ENCODE(varname);
    if (varname_16) {
        str = _wgetenv(varname_16);
        r = alloc_utf_8_from_16(str, 0);
    }
    UTF16_UN_ENCODE(varname);

    return r;
}
Exemplo n.º 13
0
int uaccess(const char *filename, int mode)
{
	int r = -1;
	UTF16_ENCODE(filename);

	if (filename_16) {
		r = _waccess(filename_16, mode);
	}

	UTF16_UN_ENCODE(filename);

	return r;
}
Exemplo n.º 14
0
int BLI_stat(const char *path, struct stat *buffer)
{
	int r;
	UTF16_ENCODE(path);

	/* workaround error in MinGW64 headers, normally, a wstat should work */
	#ifndef __MINGW64__
	r = _wstat(path_16, buffer);
	#else
	r = _wstati64(path_16, buffer);
	#endif

	UTF16_UN_ENCODE(path);
	return r;
}
Exemplo n.º 15
0
void BLI_get_short_name(char short_name[256], const char *filename)
{
	wchar_t short_name_16[256];
	int i = 0;

	UTF16_ENCODE(filename);

	GetShortPathNameW(filename_16, short_name_16, 256);

	for (i = 0; i < 256; i++) {
		short_name[i] = (char)short_name_16[i];
	}

	UTF16_UN_ENCODE(filename);
}
Exemplo n.º 16
0
DynamicLibrary *BLI_dynlib_open(char *name)
{
	DynamicLibrary *lib;
	void *handle;

	UTF16_ENCODE(name);
	handle= LoadLibraryW(name_16);
	UTF16_UN_ENCODE(name);

	if (!handle)
		return NULL;

	lib= MEM_callocN(sizeof(*lib), "Dynamic Library");
	lib->handle= handle;
		
	return lib;
}
Exemplo n.º 17
0
int uput_getenv(const char *varname, char * value, size_t buffsize)
{
    int r = 0;
    wchar_t * str;
    if(!buffsize) return r;

    UTF16_ENCODE(varname);
    if(varname_16) {
        str = _wgetenv(varname_16);
        conv_utf_16_to_8(str, value, buffsize);
        r = 1;
    }
    UTF16_UN_ENCODE(varname);

    if (!r) value[0] = 0;

    return r;
}
Exemplo n.º 18
0
static bool delete_unique(const char *path, const bool dir)
{
	bool err;

	UTF16_ENCODE(path);

	if (dir) {
		err = !RemoveDirectoryW(path_16);
		if (err) printf("Unable to remove directory");
	}
	else {
		err = !DeleteFileW(path_16);
		if (err) callLocalErrorCallBack("Unable to delete file");
	}

	UTF16_UN_ENCODE(path);

	return err;
}
Exemplo n.º 19
0
int uopen(const char *filename, int oflag, int pmode)
{
    int f = -1;
    UTF16_ENCODE(filename);

    if (filename_16) {
        f = _wopen(filename_16, oflag, pmode);
    }

    UTF16_UN_ENCODE(filename);

    if (f == -1) {
        if ((f=open(filename,oflag, pmode)) != -1) {
            printf("WARNING: %s is not utf path. Please update it.\n",filename);
        }
    }

    return f;
}
Exemplo n.º 20
0
int BLI_delete(const char *file, bool dir, bool recursive)
{
	int err;
	
	UTF16_ENCODE(file);

	if (recursive) {
		callLocalErrorCallBack("Recursive delete is unsupported on Windows");
		err = 1;
	}
	else if (dir) {
		err = !RemoveDirectoryW(file_16);
		if (err) printf("Unable to remove directory");
	}
	else {
		err = !DeleteFileW(file_16);
		if (err) callLocalErrorCallBack("Unable to delete file");
	}

	UTF16_UN_ENCODE(file);

	return err;
}
Exemplo n.º 21
0
static void bli_builddir(const char *dirname, const char *relname)
{
	struct dirent *fname;
	struct dirlink *dlink;
	int rellen, newnum = 0;
	char buf[256];
	DIR *dir;

	BLI_strncpy(buf, relname, sizeof(buf));
	rellen=strlen(relname);

	if (rellen) {
		buf[rellen]='/';
		rellen++;
	}
#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 + rellen, fname->d_name, sizeof(buf) - rellen);
				dlink->name = BLI_strdup(buf);
				BLI_addhead(dirbase, dlink);
				newnum++;
			}
		}
		
		if (newnum) {

			if (files) {
				void *tmp = realloc(files, (totnum+newnum) * sizeof(struct direntry));
				if (tmp) {
					files = (struct direntry *)tmp;
				}
				else { /* realloc fail */
					free(files);
					files = NULL;
				}
			}
			
			if (files==NULL)
				files=(struct direntry *)malloc(newnum * sizeof(struct direntry));

			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);
	}
}