Преглед на файлове

Fix some bugs in diraccess, closes #5288

Juan Linietsky преди 9 години
родител
ревизия
ffbc2e56c9
променени са 3 файла, в които са добавени 34 реда и са изтрити 25 реда
  1. 17 14
      drivers/unix/dir_access_unix.cpp
  2. 10 10
      drivers/windows/dir_access_windows.cpp
  3. 7 1
      tools/editor/editor_dir_dialog.cpp

+ 17 - 14
drivers/unix/dir_access_unix.cpp

@@ -67,8 +67,8 @@ bool DirAccessUnix::file_exists(String p_file) {
 
 	if (p_file.is_rel_path())
 		p_file=current_dir.plus_file(p_file);
-	else
-		p_file=fix_path(p_file);
+
+	p_file=fix_path(p_file);
 
 	struct stat flags;
 	bool success = 	(stat(p_file.utf8().get_data(),&flags)==0);
@@ -88,8 +88,8 @@ bool DirAccessUnix::dir_exists(String p_dir) {
 
 	if (p_dir.is_rel_path())
 		p_dir=get_current_dir().plus_file(p_dir);
-	else
-		p_dir=fix_path(p_dir);
+
+	p_dir=fix_path(p_dir);
 
 	struct stat flags;
 	bool success = 	(stat(p_dir.utf8().get_data(),&flags)==0);
@@ -105,8 +105,8 @@ uint64_t DirAccessUnix::get_modified_time(String p_file) {
 
 	if (p_file.is_rel_path())
 		p_file=current_dir.plus_file(p_file);
-	else
-		p_file=fix_path(p_file);
+
+	p_file=fix_path(p_file);
 
 	struct stat flags;
 	bool success = 	(stat(p_file.utf8().get_data(),&flags)==0);
@@ -201,8 +201,11 @@ Error DirAccessUnix::make_dir(String p_dir) {
 
 	if (p_dir.is_rel_path())
 		p_dir=get_current_dir().plus_file(p_dir);
-	else
-		p_dir=fix_path(p_dir);
+
+
+	p_dir=fix_path(p_dir);
+
+
 #if 1
 
 
@@ -287,13 +290,13 @@ Error DirAccessUnix::rename(String p_path,String p_new_path) {
 
 	if (p_path.is_rel_path())
 		p_path=get_current_dir().plus_file(p_path);
-	else
-		p_path=fix_path(p_path);
+
+	p_path=fix_path(p_path);
 
 	if (p_new_path.is_rel_path())
 		p_new_path=get_current_dir().plus_file(p_new_path);
-	else
-		p_new_path=fix_path(p_new_path);
+
+	p_new_path=fix_path(p_new_path);
 
 	return ::rename(p_path.utf8().get_data(),p_new_path.utf8().get_data())==0?OK:FAILED;
 }
@@ -301,8 +304,8 @@ Error DirAccessUnix::remove(String p_path)  {
 
 	if (p_path.is_rel_path())
 		p_path=get_current_dir().plus_file(p_path);
-	else
-		p_path=fix_path(p_path);
+
+	p_path=fix_path(p_path);
 
 	struct stat flags;
 	if ((stat(p_path.utf8().get_data(),&flags)!=0))

+ 10 - 10
drivers/windows/dir_access_windows.cpp

@@ -193,8 +193,8 @@ Error DirAccessWindows::make_dir(String p_dir) {
 
 	if (p_dir.is_rel_path())
 		p_dir=get_current_dir().plus_file(p_dir);
-	else
-		p_dir=fix_path(p_dir);
+
+	p_dir=fix_path(p_dir);
 	p_dir = p_dir.replace("/","\\");
 
 	bool success;
@@ -268,8 +268,8 @@ bool DirAccessWindows::dir_exists(String p_dir) {
 
 	if (p_dir.is_rel_path())
 		p_dir=get_current_dir().plus_file(p_dir);
-	else
-		p_dir=fix_path(p_dir);
+
+	p_dir=fix_path(p_dir);
 
 	//p_dir.replace("/","\\");
 
@@ -289,13 +289,13 @@ Error DirAccessWindows::rename(String p_path,String p_new_path) {
 
 	if (p_path.is_rel_path())
 		p_path=get_current_dir().plus_file(p_path);
-	else
-		p_path=fix_path(p_path);
+
+	p_path=fix_path(p_path);
 
 	if (p_new_path.is_rel_path())
 		p_new_path=get_current_dir().plus_file(p_new_path);
-	else
-		p_new_path=fix_path(p_new_path);
+
+	p_new_path=fix_path(p_new_path);
 
 	if (file_exists(p_new_path)) {
 		if (remove(p_new_path) != OK) {
@@ -310,8 +310,8 @@ Error DirAccessWindows::remove(String p_path)  {
 
 	if (p_path.is_rel_path())
 		p_path=get_current_dir().plus_file(p_path);
-	else
-		p_path=fix_path(p_path);
+
+	p_path=fix_path(p_path);
 
 
 	printf("erasing %s\n",p_path.utf8().get_data());

+ 7 - 1
tools/editor/editor_dir_dialog.cpp

@@ -191,10 +191,14 @@ void EditorDirDialog::ok_pressed() {
 void EditorDirDialog::_make_dir() {
 
 	TreeItem *ti=tree->get_selected();
-	if (!ti)
+	if (!ti) {
+		mkdirerr->set_text("Please select a base directory first");
+		mkdirerr->popup_centered_minsize();
 		return;
+	}
 
 	makedialog->popup_centered_minsize(Size2(250,80));
+	makedirname->grab_focus();
 }
 
 void EditorDirDialog::_make_dir_confirm() {
@@ -204,9 +208,11 @@ void EditorDirDialog::_make_dir_confirm() {
 		return;
 
 	String dir = ti->get_metadata(0);
+
 	DirAccess *d = DirAccess::open(dir);
 	ERR_FAIL_COND(!d);
 	Error err = d->make_dir(makedirname->get_text());
+
 	if (err!=OK) {
 		mkdirerr->popup_centered_minsize(Size2(250,80));
 	} else {