From 7840a550b58f856b6487c7589f4c237d799f56e3 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Mon, 28 Sep 2020 14:06:36 +0800 Subject: [PATCH] Hides special folders in FileDialog for macOS (cherry picked from commit 1998f7867940c60ac4ed8c009add64cf0a5a45a7) --- drivers/unix/dir_access_unix.cpp | 6 +++++- drivers/unix/dir_access_unix.h | 1 + platform/osx/dir_access_osx.h | 2 ++ platform/osx/dir_access_osx.mm | 10 ++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 66c76e9bec3..ed3c3f5f597 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -154,7 +154,7 @@ String DirAccessUnix::get_next() { _cisdir = (entry->d_type == DT_DIR); } - _cishidden = (fname != "." && fname != ".." && fname.begins_with(".")); + _cishidden = is_hidden(fname); return fname; } @@ -408,6 +408,10 @@ String DirAccessUnix::get_filesystem_type() const { return ""; //TODO this should be implemented } +bool DirAccessUnix::is_hidden(const String &p_name) { + return p_name != "." && p_name != ".." && p_name.begins_with("."); +} + DirAccessUnix::DirAccessUnix() { dir_stream = 0; diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h index 4237dd56912..b6d31bdc8f8 100644 --- a/drivers/unix/dir_access_unix.h +++ b/drivers/unix/dir_access_unix.h @@ -52,6 +52,7 @@ class DirAccessUnix : public DirAccess { protected: virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); } + virtual bool is_hidden(const String &p_name); public: virtual Error list_dir_begin(); ///< This starts dir listing diff --git a/platform/osx/dir_access_osx.h b/platform/osx/dir_access_osx.h index d61ee181f01..91b8f9b2c5a 100644 --- a/platform/osx/dir_access_osx.h +++ b/platform/osx/dir_access_osx.h @@ -47,6 +47,8 @@ protected: virtual int get_drive_count(); virtual String get_drive(int p_drive); + + virtual bool is_hidden(const String &p_name); }; #endif //UNIX ENABLED diff --git a/platform/osx/dir_access_osx.mm b/platform/osx/dir_access_osx.mm index 66ea3809030..f3cd516fe44 100644 --- a/platform/osx/dir_access_osx.mm +++ b/platform/osx/dir_access_osx.mm @@ -69,4 +69,14 @@ String DirAccessOSX::get_drive(int p_drive) { return volname; } +bool DirAccessOSX::is_hidden(const String &p_name) { + String f = get_current_dir().plus_file(p_name); + NSURL *url = [NSURL fileURLWithPath:@(f.utf8().get_data())]; + NSNumber *hidden = nil; + if (![url getResourceValue:&hidden forKey:NSURLIsHiddenKey error:nil]) { + return DirAccessUnix::is_hidden(p_name); + } + return [hidden boolValue]; +} + #endif //posix_enabled