Skip to content
Merged
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 @@ -408,6 +408,10 @@ Error OS::set_cwd(const String &p_cwd) {
return ERR_CANT_OPEN;
}

String OS::get_cwd() const {
return ".";
}

Dictionary OS::get_memory_info() const {
Dictionary meminfo;

Expand Down
1 change: 1 addition & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class OS {
virtual Error shell_open(const String &p_uri);
virtual Error shell_show_in_file_manager(String p_path, bool p_open_folder = true);
virtual Error set_cwd(const String &p_cwd);
virtual String get_cwd() const;

virtual bool has_environment(const String &p_var) const = 0;
virtual String get_environment(const String &p_var) const = 0;
Expand Down
10 changes: 10 additions & 0 deletions drivers/unix/os_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,16 @@ Error OS_Unix::set_cwd(const String &p_cwd) {
return OK;
}

String OS_Unix::get_cwd() const {
String dir;
char real_current_dir_name[2048];
ERR_FAIL_NULL_V(getcwd(real_current_dir_name, 2048), ".");
if (dir.append_utf8(real_current_dir_name) != OK) {
dir = real_current_dir_name;
}
return dir;
}

bool OS_Unix::has_environment(const String &p_var) const {
return getenv(p_var.utf8().get_data()) != nullptr;
}
Expand Down
1 change: 1 addition & 0 deletions drivers/unix/os_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class OS_Unix : public OS {
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String &p_name, void *&p_symbol_handle, bool p_optional = false) override;

virtual Error set_cwd(const String &p_cwd) override;
virtual String get_cwd() const override;

virtual String get_name() const override;
virtual String get_distribution_name() const override;
Expand Down
20 changes: 18 additions & 2 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->initialize();

#if !defined(OVERRIDE_PATH_ENABLED) && !defined(TOOLS_ENABLED)
String old_cwd = OS::get_singleton()->get_cwd();
#ifdef MACOS_ENABLED
String new_cwd = OS::get_singleton()->get_bundle_resource_dir();
if (new_cwd.is_empty() || !new_cwd.is_absolute_path()) {
Expand Down Expand Up @@ -2019,8 +2020,23 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
#ifdef TOOLS_ENABLED
editor = false;
#else
const String error_msg = "Error: Couldn't load project data at path \"" + project_path + "\". Is the .pck file missing?\nIf you've renamed the executable, the associated .pck file should also be renamed to match the executable's name (without the extension).\n";
OS::get_singleton()->print("%s", error_msg.utf8().get_data());
String error_msg = "Error: Couldn't load project data at path \"" + (project_path == "." ? OS::get_singleton()->get_cwd() : project_path) + "\". Is the .pck file missing?\n\n";
#if !defined(OVERRIDE_PATH_ENABLED) && !defined(TOOLS_ENABLED)
String exec_path = OS::get_singleton()->get_executable_path();
String exec_basename = exec_path.get_file().get_basename();

if (FileAccess::exists(old_cwd.path_join(exec_basename + ".pck"))) {
error_msg += "\"" + exec_basename + ".pck\" was found in the current working directory. To be able to load a project from the CWD, use the `disable_path_overrides=no` SCons option when compiling Godot.\n";
} else if (FileAccess::exists(old_cwd.path_join("project.godot"))) {
error_msg += "\"project.godot\" was found in the current working directory. To be able to load a project from the CWD, use the `disable_path_overrides=no` SCons option when compiling Godot.\n";
} else {
error_msg += "If you've renamed the executable, the associated .pck file should also be renamed to match the executable's name (without the extension).\n";
}
#else
error_msg += "If you've renamed the executable, the associated .pck file should also be renamed to match the executable's name (without the extension).\n";
#endif
ERR_PRINT(error_msg);

OS::get_singleton()->alert(error_msg);

goto error;
Expand Down
8 changes: 8 additions & 0 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,14 @@ Error OS_Windows::set_cwd(const String &p_cwd) {
return OK;
}

String OS_Windows::get_cwd() const {
Char16String real_current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
real_current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(real_current_dir_name.size(), (LPWSTR)real_current_dir_name.ptrw());
return String::utf16((const char16_t *)real_current_dir_name.get_data()).trim_prefix(R"(\\?\)").replace_char('\\', '/');
}

Vector<String> OS_Windows::get_system_fonts() const {
if (!dwrite_init) {
return Vector<String>();
Expand Down
1 change: 1 addition & 0 deletions platform/windows/os_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class OS_Windows : public OS {
virtual double get_unix_time() const override;

virtual Error set_cwd(const String &p_cwd) override;
virtual String get_cwd() const override;

virtual void add_frame_delay(bool p_can_draw, bool p_wake_for_events) override;
virtual void delay_usec(uint32_t p_usec) const override;
Expand Down