@@ -583,19 +583,18 @@ uint64_t FileAccess::get_modified_time(const String &p_file) {
583
583
return mt;
584
584
}
585
585
586
- uint32_t FileAccess::get_unix_permissions (const String &p_file) {
586
+ BitField<FileAccess::UnixPermissionFlags> FileAccess::get_unix_permissions (const String &p_file) {
587
587
if (PackedData::get_singleton () && !PackedData::get_singleton ()->is_disabled () && (PackedData::get_singleton ()->has_path (p_file) || PackedData::get_singleton ()->has_directory (p_file))) {
588
588
return 0 ;
589
589
}
590
590
591
591
Ref<FileAccess> fa = create_for_path (p_file);
592
592
ERR_FAIL_COND_V_MSG (fa.is_null (), 0 , " Cannot create FileAccess for path '" + p_file + " '." );
593
593
594
- uint32_t mt = fa->_get_unix_permissions (p_file);
595
- return mt;
594
+ return fa->_get_unix_permissions (p_file);
596
595
}
597
596
598
- Error FileAccess::set_unix_permissions (const String &p_file, uint32_t p_permissions) {
597
+ Error FileAccess::set_unix_permissions (const String &p_file, BitField<FileAccess::UnixPermissionFlags> p_permissions) {
599
598
if (PackedData::get_singleton () && !PackedData::get_singleton ()->is_disabled () && (PackedData::get_singleton ()->has_path (p_file) || PackedData::get_singleton ()->has_directory (p_file))) {
600
599
return ERR_UNAVAILABLE;
601
600
}
@@ -607,6 +606,52 @@ Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissi
607
606
return err;
608
607
}
609
608
609
+ bool FileAccess::get_hidden_attribute (const String &p_file) {
610
+ if (PackedData::get_singleton () && !PackedData::get_singleton ()->is_disabled () && (PackedData::get_singleton ()->has_path (p_file) || PackedData::get_singleton ()->has_directory (p_file))) {
611
+ return false ;
612
+ }
613
+
614
+ Ref<FileAccess> fa = create_for_path (p_file);
615
+ ERR_FAIL_COND_V_MSG (fa.is_null (), false , " Cannot create FileAccess for path '" + p_file + " '." );
616
+
617
+ return fa->_get_hidden_attribute (p_file);
618
+ }
619
+
620
+ Error FileAccess::set_hidden_attribute (const String &p_file, bool p_hidden) {
621
+ if (PackedData::get_singleton () && !PackedData::get_singleton ()->is_disabled () && (PackedData::get_singleton ()->has_path (p_file) || PackedData::get_singleton ()->has_directory (p_file))) {
622
+ return ERR_UNAVAILABLE;
623
+ }
624
+
625
+ Ref<FileAccess> fa = create_for_path (p_file);
626
+ ERR_FAIL_COND_V_MSG (fa.is_null (), ERR_CANT_CREATE, " Cannot create FileAccess for path '" + p_file + " '." );
627
+
628
+ Error err = fa->_set_hidden_attribute (p_file, p_hidden);
629
+ return err;
630
+ }
631
+
632
+ bool FileAccess::get_read_only_attribute (const String &p_file) {
633
+ if (PackedData::get_singleton () && !PackedData::get_singleton ()->is_disabled () && (PackedData::get_singleton ()->has_path (p_file) || PackedData::get_singleton ()->has_directory (p_file))) {
634
+ return false ;
635
+ }
636
+
637
+ Ref<FileAccess> fa = create_for_path (p_file);
638
+ ERR_FAIL_COND_V_MSG (fa.is_null (), false , " Cannot create FileAccess for path '" + p_file + " '." );
639
+
640
+ return fa->_get_read_only_attribute (p_file);
641
+ }
642
+
643
+ Error FileAccess::set_read_only_attribute (const String &p_file, bool p_ro) {
644
+ if (PackedData::get_singleton () && !PackedData::get_singleton ()->is_disabled () && (PackedData::get_singleton ()->has_path (p_file) || PackedData::get_singleton ()->has_directory (p_file))) {
645
+ return ERR_UNAVAILABLE;
646
+ }
647
+
648
+ Ref<FileAccess> fa = create_for_path (p_file);
649
+ ERR_FAIL_COND_V_MSG (fa.is_null (), ERR_CANT_CREATE, " Cannot create FileAccess for path '" + p_file + " '." );
650
+
651
+ Error err = fa->_set_read_only_attribute (p_file, p_ro);
652
+ return err;
653
+ }
654
+
610
655
void FileAccess::store_string (const String &p_string) {
611
656
if (p_string.length () == 0 ) {
612
657
return ;
@@ -865,6 +910,14 @@ void FileAccess::_bind_methods() {
865
910
ClassDB::bind_static_method (" FileAccess" , D_METHOD (" file_exists" , " path" ), &FileAccess::exists);
866
911
ClassDB::bind_static_method (" FileAccess" , D_METHOD (" get_modified_time" , " file" ), &FileAccess::get_modified_time);
867
912
913
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" get_unix_permissions" , " file" ), &FileAccess::get_unix_permissions);
914
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" set_unix_permissions" , " file" , " permissions" ), &FileAccess::set_unix_permissions);
915
+
916
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" get_hidden_attribute" , " file" ), &FileAccess::get_hidden_attribute);
917
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" set_hidden_attribute" , " file" , " hidden" ), &FileAccess::set_hidden_attribute);
918
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" set_read_only_attribute" , " file" , " ro" ), &FileAccess::set_read_only_attribute);
919
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" get_read_only_attribute" , " file" ), &FileAccess::get_read_only_attribute);
920
+
868
921
ADD_PROPERTY (PropertyInfo (Variant::BOOL, " big_endian" ), " set_big_endian" , " is_big_endian" );
869
922
870
923
BIND_ENUM_CONSTANT (READ);
@@ -877,4 +930,17 @@ void FileAccess::_bind_methods() {
877
930
BIND_ENUM_CONSTANT (COMPRESSION_ZSTD);
878
931
BIND_ENUM_CONSTANT (COMPRESSION_GZIP);
879
932
BIND_ENUM_CONSTANT (COMPRESSION_BROTLI);
933
+
934
+ BIND_BITFIELD_FLAG (UNIX_READ_OWNER);
935
+ BIND_BITFIELD_FLAG (UNIX_WRITE_OWNER);
936
+ BIND_BITFIELD_FLAG (UNIX_EXECUTE_OWNER);
937
+ BIND_BITFIELD_FLAG (UNIX_READ_GROUP);
938
+ BIND_BITFIELD_FLAG (UNIX_WRITE_GROUP);
939
+ BIND_BITFIELD_FLAG (UNIX_EXECUTE_GROUP);
940
+ BIND_BITFIELD_FLAG (UNIX_READ_OTHER);
941
+ BIND_BITFIELD_FLAG (UNIX_WRITE_OTHER);
942
+ BIND_BITFIELD_FLAG (UNIX_EXECUTE_OTHER);
943
+ BIND_BITFIELD_FLAG (UNIX_SET_USER_ID);
944
+ BIND_BITFIELD_FLAG (UNIX_SET_GROUP_ID);
945
+ BIND_BITFIELD_FLAG (UNIX_RESTRICTED_DELETE);
880
946
}
0 commit comments