Skip to content

Commit

Permalink
Merge pull request #65066 from aaronfranke/str-path-join
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Aug 30, 2022
2 parents 0b5d728 + 10a5698 commit 432b25d
Show file tree
Hide file tree
Showing 100 changed files with 519 additions and 519 deletions.
28 changes: 14 additions & 14 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ String ProjectSettings::get_safe_project_name() const {
}

String ProjectSettings::get_imported_files_path() const {
return get_project_data_path().plus_file("imported");
return get_project_data_path().path_join("imported");
}

// Returns the features that a project must have when opened with this build of Godot.
Expand Down Expand Up @@ -157,12 +157,12 @@ String ProjectSettings::localize_path(const String &p_path) const {
// in an absolute path that just happens to contain this string but points to a
// different folder (e.g. "/my/project" as resource_path would be contained in
// "/my/project_data", even though the latter is not part of res://.
// `plus_file("")` is an easy way to ensure we have a trailing '/'.
const String res_path = resource_path.plus_file("");
// `path_join("")` is an easy way to ensure we have a trailing '/'.
const String res_path = resource_path.path_join("");

// DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
// so we must make sure we have it as well in order to compare with 'res_path'.
cwd = cwd.plus_file("");
cwd = cwd.path_join("");

if (!cwd.begins_with(res_path)) {
return p_path;
Expand Down Expand Up @@ -472,7 +472,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
if (err == OK && !p_ignore_override) {
// Load override from location of the main pack
// Optional, we don't mind if it fails
_load_settings_text(p_main_pack.get_base_dir().plus_file("override.cfg"));
_load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
}
return err;
}
Expand Down Expand Up @@ -500,14 +500,14 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
#ifdef MACOS_ENABLED
if (!found) {
// Attempt to load PCK from macOS .app bundle resources.
found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_filename + ".pck"));
found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"));
}
#endif

if (!found) {
// Try to load data pack at the location of the executable.
// As mentioned above, we have two potential names to attempt.
found = _load_resource_pack(exec_dir.plus_file(exec_basename + ".pck")) || _load_resource_pack(exec_dir.plus_file(exec_filename + ".pck"));
found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck")) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"));
}

if (!found) {
Expand All @@ -523,7 +523,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
// Load overrides from the PCK and the executable location.
// Optional, we don't mind if either fails.
_load_settings_text("res://override.cfg");
_load_settings_text(exec_path.get_base_dir().plus_file("override.cfg"));
_load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
}
return err;
}
Expand Down Expand Up @@ -556,10 +556,10 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
// Set the resource path early so things can be resolved when loading.
resource_path = current_dir;
resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary"));
if (err == OK && !p_ignore_override) {
// Optional, we don't mind if it fails.
_load_settings_text(current_dir.plus_file("override.cfg"));
_load_settings_text(current_dir.path_join("override.cfg"));
found = true;
break;
}
Expand Down Expand Up @@ -685,7 +685,7 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
// If we're loading a project.godot from source code, we can operate some
// ProjectSettings conversions if need be.
_convert_to_last_version(config_version);
last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
return OK;
}
ERR_FAIL_COND_V_MSG(err != OK, err, "Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
Expand Down Expand Up @@ -764,9 +764,9 @@ void ProjectSettings::clear(const String &p_name) {
}

Error ProjectSettings::save() {
Error error = save_custom(get_resource_path().plus_file("project.godot"));
Error error = save_custom(get_resource_path().path_join("project.godot"));
if (error == OK) {
last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
}
return error;
}
Expand Down Expand Up @@ -911,7 +911,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
}
}
// Check for the existence of a csproj file.
if (FileAccess::exists(get_resource_path().plus_file(get_safe_project_name() + ".csproj"))) {
if (FileAccess::exists(get_resource_path().path_join(get_safe_project_name() + ".csproj"))) {
// If there is a csproj file, add the C# feature if it doesn't already exist.
if (!project_features.has("C#")) {
project_features.append("C#");
Expand Down
4 changes: 2 additions & 2 deletions core/extension/native_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "core/os/os.h"

String NativeExtension::get_extension_list_config_file() {
return ProjectSettings::get_singleton()->get_project_data_path().plus_file("extension_list.cfg");
return ProjectSettings::get_singleton()->get_project_data_path().path_join("extension_list.cfg");
}

class NativeExtensionMethodBind : public MethodBind {
Expand Down Expand Up @@ -421,7 +421,7 @@ Ref<Resource> NativeExtensionResourceLoader::load(const String &p_path, const St
}

if (!library_path.is_resource_file() && !library_path.is_absolute_path()) {
library_path = p_path.get_base_dir().plus_file(library_path);
library_path = p_path.get_base_dir().path_join(library_path);
}

Ref<NativeExtension> lib;
Expand Down
14 changes: 7 additions & 7 deletions core/io/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static Error _erase_recursive(DirAccess *da) {
if (err) {
return err;
}
err = da->remove(da->get_current_dir().plus_file(E));
err = da->remove(da->get_current_dir().path_join(E));
if (err) {
return err;
}
Expand All @@ -116,7 +116,7 @@ static Error _erase_recursive(DirAccess *da) {
}

for (const String &E : files) {
Error err = da->remove(da->get_current_dir().plus_file(E));
Error err = da->remove(da->get_current_dir().path_join(E));
if (err) {
return err;
}
Expand All @@ -138,7 +138,7 @@ Error DirAccess::make_dir_recursive(String p_dir) {

if (p_dir.is_relative_path()) {
//append current
full_dir = get_current_dir().plus_file(p_dir);
full_dir = get_current_dir().path_join(p_dir);

} else {
full_dir = p_dir;
Expand Down Expand Up @@ -172,7 +172,7 @@ Error DirAccess::make_dir_recursive(String p_dir) {

String curpath = base;
for (int i = 0; i < subdirs.size(); i++) {
curpath = curpath.plus_file(subdirs[i]);
curpath = curpath.path_join(subdirs[i]);
Error err = make_dir(curpath);
if (err != OK && err != ERR_ALREADY_EXISTS) {
ERR_FAIL_V_MSG(err, "Could not create directory: " + curpath);
Expand Down Expand Up @@ -354,8 +354,8 @@ Error DirAccess::_copy_dir(Ref<DirAccess> &p_target_da, String p_to, int p_chmod
String n = get_next();
while (!n.is_empty()) {
if (n != "." && n != "..") {
if (p_copy_links && is_link(get_current_dir().plus_file(n))) {
create_link(read_link(get_current_dir().plus_file(n)), p_to + n);
if (p_copy_links && is_link(get_current_dir().path_join(n))) {
create_link(read_link(get_current_dir().path_join(n)), p_to + n);
} else if (current_is_dir()) {
dirs.push_back(n);
} else {
Expand All @@ -364,7 +364,7 @@ Error DirAccess::_copy_dir(Ref<DirAccess> &p_target_da, String p_to, int p_chmod
list_dir_end();
return ERR_BUG;
}
Error err = copy(get_current_dir().plus_file(n), p_to + rel_path, p_chmod_flags);
Error err = copy(get_current_dir().path_join(n), p_to + rel_path, p_chmod_flags);
if (err) {
list_dir_end();
return err;
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ String DirAccessPack::get_current_dir(bool p_include_drive) const {

while (pd->parent) {
pd = pd->parent;
p = pd->name.plus_file(p);
p = pd->name.path_join(p);
}

return "res://" + p;
Expand Down
6 changes: 3 additions & 3 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {

if (!path.contains("://") && path.is_relative_path()) {
// path is relative to file being loaded, so convert to a resource path
path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().path_join(path));
}

if (remaps.find(path)) {
Expand Down Expand Up @@ -683,7 +683,7 @@ Error ResourceLoaderBinary::load() {

if (!path.contains("://") && path.is_relative_path()) {
// path is relative to file being loaded, so convert to a resource path
path = ProjectSettings::get_singleton()->localize_path(path.get_base_dir().plus_file(external_resources[i].path));
path = ProjectSettings::get_singleton()->localize_path(path.get_base_dir().path_join(external_resources[i].path));
}

external_resources.write[i].path = path; //remap happens here, not on load because on load it can actually be used for filesystem dock resource remap
Expand Down Expand Up @@ -1329,7 +1329,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons

bool relative = false;
if (!path.begins_with("res://")) {
path = local_path.plus_file(path).simplify_path();
path = local_path.path_join(path).simplify_path();
relative = true;
}

Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const St
}

String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const {
return ProjectSettings::get_singleton()->get_imported_files_path().plus_file(p_for_file.get_file() + "-" + p_for_file.md5_text());
return ProjectSettings::get_singleton()->get_imported_files_path().path_join(p_for_file.get_file() + "-" + p_for_file.md5_text());
}

bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const {
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_uid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static constexpr uint32_t char_count = ('z' - 'a');
static constexpr uint32_t base = char_count + ('9' - '0');

String ResourceUID::get_cache_file() {
return ProjectSettings::get_singleton()->get_project_data_path().plus_file("uid_cache.bin");
return ProjectSettings::get_singleton()->get_project_data_path().path_join("uid_cache.bin");
}

String ResourceUID::id_to_text(ID p_id) const {
Expand Down
2 changes: 1 addition & 1 deletion core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4451,7 +4451,7 @@ String String::get_extension() const {
return substr(pos + 1, length());
}

String String::plus_file(const String &p_file) const {
String String::path_join(const String &p_file) const {
if (is_empty()) {
return p_file;
}
Expand Down
2 changes: 1 addition & 1 deletion core/string/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class String {
String rstrip(const String &p_chars) const;
String get_extension() const;
String get_basename() const;
String plus_file(const String &p_file) const;
String path_join(const String &p_file) const;
char32_t unicode_at(int p_idx) const;

void erase(int p_pos, int p_chars);
Expand Down
2 changes: 1 addition & 1 deletion core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ static void _register_variant_builtin_methods() {
bind_method(String, rstrip, sarray("chars"), varray());
bind_method(String, get_extension, sarray(), varray());
bind_method(String, get_basename, sarray(), varray());
bind_method(String, plus_file, sarray("file"), varray());
bind_method(String, path_join, sarray("file"), varray());
bind_method(String, unicode_at, sarray("at"), varray());
bind_method(String, indent, sarray("prefix"), varray());
bind_method(String, dedent, sarray(), varray());
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# `path` will contain the absolute path to `hello.txt` next to the executable.
# This is *not* identical to using `ProjectSettings.globalize_path()` with a `res://` path,
# but is close enough in spirit.
path = OS.get_executable_path().get_base_dir().plus_file("hello.txt")
path = OS.get_executable_path().get_base_dir().path_join("hello.txt")
[/codeblock]
</description>
</method>
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/String.xml
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,11 @@
Formats a number to have an exact number of [param digits] before the decimal point.
</description>
</method>
<method name="plus_file" qualifiers="const">
<method name="path_join" qualifiers="const">
<return type="String" />
<param index="0" name="file" type="String" />
<description>
If the string is a path, this concatenates [param file] at the end of the string as a subpath. E.g. [code]"this/is".plus_file("path") == "this/is/path"[/code].
If the string is a path, this concatenates [param file] at the end of the string as a subpath. E.g. [code]"this/is".path_join("path") == "this/is/path"[/code].
</description>
</method>
<method name="repeat" qualifiers="const">
Expand Down
4 changes: 2 additions & 2 deletions drivers/gles3/shader_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ String ShaderGLES3::_version_get_sha1(Version *p_version) const {
bool ShaderGLES3::_load_from_cache(Version *p_version) {
#if 0
String sha1 = _version_get_sha1(p_version);
String path = shader_cache_dir.plus_file(name).plus_file(base_sha256).plus_file(sha1) + ".cache";
String path = shader_cache_dir.path_join(name).path_join(base_sha256).path_join(sha1) + ".cache";

Ref<FileAccess> f = FileAccess::open(path, FileAccess::READ);
if (f.is_null()) {
Expand Down Expand Up @@ -538,7 +538,7 @@ bool ShaderGLES3::_load_from_cache(Version *p_version) {
void ShaderGLES3::_save_to_cache(Version *p_version) {
#if 0
String sha1 = _version_get_sha1(p_version);
String path = shader_cache_dir.plus_file(name).plus_file(base_sha256).plus_file(sha1) + ".cache";
String path = shader_cache_dir.path_join(name).path_join(base_sha256).path_join(sha1) + ".cache";

Ref<FileAccess> f = FileAccess::open(path, FileAccess::WRITE);
ERR_FAIL_COND(f.is_null());
Expand Down
Loading

0 comments on commit 432b25d

Please sign in to comment.