summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-07-10 10:21:03 +0200
committerGitHub <noreply@github.com>2020-07-10 10:21:03 +0200
commit1282b8201fc22782e6566f080a030e1682b3778e (patch)
tree11eab27469e7b4f8e372e428f96764292345e101
parent2638168da8fc357b9edde62cc0a08aae4f9fead5 (diff)
parent6952458538ad669922614eb15a9ece45c0a235e3 (diff)
Merge pull request #40243 from nathanfranke/fix-regression-directory-open-check
Follow-Up Fix Directory Open
-rw-r--r--core/bind/core_bind.cpp21
-rw-r--r--doc/classes/Directory.xml4
2 files changed, 16 insertions, 9 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 6df8dd380a..94da74cbda 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1673,8 +1673,15 @@ int _Directory::get_current_drive() {
}
Error _Directory::change_dir(String p_dir) {
- ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
- return d->change_dir(p_dir);
+ ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory is not configured properly.");
+ Error err = d->change_dir(p_dir);
+
+ if (err != OK) {
+ return err;
+ }
+ dir_open = true;
+
+ return OK;
}
String _Directory::get_current_dir() {
@@ -1705,8 +1712,7 @@ Error _Directory::make_dir_recursive(String p_dir) {
}
bool _Directory::file_exists(String p_file) {
- ERR_FAIL_COND_V_MSG(!is_open(), false, "Directory must be opened before use.");
-
+ ERR_FAIL_COND_V_MSG(!d, false, "Directory is not configured properly.");
if (!p_file.is_rel_path()) {
return FileAccess::exists(p_file);
}
@@ -1715,16 +1721,15 @@ bool _Directory::file_exists(String p_file) {
}
bool _Directory::dir_exists(String p_dir) {
- ERR_FAIL_COND_V_MSG(!is_open(), false, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!d, false, "Directory is not configured properly.");
if (!p_dir.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_dir);
bool exists = d->dir_exists(p_dir);
memdelete(d);
return exists;
-
- } else {
- return d->dir_exists(p_dir);
}
+
+ return d->dir_exists(p_dir);
}
int _Directory::get_space_left() {
diff --git a/doc/classes/Directory.xml b/doc/classes/Directory.xml
index ed4257a809..a86dbfedde 100644
--- a/doc/classes/Directory.xml
+++ b/doc/classes/Directory.xml
@@ -5,7 +5,7 @@
</brief_description>
<description>
Directory type. It is used to manage directories and their content (not restricted to the project folder).
- When creating a new [Directory], its default opened directory will be [code]res://[/code]. This may change in the future, so it is advised to always use [method open] to initialize your [Directory] where you want to operate, with explicit error checking.
+ When creating a new [Directory], it must be explicitly opened using [method open] before most methods can be used. However, [method file_exists] and [method dir_exists] can be used without opening a directory. If so, they use a path relative to [code]res://[/code].
Here is an example on how to iterate through the files of a directory:
[codeblock]
func dir_contents(path):
@@ -63,6 +63,7 @@
</argument>
<description>
Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path.
+ If the [Directory] is not open, the path is relative to [code]res://[/code].
</description>
</method>
<method name="file_exists">
@@ -72,6 +73,7 @@
</argument>
<description>
Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path.
+ If the [Directory] is not open, the path is relative to [code]res://[/code].
</description>
</method>
<method name="get_current_dir">