Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarley Acheson <harley.acheson@gmail.com>2020-02-21 19:18:29 +0300
committerHarley Acheson <harley.acheson@gmail.com>2020-02-21 19:20:58 +0300
commit1fb62d1272db477277534c5d31ce220afd100637 (patch)
tree152044d21435b9f3d347b132b8b860d0d706b1f4 /source/blender/blenlib
parentb1b020806e2d5ca403de62dc956c4a27f36bc377 (diff)
UI: Windows File Attributes and Hidden Items
File Browser using Windows file attributes for decorating and hiding items. Differential Revision: https://developer.blender.org/D6816 Reviewed by Campbell Barton
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_fileops.h24
-rw-r--r--source/blender/blenlib/intern/storage.c63
2 files changed, 87 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 5c20e57181e..3ee22e4ad0a 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -73,6 +73,29 @@ int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_
int BLI_wstat(const wchar_t *path, BLI_stat_t *buffer);
#endif
+typedef enum eFileAttributes {
+ FILE_ATTR_READONLY = 1 << 0, /* Read-only or Immutable. */
+ FILE_ATTR_HIDDEN = 1 << 1, /* Hidden or invisible. */
+ FILE_ATTR_SYSTEM = 1 << 2, /* Used by the Operating System. */
+ FILE_ATTR_ARCHIVE = 1 << 3, /* Marked as archived. */
+ FILE_ATTR_COMPRESSED = 1 << 4, /* Compressed. */
+ FILE_ATTR_ENCRYPTED = 1 << 5, /* Encrypted. */
+ FILE_ATTR_RESTRICTED = 1 << 6, /* Protected by OS. */
+ FILE_ATTR_TEMPORARY = 1 << 7, /* Used for temporary storage. */
+ FILE_ATTR_SPARSE_FILE = 1 << 8, /* Sparse File. */
+ FILE_ATTR_OFFLINE = 1 << 9, /* Data is not immediately available. */
+ FILE_ATTR_ALIAS = 1 << 10, /* Mac Alias or Windows Lnk. File-based redirection. */
+ FILE_ATTR_REPARSE_POINT = 1 << 11, /* File has associated reparse point. */
+ FILE_ATTR_SYMLINK = 1 << 12, /* Reference to another file. */
+ FILE_ATTR_JUNCTION_POINT = 1 << 13, /* Folder Symlink. */
+ FILE_ATTR_MOUNT_POINT = 1 << 14, /* Volume mounted as a folder. */
+ FILE_ATTR_HARDLINK = 1 << 15, /* Duplicated directory entry. */
+} eFileAttributes;
+
+#define FILE_ATTR_ANY_LINK \
+ (FILE_ATTR_ALIAS | FILE_ATTR_REPARSE_POINT | FILE_ATTR_SYMLINK | FILE_ATTR_JUNCTION_POINT | \
+ FILE_ATTR_MOUNT_POINT | FILE_ATTR_HARDLINK)
+
/* Directories */
struct direntry;
@@ -83,6 +106,7 @@ bool BLI_dir_create_recursive(const char *dir) ATTR_NONNULL();
double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
char *BLI_current_working_dir(char *dir, const size_t maxlen) ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL();
+eFileAttributes BLI_file_attributes(const char *path);
/* Filelist */
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 7c481868d64..04b3e8abca2 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -199,6 +199,69 @@ size_t BLI_file_size(const char *path)
return stats.st_size;
}
+eFileAttributes BLI_file_attributes(const char *path)
+{
+ int ret = 0;
+
+#ifdef WIN32
+ wchar_t wline[FILE_MAXDIR];
+ BLI_strncpy_wchar_from_utf8(wline, path, ARRAY_SIZE(wline));
+ DWORD attr = GetFileAttributesW(wline);
+ if (attr & FILE_ATTRIBUTE_READONLY) {
+ ret |= FILE_ATTR_READONLY;
+ }
+ if (attr & FILE_ATTRIBUTE_HIDDEN) {
+ ret |= FILE_ATTR_HIDDEN;
+ }
+ if (attr & FILE_ATTRIBUTE_SYSTEM) {
+ ret |= FILE_ATTR_SYSTEM;
+ }
+ if (attr & FILE_ATTRIBUTE_ARCHIVE) {
+ ret |= FILE_ATTR_ARCHIVE;
+ }
+ if (attr & FILE_ATTRIBUTE_COMPRESSED) {
+ ret |= FILE_ATTR_COMPRESSED;
+ }
+ if (attr & FILE_ATTRIBUTE_ENCRYPTED) {
+ ret |= FILE_ATTR_ENCRYPTED;
+ }
+ if (attr & FILE_ATTRIBUTE_TEMPORARY) {
+ ret |= FILE_ATTR_TEMPORARY;
+ }
+ if (attr & FILE_ATTRIBUTE_SPARSE_FILE) {
+ ret |= FILE_ATTR_SPARSE_FILE;
+ }
+ if (attr & FILE_ATTRIBUTE_OFFLINE) {
+ ret |= FILE_ATTR_OFFLINE;
+ }
+ if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
+ ret |= FILE_ATTR_REPARSE_POINT;
+ }
+
+#endif
+
+#ifdef __APPLE__
+
+ /* TODO:
+ * If Hidden (Invisible) set FILE_ATTR_HIDDEN
+ * If Locked set FILE_ATTR_READONLY
+ * If Restricted set FILE_ATTR_RESTRICTED
+ */
+
+#endif
+
+#ifdef __linux__
+
+ /* TODO:
+ * If Immutable set FILE_ATTR_READONLY
+ * If Archived set FILE_ATTR_ARCHIVE
+ */
+
+#endif
+
+ return ret;
+}
+
/**
* Returns the st_mode from stat-ing the specified path name, or 0 if stat fails
* (most likely doesn't exist or no access).