From c06a2db63a85c23fa35058f5bfd62245ed998951 Mon Sep 17 00:00:00 2001 From: Andreas Haas Date: Sun, 16 Apr 2017 10:17:24 +0200 Subject: Use .godot as file extension for project files. Now project files don't have to be named "godot.cfg" anymore, they can have any name so as long as it ends with *.godot. Also godot will automatically start the editor now if launched with a project file as an argument. This allows for double-clicking of projects to open them :) Code-wise this should be complete, but there's still work to do: - Make a nice icon for godot projects. - Work on installers/packaging -> register the extension and icon with godot. - Update the 2.1 to 3.0 exporter. Tested on linux and windows so far. --- core/global_config.cpp | 72 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'core/global_config.cpp') diff --git a/core/global_config.cpp b/core/global_config.cpp index d37c67c84a..04838b5cc3 100644 --- a/core/global_config.cpp +++ b/core/global_config.cpp @@ -53,6 +53,11 @@ String GlobalConfig::get_resource_path() const { return resource_path; }; +String GlobalConfig::get_project_file_name() const { + + return project_file_name; +} + String GlobalConfig::localize_path(const String &p_path) const { if (resource_path == "") @@ -236,13 +241,43 @@ bool GlobalConfig::_load_resource_pack(const String &p_pack) { return true; } +static String _find_project_file(DirAccess *p_diraccess, bool p_res = false) { + p_diraccess->list_dir_begin(); + String ret = ""; + while (true) { + bool isdir; + String file = p_diraccess->get_next(&isdir); + if (file == "") + break; + + if (!isdir) { + if (file.get_extension() == "godot") { + + if (p_res) { + ret = "res://" + file; + } else { + ret = p_diraccess->get_current_dir() + "/" + file; + } + } + } + } + p_diraccess->list_dir_end(); + return ret; +} + +static String _find_project_file() { + DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES); + String ret = _find_project_file(dir, true); + memdelete(dir); + return ret; +} + Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { //If looking for files in network, just use network! - if (FileAccessNetworkClient::get_singleton()) { - - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { _load_settings("res://override.cfg"); } @@ -258,8 +293,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { bool ok = _load_resource_pack(p_main_pack); ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN); - - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { //load override from location of the main pack _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg")); } @@ -272,7 +307,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { if (_load_resource_pack(exec_path.get_basename() + ".pck")) { - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { //load override from location of executable _load_settings(exec_path.get_base_dir().plus_file("override.cfg")); } @@ -292,15 +328,15 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { // data.pck and data.zip are deprecated and no longer supported, apologies. // make sure this is loaded from the resource path - - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { _load_settings("res://override.cfg"); } return OK; } - //Nothing was found, try to find a godot.cfg somewhere! + //Nothing was found, try to find a *.godot somewhere! DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); ERR_FAIL_COND_V(!d, ERR_CANT_CREATE); @@ -313,8 +349,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { while (true) { //try to load settings in ascending through dirs shape! - - if (_load_settings(current_dir + "/godot.cfg") == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) { + String gdproj = _find_project_file(d); + if (_load_settings(gdproj) == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) { _load_settings(current_dir + "/override.cfg"); candidate = current_dir; @@ -428,6 +464,7 @@ Error GlobalConfig::_load_settings(const String p_path) { err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); if (err == ERR_FILE_EOF) { memdelete(f); + project_file_name = p_path.get_file(); return OK; } else if (err != OK) { ERR_PRINTS("GlobalConfig::load - " + p_path + ":" + itos(lines) + " error: " + error_text); @@ -449,6 +486,7 @@ Error GlobalConfig::_load_settings(const String p_path) { } } + project_file_name = p_path.get_file(); memdelete(f); return OK; @@ -474,7 +512,12 @@ void GlobalConfig::clear(const String &p_name) { Error GlobalConfig::save() { - return save_custom(get_resource_path() + "/godot.cfg"); + if (project_file_name.empty()) { + String name = ((String)get("application/name")).replace(" ", "_"); + return save_custom(get_resource_path() + "/" + name + ".godot"); + } else { + return save_custom(get_resource_path() + "/" + project_file_name); + } } Error GlobalConfig::_save_settings_binary(const String &p_file, const Map > &props, const CustomMap &p_custom) { @@ -483,7 +526,7 @@ Error GlobalConfig::_save_settings_binary(const String &p_file, const Map