diff options
author | Andreas Haas <liu.gam3@gmail.com> | 2017-04-16 10:17:24 +0200 |
---|---|---|
committer | Andreas Haas <liu.gam3@gmail.com> | 2017-04-16 10:19:07 +0200 |
commit | c06a2db63a85c23fa35058f5bfd62245ed998951 (patch) | |
tree | f97462cfc99d5ac40238e5bb3adc3ea7131a5019 /core | |
parent | e46af1e23668e23160604742f8f1d22898796d1c (diff) |
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.
Diffstat (limited to 'core')
-rw-r--r-- | core/global_config.cpp | 72 | ||||
-rw-r--r-- | core/global_config.h | 3 |
2 files changed, 61 insertions, 14 deletions
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<String, List<String> > &props, const CustomMap &p_custom) { @@ -483,7 +526,7 @@ Error GlobalConfig::_save_settings_binary(const String &p_file, const Map<String FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); if (err != OK) { - ERR_EXPLAIN("Coudln't save godot.cfb at " + p_file); + ERR_EXPLAIN("Couldn't save godot.cfb at " + p_file); ERR_FAIL_COND_V(err, err) } @@ -548,7 +591,7 @@ Error GlobalConfig::_save_settings_text(const String &p_file, const Map<String, FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); if (err) { - ERR_EXPLAIN("Coudln't save godot.cfg - " + p_file); + ERR_EXPLAIN("Couldn't save project file - " + p_file); ERR_FAIL_COND_V(err, err) } @@ -828,6 +871,7 @@ void GlobalConfig::_bind_methods() { ClassDB::bind_method(D_METHOD("clear", "name"), &GlobalConfig::clear); ClassDB::bind_method(D_METHOD("localize_path", "path"), &GlobalConfig::localize_path); ClassDB::bind_method(D_METHOD("globalize_path", "path"), &GlobalConfig::globalize_path); + ClassDB::bind_method(D_METHOD("get_project_file_name"), &GlobalConfig::get_project_file_name); ClassDB::bind_method(D_METHOD("save"), &GlobalConfig::save); ClassDB::bind_method(D_METHOD("has_singleton", "name"), &GlobalConfig::has_singleton); ClassDB::bind_method(D_METHOD("get_singleton", "name"), &GlobalConfig::get_singleton_object); diff --git a/core/global_config.h b/core/global_config.h index d0f64dc23c..5148c4377e 100644 --- a/core/global_config.h +++ b/core/global_config.h @@ -111,6 +111,8 @@ protected: void _add_property_info_bind(const Dictionary &p_info); + String project_file_name; + protected: static void _bind_methods(); @@ -124,6 +126,7 @@ public: Variant property_get_revert(const String &p_name); String get_resource_path() const; + String get_project_file_name() const; static GlobalConfig *get_singleton(); |