2011-02-18 13:58:08 +00:00
|
|
|
/*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2011-02-18 13:58:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file BLI_fileops.h
|
|
|
|
* \ingroup bli
|
2011-10-22 15:35:49 +00:00
|
|
|
* \brief File and directory operations.
|
2002-10-12 11:37:38 +00:00
|
|
|
* */
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BLI_FILEOPS_H__
|
|
|
|
#define __BLI_FILEOPS_H__
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-20 02:17:37 +00:00
|
|
|
#include <stdio.h>
|
2013-03-05 03:44:47 +00:00
|
|
|
#include <sys/stat.h>
|
2012-03-20 02:17:37 +00:00
|
|
|
|
2010-10-06 16:23:52 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-10-22 15:35:49 +00:00
|
|
|
/* for size_t (needed on windows) */
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2013-08-20 08:33:04 +00:00
|
|
|
#include <limits.h> /* for PATH_MAX */
|
|
|
|
|
2015-02-18 07:26:10 +11:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2013-08-20 08:33:04 +00:00
|
|
|
#ifndef PATH_MAX
|
|
|
|
# define PATH_MAX 4096
|
|
|
|
#endif
|
|
|
|
|
2012-03-20 03:48:32 +00:00
|
|
|
|
2011-10-22 15:35:49 +00:00
|
|
|
/* Common */
|
|
|
|
|
2015-02-18 07:26:10 +11:00
|
|
|
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
int BLI_copy(const char *path, const char *to) ATTR_NONNULL();
|
|
|
|
int BLI_rename(const char *from, const char *to) ATTR_NONNULL();
|
|
|
|
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL();
|
2015-08-24 22:09:01 +02:00
|
|
|
#if 0 /* Unused */
|
2015-02-18 07:26:10 +11:00
|
|
|
int BLI_move(const char *path, const char *to) ATTR_NONNULL();
|
|
|
|
int BLI_create_symlink(const char *path, const char *to) ATTR_NONNULL();
|
2015-08-24 22:09:01 +02:00
|
|
|
#endif
|
2014-05-28 22:50:40 +06:00
|
|
|
|
2014-06-23 10:07:06 +09:00
|
|
|
/* keep in sync with the definition of struct direntry in BLI_fileops_types.h */
|
2014-05-28 22:50:40 +06:00
|
|
|
#ifdef WIN32
|
2014-08-07 13:51:05 +02:00
|
|
|
# if defined(_MSC_VER) || defined(__MINGW64__)
|
2014-05-28 22:50:40 +06:00
|
|
|
typedef struct _stat64 BLI_stat_t;
|
2014-06-23 10:07:06 +09:00
|
|
|
# elif defined(__MINGW32__)
|
|
|
|
typedef struct _stati64 BLI_stat_t;
|
2014-05-28 22:50:40 +06:00
|
|
|
# else
|
2014-06-23 10:07:06 +09:00
|
|
|
typedef struct _stat BLI_stat_t;
|
|
|
|
# endif
|
2014-05-28 22:50:40 +06:00
|
|
|
#else
|
|
|
|
typedef struct stat BLI_stat_t;
|
|
|
|
#endif
|
|
|
|
|
2015-02-18 07:26:10 +11:00
|
|
|
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2014-06-23 10:07:06 +09:00
|
|
|
#ifdef WIN32
|
|
|
|
int BLI_wstat(const wchar_t *path, BLI_stat_t *buffer);
|
|
|
|
#endif
|
2011-10-22 15:35:49 +00:00
|
|
|
|
|
|
|
/* Directories */
|
|
|
|
|
|
|
|
struct direntry;
|
|
|
|
|
2015-02-18 07:26:10 +11:00
|
|
|
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2015-07-14 18:36:48 +02:00
|
|
|
bool BLI_dir_create_recursive(const char *dir) ATTR_NONNULL();
|
2015-02-18 07:26:10 +11:00
|
|
|
double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2015-10-08 15:05:58 +11:00
|
|
|
char *BLI_current_working_dir(char *dir, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2011-10-22 15:35:49 +00:00
|
|
|
|
2015-01-03 12:27:40 +01:00
|
|
|
/* Filelist */
|
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
unsigned int BLI_filelist_dir_contents(const char *dir, struct direntry **r_filelist);
|
|
|
|
void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *src);
|
2015-01-03 10:13:02 +01:00
|
|
|
void BLI_filelist_duplicate(
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
struct direntry **dest_filelist, struct direntry * const src_filelist, const unsigned int nrentries);
|
|
|
|
void BLI_filelist_entry_free(struct direntry *entry);
|
|
|
|
void BLI_filelist_free(struct direntry *filelist, const unsigned int nrentries);
|
|
|
|
|
|
|
|
void BLI_filelist_entry_size_to_string(const struct stat *st, const uint64_t sz, const bool compact, char r_size[]);
|
|
|
|
void BLI_filelist_entry_mode_to_string(
|
|
|
|
const struct stat *st, const bool compact, char r_mode1[], char r_mode2[], char r_mode3[]);
|
|
|
|
void BLI_filelist_entry_owner_to_string(const struct stat *st, const bool compact, char r_owner[]);
|
|
|
|
void BLI_filelist_entry_datetime_to_string(
|
|
|
|
const struct stat *st, const int64_t ts, const bool compact, char r_time[], char r_date[]);
|
2011-10-22 15:35:49 +00:00
|
|
|
|
|
|
|
/* Files */
|
|
|
|
|
2015-02-18 07:26:10 +11:00
|
|
|
FILE *BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
void *BLI_gzopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
int BLI_open(const char *filename, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
int BLI_access(const char *filename, int mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2012-03-20 02:17:37 +00:00
|
|
|
|
2015-02-18 07:26:10 +11:00
|
|
|
bool BLI_file_is_writable(const char *file) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
bool BLI_file_touch(const char *file) ATTR_NONNULL();
|
2011-10-22 15:35:49 +00:00
|
|
|
|
2014-09-04 21:48:36 +10:00
|
|
|
#if 0 /* UNUSED */
|
2015-02-18 07:26:10 +11:00
|
|
|
int BLI_file_gzip(const char *from, const char *to) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2014-09-04 21:48:36 +10:00
|
|
|
#endif
|
2015-02-18 07:26:10 +11:00
|
|
|
char *BLI_file_ungzip_to_mem(const char *from_file, int *r_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2011-10-22 15:35:49 +00:00
|
|
|
|
2015-02-18 07:26:10 +11:00
|
|
|
size_t BLI_file_descriptor_size(int file) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
size_t BLI_file_size(const char *file) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2011-10-22 15:35:49 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/* compare if one was last modified before the other */
|
2015-02-18 07:26:10 +11:00
|
|
|
bool BLI_file_older(const char *file1, const char *file2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2011-10-22 15:35:49 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/* read ascii file as lines, empty list if reading fails */
|
2015-02-18 07:26:10 +11:00
|
|
|
struct LinkNode *BLI_file_read_as_lines(const char *file) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2015-12-14 17:12:16 +11:00
|
|
|
void *BLI_file_read_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size);
|
2015-07-21 09:40:48 +10:00
|
|
|
void BLI_file_free_lines(struct LinkNode *lines);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-09-03 10:12:25 +00:00
|
|
|
/* this weirdo pops up in two places ... */
|
|
|
|
#if !defined(WIN32)
|
|
|
|
# ifndef O_BINARY
|
|
|
|
# define O_BINARY 0
|
|
|
|
# endif
|
2012-10-06 07:03:03 +00:00
|
|
|
#else
|
|
|
|
void BLI_get_short_name(char short_name[256], const char *filename);
|
2012-09-03 10:12:25 +00:00
|
|
|
#endif
|
|
|
|
|
2010-10-06 16:23:52 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-05 03:53:22 +00:00
|
|
|
#endif /* __BLI_FILEOPS_H__ */
|