瀏覽代碼

Revert "Follow-Up Fix Directory Open"

This reverts commit ec787f01340ff37840580dd21401456123670e83.
Nathan Franke 5 年之前
父節點
當前提交
9de0439a45
共有 2 個文件被更改,包括 9 次插入16 次删除
  1. 8 13
      core/bind/core_bind.cpp
  2. 1 3
      doc/classes/Directory.xml

+ 8 - 13
core/bind/core_bind.cpp

@@ -2421,15 +2421,8 @@ int _Directory::get_current_drive() {
 }
 
 Error _Directory::change_dir(String 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;
+	ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
+	return d->change_dir(p_dir);
 }
 String _Directory::get_current_dir() {
 	ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");
@@ -2457,7 +2450,8 @@ Error _Directory::make_dir_recursive(String p_dir) {
 }
 
 bool _Directory::file_exists(String p_file) {
-	ERR_FAIL_COND_V_MSG(!d, false, "Directory is not configured properly.");
+	ERR_FAIL_COND_V_MSG(!is_open(), false, "Directory must be opened before use.");
+
 	if (!p_file.is_rel_path()) {
 		return FileAccess::exists(p_file);
 	}
@@ -2466,16 +2460,17 @@ bool _Directory::file_exists(String p_file) {
 }
 
 bool _Directory::dir_exists(String p_dir) {
-	ERR_FAIL_COND_V_MSG(!d, false, "Directory is not configured properly.");
+	ERR_FAIL_COND_V_MSG(!is_open(), false, "Directory must be opened before use.");
 	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;
-	}
 
-	return d->dir_exists(p_dir);
+	} else {
+		return d->dir_exists(p_dir);
+	}
 }
 
 int _Directory::get_space_left() {

+ 1 - 3
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], 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].
+		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.
 		Here is an example on how to iterate through the files of a directory:
 		[codeblock]
 		func dir_contents(path):
@@ -63,7 +63,6 @@
 			</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">
@@ -73,7 +72,6 @@
 			</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">