You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-02 16:48:55 +00:00
Add error message when trying to load project from CWD.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -205,6 +205,7 @@ public:
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
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;
|
||||
|
||||
@@ -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()) {
|
||||
@@ -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;
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -201,6 +201,7 @@ public:
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user