Skip to content

Commit

Permalink
Reserve gdscript protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
TML233 committed Oct 28, 2024
1 parent 2c258a8 commit 0d7d661
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/io/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "filesystem.h"
#include "filesystem_protocol_placeholder.h"
#include "filesystem_protocol_resources.h"
#include "filesystem_protocol_user.h"

Expand All @@ -49,6 +50,7 @@ String FileSystem::protocol_name_os = "os";
String FileSystem::protocol_name_pipe = "pipe";
String FileSystem::protocol_name_resources = "res";
String FileSystem::protocol_name_user = "user";
String FileSystem::protocol_name_gdscript = "gdscript";
String FileSystem::protocol_name_memory = "mem";

bool FileSystem::has_protocol(const String &p_name) const {
Expand Down Expand Up @@ -189,6 +191,12 @@ void FileSystem::register_protocols() {
Ref<FileSystemProtocolResources> protocol_resources = Ref<FileSystemProtocolResources>();
protocol_resources.instantiate(protocol_os);
add_protocol(protocol_name_resources, protocol_resources);

// We reserve gdscript:// since it is used for marking a script instance in memory.
// This is the simpliest way to prevent stepping in the old code.
Ref<FileSystemProtocolPlaceholder> protocol_gdscript = Ref<FileSystemProtocolPlaceholder>();
protocol_gdscript.instantiate();
add_protocol(protocol_name_gdscript, protocol_gdscript);
}

uint64_t FileSystem::get_modified_time(const String &p_path) const {
Expand Down
1 change: 1 addition & 0 deletions core/io/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class FileSystem : public Object {
static String protocol_name_pipe;
static String protocol_name_resources;
static String protocol_name_user;
static String protocol_name_gdscript;
static String protocol_name_memory;

FileSystem();
Expand Down
55 changes: 55 additions & 0 deletions core/io/filesystem_protocol_placeholder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**************************************************************************/
/* filesystem_protocol_placeholder.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef FILESYSTEM_PROTOCOL_PLACEHOLDER_H
#define FILESYSTEM_PROTOCOL_PLACEHOLDER_H

#include "core/io/filesystem_protocol.h"

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

public:
virtual Ref<FileAccess> open_file(const String &p_path, int p_mode_flags, Error &r_error) const override {
r_error = ERR_FILE_NOT_FOUND;
return Ref<FileAccess>();
}
virtual bool file_exists(const String &p_path) const override { return false; }

virtual uint64_t get_modified_time(const String &p_path) const override { return 0; }
virtual BitField<FileAccess::UnixPermissionFlags> get_unix_permissions(const String &p_path) const override { return 0; }
virtual Error set_unix_permissions(const String &p_path, BitField<FileAccess::UnixPermissionFlags> p_permissions) const override { return ERR_UNAVAILABLE; }
virtual bool get_hidden_attribute(const String &p_path) const override { return false; }
virtual Error set_hidden_attribute(const String &p_path, bool p_hidden) const override { return ERR_UNAVAILABLE; }
virtual bool get_read_only_attribute(const String &p_path) const override { return 0; }
virtual Error set_read_only_attribute(const String &p_path, bool p_ro) const override { return ERR_UNAVAILABLE; }
};

#endif // FILESYSTEM_PROTOCOL_PLACEHOLDER_H

0 comments on commit 0d7d661

Please sign in to comment.