Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
return ".";
}

String OS::expand_path(const String &p_path) const {
return p_path;
}

void OS::create_lock_file() {
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return;
Expand Down
2 changes: 2 additions & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ class OS {

virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;

virtual String expand_path(const String &p_path) const;

virtual Error move_to_trash(const String &p_path) { return FAILED; }

void create_lock_file();
Expand Down
13 changes: 13 additions & 0 deletions drivers/unix/os_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,19 @@ String OS_Unix::get_executable_path() const {
#endif
}

String OS_Unix::expand_path(const String &p_path) const {
String path = p_path;

if (path.begins_with("~/") || path == "~") {
String home = get_environment("HOME");
if (!home.is_empty()) {
path = home + path.substr(1);
}
}

return path;
}

void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type, const Vector<Ref<ScriptBacktrace>> &p_script_backtraces) {
if (!should_log(true)) {
return;
Expand Down
2 changes: 2 additions & 0 deletions drivers/unix/os_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class OS_Unix : public OS {

virtual String get_executable_path() const override;
virtual String get_user_data_dir(const String &p_user_dir) const override;

virtual String expand_path(const String &p_path) const override;
};

class UnixTerminalLogger : public StdLogger {
Expand Down
13 changes: 13 additions & 0 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,19 @@ String OS_Windows::get_user_data_dir(const String &p_user_dir) const {
return get_data_path().path_join(p_user_dir).replace_char('\\', '/');
}

String OS_Windows::expand_path(const String &p_path) const {
String path = p_path.replace_char('\\', '/');

if (path.begins_with("~/") || path == "~") {
String home = get_environment("USERPROFILE").replace_char('\\', '/').rstrip("/");
if (!home.is_empty()) {
path = home + path.substr(1);
}
}

return path;
}

String OS_Windows::get_unique_id() const {
HW_PROFILE_INFOA HwProfInfo;
ERR_FAIL_COND_V(!GetCurrentHwProfileA(&HwProfInfo), "");
Expand Down
2 changes: 2 additions & 0 deletions platform/windows/os_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ class OS_Windows : public OS {
virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override;
virtual String get_user_data_dir(const String &p_user_dir) const override;

virtual String expand_path(const String &p_path) const override;

virtual String get_unique_id() const override;

virtual Error shell_open(const String &p_uri) override;
Expand Down
18 changes: 12 additions & 6 deletions scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void FileDialog::update_dir() {
}

void FileDialog::_dir_submitted(String p_dir) {
String new_dir = p_dir;
String new_dir = OS::get_singleton()->expand_path(p_dir);
#ifdef WINDOWS_ENABLED
if (root_prefix.is_empty() && drives->is_visible() && !new_dir.is_network_share_path() && new_dir.is_absolute_path() && new_dir.find(":/") == -1 && new_dir.find(":\\") == -1) {
// Non network path without X:/ prefix on Windows, add drive letter.
Expand Down Expand Up @@ -466,6 +466,9 @@ void FileDialog::_action_pressed() {
}

String file_text = filename_edit->get_text();

file_text = OS::get_singleton()->expand_path(file_text);

String f = file_text.is_absolute_path() ? file_text : dir_access->get_current_dir().path_join(file_text);

if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && (dir_access->file_exists(f) || dir_access->is_bundle(f))) {
Expand Down Expand Up @@ -1203,7 +1206,7 @@ String FileDialog::get_current_path() const {
}

void FileDialog::set_current_dir(const String &p_dir) {
_change_dir(p_dir);
_change_dir(OS::get_singleton()->expand_path(p_dir));

_push_history();
}
Expand All @@ -1222,12 +1225,15 @@ void FileDialog::set_current_path(const String &p_path) {
if (!p_path.size()) {
return;
}
int pos = MAX(p_path.rfind_char('/'), p_path.rfind_char('\\'));

String path = OS::get_singleton()->expand_path(p_path);

int pos = MAX(path.rfind_char('/'), path.rfind_char('\\'));
if (pos == -1) {
set_current_file(p_path);
set_current_file(path);
} else {
String path_dir = p_path.substr(0, pos);
String path_file = p_path.substr(pos + 1);
String path_dir = path.substr(0, pos);
String path_file = path.substr(pos + 1);
set_current_dir(path_dir);
set_current_file(path_file);
}
Expand Down
Loading