Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
TML233 committed Oct 26, 2024
1 parent 5f9a659 commit b3b2029
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 68 deletions.
4 changes: 2 additions & 2 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#include "core/input/input_map.h"
#include "core/io/config_file.h"
#include "core/io/dir_access.h"
#include "core/io/filesystem.h"
#include "core/io/file_access.h"
#include "core/io/file_access_pack.h"
#include "core/io/filesystem.h"
#include "core/io/marshalls.h"
#include "core/io/resource_uid.h"
#include "core/object/script_language.h"
Expand Down Expand Up @@ -156,7 +156,7 @@ String ProjectSettings::localize_path(const String &p_path) const {
}

// Check if we have a special path (like res://) or a protocol identifier.
bool found=FileSystem::try_find_protocol_in_path(path,nullptr,nullptr);
bool found = FileSystem::try_find_protocol_in_path(path, nullptr, nullptr);
if (found) {
return path;
}
Expand Down
1 change: 0 additions & 1 deletion core/io/file_access_compressed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ void FileAccessCompressed::store_buffer(const uint8_t *p_src, uint64_t p_length)
write_pos += p_length;
}


void FileAccessCompressed::close() {
_close();
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,4 @@ void FileSystem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_hidden_attribute", "path", "hidden"), &FileSystem::set_hidden_attribute);
ClassDB::bind_method(D_METHOD("get_read_only_attribute", "path"), &FileSystem::get_read_only_attribute);
ClassDB::bind_method(D_METHOD("set_read_only_attribute", "path", "ro"), &FileSystem::set_read_only_attribute);
}
}
13 changes: 6 additions & 7 deletions core/io/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class FileSystem : public Object {

HashMap<String, Ref<FileSystemProtocol>> protocols;


// for paths that doesn't have the protocol part, it fallsback to host://
// if r_protocol returns null, the protocol of the path targeted is invalid.
void process_path(const String &p_path, String *r_protocol_name, Ref<FileSystemProtocol> *r_protocol, String *r_file_path) const;
Expand All @@ -60,15 +59,15 @@ class FileSystem : public Object {

public:
// out values are only valid when method returns true
static bool try_find_protocol_in_path(const String& p_path,int* r_protocol_name_end,int* r_file_path_start);
static bool try_find_protocol_in_path(const String &p_path, int *r_protocol_name_end, int *r_file_path_start);
// returns whether it found a protocol present in the path
static bool split_path(const String &p_path, String *r_protocol_name, String *r_file_path);

static String protocol_name_os;
static String protocol_name_pipe;
static String protocol_name_resources;
static String protocol_name_user;
static String protocol_name_memory;
static String protocol_name_memory;

FileSystem();
~FileSystem();
Expand All @@ -81,13 +80,13 @@ class FileSystem : public Object {
Ref<FileSystemProtocol> get_protocol_or_null(const String &p_name) const;

// Basic path fix. Replaces FileAccess::fix_path.
static String fix_path(const String& p_path);
static String fix_path(const String &p_path);

Error get_open_error() const;

String globalize_path(const String& path) const;
String globalize_path(const String &path) const;

Ref<FileAccess> open_file(const String &p_path, int p_mode_flags, Error *r_error=nullptr) const;
Ref<FileAccess> open_file(const String &p_path, int p_mode_flags, Error *r_error = nullptr) const;
bool file_exists(const String &p_path) const;

uint64_t get_modified_time(const String &p_path) const;
Expand All @@ -99,4 +98,4 @@ class FileSystem : public Object {
Error set_read_only_attribute(const String &p_path, bool p_ro) const;
};

#endif // FILESYSTEM_H
#endif // FILESYSTEM_H
20 changes: 10 additions & 10 deletions core/io/filesystem_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ Ref<FileAccess> FileSystemProtocol::_open_file(const String &p_path, int p_mode_
return open_file(p_path, p_mode_flags, open_error);
}

String FileSystemProtocol::globalize_path(const String& p_path) const {
String FileSystemProtocol::globalize_path(const String &p_path) const {
return p_path;
}

void FileSystemProtocol::disguise_file(const Ref<FileAccess> &p_file, const String &p_protocol_name, const String &p_path) const {
p_file->set_path_disguise(p_protocol_name+"://"+p_path);
p_file->set_path_disguise(p_protocol_name + "://" + p_path);
}

void FileSystemProtocol::_bind_methods(){
void FileSystemProtocol::_bind_methods() {
ClassDB::bind_method(D_METHOD("globalize_path", "path"), &FileSystemProtocol::globalize_path);

ClassDB::bind_method(D_METHOD("get_open_error"), &FileSystemProtocol::get_open_error);
ClassDB::bind_method(D_METHOD("open_file", "path","mode_flags"), &FileSystemProtocol::_open_file);
ClassDB::bind_method(D_METHOD("open_file", "path", "mode_flags"), &FileSystemProtocol::_open_file);
ClassDB::bind_method(D_METHOD("file_exists", "name"), &FileSystemProtocol::file_exists);

ClassDB::bind_method(D_METHOD("get_modified_time", "path"), &FileSystemProtocol::get_modified_time);
ClassDB::bind_method(D_METHOD("get_unix_permissions", "path"), &FileSystemProtocol::get_unix_permissions);
ClassDB::bind_method(D_METHOD("set_unix_permissions", "path","permissions"), &FileSystemProtocol::set_unix_permissions);
ClassDB::bind_method(D_METHOD("set_unix_permissions", "path", "permissions"), &FileSystemProtocol::set_unix_permissions);
ClassDB::bind_method(D_METHOD("get_hidden_attribute", "path"), &FileSystemProtocol::get_hidden_attribute);
ClassDB::bind_method(D_METHOD("set_hidden_attribute", "path","hidden"), &FileSystemProtocol::set_hidden_attribute);
ClassDB::bind_method(D_METHOD("set_hidden_attribute", "path", "hidden"), &FileSystemProtocol::set_hidden_attribute);
ClassDB::bind_method(D_METHOD("get_read_only_attribute", "path"), &FileSystemProtocol::get_read_only_attribute);
ClassDB::bind_method(D_METHOD("set_read_only_attribute", "path","ro"), &FileSystemProtocol::set_read_only_attribute);
}
ClassDB::bind_method(D_METHOD("set_read_only_attribute", "path", "ro"), &FileSystemProtocol::set_read_only_attribute);
}
2 changes: 1 addition & 1 deletion core/io/filesystem_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ class FileSystemProtocol : public RefCounted {
virtual Error set_read_only_attribute(const String &p_path, bool p_ro) const = 0;
};

#endif // FILESYSTEM_PROTOCOL_H
#endif // FILESYSTEM_PROTOCOL_H
12 changes: 6 additions & 6 deletions core/io/filesystem_protocol_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

#include "filesystem_protocol_resources.h"
#include "core/config/project_settings.h"
#include "core/io/filesystem.h"
#include "core/io/file_access_pack.h"
#include "core/io/filesystem.h"
#include "core/os/os.h"

FileSystemProtocolResources::FileSystemProtocolResources() {}
Expand Down Expand Up @@ -69,7 +69,7 @@ bool FileSystemProtocolResources::file_exists(const String &p_path) const {
// TODO: Replace this with resource mounting stack

//try packed data first
if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path("res://"+p_path)) {
if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path("res://" + p_path)) {
return true;
}

Expand All @@ -81,15 +81,15 @@ uint64_t FileSystemProtocolResources::get_modified_time(const String &p_path) co
if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && (PackedData::get_singleton()->has_path(p_path) || PackedData::get_singleton()->has_directory(p_path))) {
return 0;
}

String path = globalize_path(p_path);
return protocol_os->get_modified_time(path);
}
BitField<FileAccess::UnixPermissionFlags> FileSystemProtocolResources::get_unix_permissions(const String &p_path) const {
if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && (PackedData::get_singleton()->has_path(p_path) || PackedData::get_singleton()->has_directory(p_path))) {
return 0;
}

String path = globalize_path(p_path);
return protocol_os->get_unix_permissions(path);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ Error FileSystemProtocolResources::set_read_only_attribute(const String &p_path,
if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && (PackedData::get_singleton()->has_path(p_path) || PackedData::get_singleton()->has_directory(p_path))) {
return ERR_UNAVAILABLE;
}

String path = globalize_path(p_path);
return protocol_os->set_read_only_attribute(path, p_ro);
}
}
10 changes: 5 additions & 5 deletions core/io/filesystem_protocol_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@

#include "core/io/filesystem_protocol.h"


class FileSystemProtocolResources : public FileSystemProtocol {
GDCLASS(FileSystemProtocolResources, FileSystemProtocol);

private:
Ref<FileSystemProtocol> protocol_os;

public:
FileSystemProtocolResources();
FileSystemProtocolResources(const Ref<FileSystemProtocol>& p_protocol_os);
FileSystemProtocolResources(const Ref<FileSystemProtocol> &p_protocol_os);

void set_protocol_os(const Ref<FileSystemProtocol>& p_protocol_os);
void set_protocol_os(const Ref<FileSystemProtocol> &p_protocol_os);

virtual String globalize_path(const String& p_path) const override;
virtual String globalize_path(const String &p_path) const override;

virtual Ref<FileAccess> open_file(const String &p_path, int p_mode_flags, Error &r_error) const override;
virtual bool file_exists(const String &p_path) const override;
Expand All @@ -59,4 +59,4 @@ class FileSystemProtocolResources : public FileSystemProtocol {
virtual Error set_read_only_attribute(const String &p_path, bool p_ro) const override;
};

#endif // FILESYSTEM_PROTOCOL_RESOURCES_H
#endif // FILESYSTEM_PROTOCOL_RESOURCES_H
2 changes: 1 addition & 1 deletion core/io/filesystem_protocol_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ bool FileSystemProtocolUser::get_read_only_attribute(const String &p_path) const
Error FileSystemProtocolUser::set_read_only_attribute(const String &p_path, bool p_ro) const {
String path = globalize_path(p_path);
return protocol_os->set_read_only_attribute(path, p_ro);
}
}
10 changes: 5 additions & 5 deletions core/io/filesystem_protocol_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@

#include "core/io/filesystem_protocol.h"


class FileSystemProtocolUser : public FileSystemProtocol {
GDCLASS(FileSystemProtocolUser, FileSystemProtocol);

private:
Ref<FileSystemProtocol> protocol_os;

public:
FileSystemProtocolUser();
FileSystemProtocolUser(const Ref<FileSystemProtocol>& p_protocol_os);
FileSystemProtocolUser(const Ref<FileSystemProtocol> &p_protocol_os);

void set_protocol_os(const Ref<FileSystemProtocol>& p_protocol_os);
void set_protocol_os(const Ref<FileSystemProtocol> &p_protocol_os);

virtual String globalize_path(const String& p_path) const override;
virtual String globalize_path(const String &p_path) const override;

virtual Ref<FileAccess> open_file(const String &p_path, int p_mode_flags, Error &r_error) const override;
virtual bool file_exists(const String &p_path) const override;
Expand All @@ -59,4 +59,4 @@ class FileSystemProtocolUser : public FileSystemProtocol {
virtual Error set_read_only_attribute(const String &p_path, bool p_ro) const override;
};

#endif // FILESYSTEM_PROTOCOL_USER_H
#endif // FILESYSTEM_PROTOCOL_USER_H
2 changes: 1 addition & 1 deletion core/register_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
#include "core/input/shortcut.h"
#include "core/io/config_file.h"
#include "core/io/dir_access.h"
#include "core/io/dtls_server.h"
#include "core/io/filesystem.h"
#include "core/io/filesystem_protocol.h"
#include "core/io/dtls_server.h"
#include "core/io/http_client.h"
#include "core/io/image_loader.h"
#include "core/io/json.h"
Expand Down
14 changes: 7 additions & 7 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#include "ustring.h"

#include "core/crypto/crypto_core.h"
#include "core/io/filesystem.h"
#include "core/math/color.h"
#include "core/math/math_funcs.h"
#include "core/os/memory.h"
#include "core/io/filesystem.h"
#include "core/string/print_string.h"
#include "core/string/string_name.h"
#include "core/string/translation_server.h"
Expand Down Expand Up @@ -4512,12 +4512,12 @@ String String::simplify_path() const {
String drive;

// Check if we have a special path (like res://) or a protocol identifier.
int file_path_start=0;
bool found=FileSystem::try_find_protocol_in_path(s,nullptr,&file_path_start);
if(found){
drive=s.substr(0,file_path_start);
s=s.substr(file_path_start);
}else{
int file_path_start = 0;
bool found = FileSystem::try_find_protocol_in_path(s, nullptr, &file_path_start);
if (found) {
drive = s.substr(0, file_path_start);
s = s.substr(file_path_start);
} else {
if (is_network_share_path()) {
// Network path, beginning with // or \\.
drive = s.substr(0, 2);
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/file_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Error FileAccessWindows::open_internal(const String &p_path, int p_mode_flags) {
}

// TODO: reimplement this in protocol level
#if 0//TOOLS_ENABLED
#if 0 //TOOLS_ENABLED
// Windows is case insensitive, but all other platforms are sensitive to it
// To ease cross-platform development, we issue a warning if users try to access
// a file using the wrong case (which *works* on Windows, but won't on other
Expand Down
24 changes: 12 additions & 12 deletions drivers/windows/filesystem_protocol_os_windows.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* filesystem_protocol_os_windows.h */
/* filesystem_protocol_os_windows.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -96,13 +96,13 @@ bool FileSystemProtocolOSWindows::file_exists_static(const String &p_path) {
return true;
}
}
BitField<FileAccess::UnixPermissionFlags> FileSystemProtocolOSWindows::get_unix_permissions_static(const String &p_path){
BitField<FileAccess::UnixPermissionFlags> FileSystemProtocolOSWindows::get_unix_permissions_static(const String &p_path) {
return 0;
}
Error FileSystemProtocolOSWindows::set_unix_permissions_static(const String &p_path, BitField<FileAccess::UnixPermissionFlags> p_permissions){
Error FileSystemProtocolOSWindows::set_unix_permissions_static(const String &p_path, BitField<FileAccess::UnixPermissionFlags> p_permissions) {
return ERR_UNAVAILABLE;
}
uint64_t FileSystemProtocolOSWindows::get_modified_time_static(const String& p_path){
uint64_t FileSystemProtocolOSWindows::get_modified_time_static(const String &p_path) {
if (is_path_invalid(p_path)) {
return 0;
}
Expand Down Expand Up @@ -147,14 +147,14 @@ uint64_t FileSystemProtocolOSWindows::get_modified_time_static(const String& p_p
return 0;
}

bool FileSystemProtocolOSWindows::get_hidden_attribute_static(const String& p_path){
bool FileSystemProtocolOSWindows::get_hidden_attribute_static(const String &p_path) {
String file = fix_path(p_path);

DWORD attrib = GetFileAttributesW((LPCWSTR)file.utf16().get_data());
ERR_FAIL_COND_V_MSG(attrib == INVALID_FILE_ATTRIBUTES, false, "Failed to get attributes for: " + p_path);
return (attrib & FILE_ATTRIBUTE_HIDDEN);
}
Error FileSystemProtocolOSWindows::set_hidden_attribute_static(const String& p_path,bool p_hidden){
Error FileSystemProtocolOSWindows::set_hidden_attribute_static(const String &p_path, bool p_hidden) {
String file = fix_path(p_path);
const Char16String &file_utf16 = file.utf16();

Expand All @@ -170,14 +170,14 @@ Error FileSystemProtocolOSWindows::set_hidden_attribute_static(const String& p_p

return OK;
}
bool FileSystemProtocolOSWindows::get_read_only_attribute_static(const String& p_path){
bool FileSystemProtocolOSWindows::get_read_only_attribute_static(const String &p_path) {
String file = fix_path(p_path);

DWORD attrib = GetFileAttributesW((LPCWSTR)file.utf16().get_data());
ERR_FAIL_COND_V_MSG(attrib == INVALID_FILE_ATTRIBUTES, false, "Failed to get attributes for: " + p_path);
return (attrib & FILE_ATTRIBUTE_READONLY);
}
Error FileSystemProtocolOSWindows::set_read_only_attribute_static(const String& p_path,bool p_ro){
Error FileSystemProtocolOSWindows::set_read_only_attribute_static(const String &p_path, bool p_ro) {
String file = fix_path(p_path);
const Char16String &file_utf16 = file.utf16();

Expand All @@ -197,7 +197,7 @@ Error FileSystemProtocolOSWindows::set_read_only_attribute_static(const String&
Ref<FileAccess> FileSystemProtocolOSWindows::open_file(const String &p_path, int p_mode_flags, Error &r_error) const {
Ref<FileAccessWindows> file = Ref<FileAccessWindows>();
file.instantiate();

r_error = file->open_internal(p_path, p_mode_flags);

if (r_error != OK) {
Expand All @@ -217,18 +217,18 @@ BitField<FileAccess::UnixPermissionFlags> FileSystemProtocolOSWindows::get_unix_
return get_unix_permissions_static(p_path);
}
Error FileSystemProtocolOSWindows::set_unix_permissions(const String &p_path, BitField<FileAccess::UnixPermissionFlags> p_permissions) const {
return set_unix_permissions_static(p_path,p_permissions);
return set_unix_permissions_static(p_path, p_permissions);
}
bool FileSystemProtocolOSWindows::get_hidden_attribute(const String &p_path) const {
return get_hidden_attribute_static(p_path);
}
Error FileSystemProtocolOSWindows::set_hidden_attribute(const String &p_path, bool p_hidden) const {
return set_hidden_attribute_static(p_path,p_hidden);
return set_hidden_attribute_static(p_path, p_hidden);
}
bool FileSystemProtocolOSWindows::get_read_only_attribute(const String &p_path) const {
return get_read_only_attribute_static(p_path);
}
Error FileSystemProtocolOSWindows::set_read_only_attribute(const String &p_path, bool p_ro) const {
return set_read_only_attribute_static(p_path,p_ro);
return set_read_only_attribute_static(p_path, p_ro);
}
#endif // WINDOWS_ENABLED
2 changes: 1 addition & 1 deletion drivers/windows/filesystem_protocol_os_windows.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* filesystem_protocol_os_windows.cpp */
/* filesystem_protocol_os_windows.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down
Loading

0 comments on commit b3b2029

Please sign in to comment.