瀏覽代碼

Use new XDG folders to dehardcode paths

Rémi Verschelde 8 年之前
父節點
當前提交
6e3f2f44af

+ 2 - 2
editor/editor_export.cpp

@@ -677,7 +677,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
 	}
 
 	String config_file = "project.binary";
-	String engine_cfb = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/tmp" + config_file;
+	String engine_cfb = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp" + config_file);
 	ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
 	Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
 
@@ -690,7 +690,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
 
 	EditorProgress ep("savepack", TTR("Packing"), 102);
 
-	String tmppath = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/packtmp";
+	String tmppath = EditorSettings::get_singleton()->get_cache_dir().plus_file("packtmp");
 	FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE);
 	ERR_FAIL_COND_V(!ftmp, ERR_CANT_CREATE)
 

+ 7 - 7
editor/editor_node.cpp

@@ -926,7 +926,7 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
 		img->flip_y();
 
 		//save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5
-		String temp_path = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp");
+		String temp_path = EditorSettings::get_singleton()->get_cache_dir();
 		String cache_base = ProjectSettings::get_singleton()->globalize_path(p_file).md5_text();
 		cache_base = temp_path.plus_file("resthumb-" + cache_base);
 
@@ -1198,7 +1198,7 @@ void EditorNode::_dialog_action(String p_file) {
 
 			Ref<ConfigFile> config;
 			config.instance();
-			Error err = config->load(EditorSettings::get_singleton()->get_settings_dir().plus_file("editor_layouts-3.cfg"));
+			Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
 
 			if (err == ERR_CANT_OPEN) {
 				config.instance(); // new config
@@ -1209,7 +1209,7 @@ void EditorNode::_dialog_action(String p_file) {
 
 			_save_docks_to_config(config, p_file);
 
-			config->save(EditorSettings::get_singleton()->get_settings_dir().plus_file("editor_layouts-3.cfg"));
+			config->save(EditorSettings::get_singleton()->get_editor_layouts_config());
 
 			layout_dialog->hide();
 			_update_layouts_menu();
@@ -1226,7 +1226,7 @@ void EditorNode::_dialog_action(String p_file) {
 
 			Ref<ConfigFile> config;
 			config.instance();
-			Error err = config->load(EditorSettings::get_singleton()->get_settings_dir().plus_file("editor_layouts-3.cfg"));
+			Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
 
 			if (err != OK || !config->has_section(p_file)) {
 				show_warning(TTR("Layout name not found!"));
@@ -1240,7 +1240,7 @@ void EditorNode::_dialog_action(String p_file) {
 				config->set_value(p_file, E->get(), Variant());
 			}
 
-			config->save(EditorSettings::get_singleton()->get_settings_dir().plus_file("editor_layouts-3.cfg"));
+			config->save(EditorSettings::get_singleton()->get_editor_layouts_config());
 
 			layout_dialog->hide();
 			_update_layouts_menu();
@@ -3812,7 +3812,7 @@ void EditorNode::_update_layouts_menu() {
 
 	Ref<ConfigFile> config;
 	config.instance();
-	Error err = config->load(EditorSettings::get_singleton()->get_settings_dir().plus_file("editor_layouts-3.cfg"));
+	Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
 	if (err != OK) {
 		return; //no config
 	}
@@ -3860,7 +3860,7 @@ void EditorNode::_layout_menu_option(int p_id) {
 
 			Ref<ConfigFile> config;
 			config.instance();
-			Error err = config->load(EditorSettings::get_singleton()->get_settings_dir().plus_file("editor_layouts-3.cfg"));
+			Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
 			if (err != OK) {
 				return; //no config
 			}

+ 1 - 1
editor/editor_resource_preview.cpp

@@ -198,7 +198,7 @@ void EditorResourcePreview::_thread() {
 
 				} else {
 
-					String temp_path = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp");
+					String temp_path = EditorSettings::get_singleton()->get_cache_dir();
 					String cache_base = ProjectSettings::get_singleton()->globalize_path(item.path).md5_text();
 					cache_base = temp_path.plus_file("resthumb-" + cache_base);
 

+ 23 - 28
editor/editor_settings.cpp

@@ -712,6 +712,12 @@ void EditorSettings::create() {
 			}
 		}
 
+		if (dir->change_dir("templates") != OK) {
+			dir->make_dir("templates");
+		} else {
+			dir->change_dir("..");
+		}
+
 		// Validate/create cache dir
 
 		if (dir->change_dir(cache_path) != OK) {
@@ -746,20 +752,6 @@ void EditorSettings::create() {
 			}
 		}
 
-		// FIXME: Move to data dir
-		if (dir->change_dir("templates") != OK) {
-			dir->make_dir("templates");
-		} else {
-			dir->change_dir("..");
-		}
-
-		// FIXME: Move to cache dir
-		if (dir->change_dir("tmp") != OK) {
-			dir->make_dir("tmp");
-		} else {
-			dir->change_dir("..");
-		}
-
 		if (dir->change_dir("text_editor_themes") != OK) {
 			dir->make_dir("text_editor_themes");
 		} else {
@@ -771,18 +763,17 @@ void EditorSettings::create() {
 		} else {
 			dir->change_dir("..");
 		}
-		_create_script_templates(dir->get_current_dir() + "/script_templates");
+		_create_script_templates(dir->get_current_dir().plus_file("script_templates"));
 
-		// FIXME: Rename to "projects"
-		if (dir->change_dir("config") != OK) {
-			dir->make_dir("config");
+		if (dir->change_dir("projects") != OK) {
+			dir->make_dir("projects");
 		} else {
 			dir->change_dir("..");
 		}
 
 		// Validate/create project-specific config dir
 
-		dir->change_dir("config");
+		dir->change_dir("projects");
 		String project_config_dir = ProjectSettings::get_singleton()->get_resource_path();
 		if (project_config_dir.ends_with("/"))
 			project_config_dir = config_path.substr(0, project_config_dir.size() - 1);
@@ -1040,8 +1031,7 @@ String EditorSettings::get_settings_dir() const {
 
 String EditorSettings::get_project_settings_dir() const {
 
-	// FIXME: Rename to "projects"
-	return get_settings_dir().plus_file("config").plus_file(project_config_dir);
+	return get_settings_dir().plus_file("projects").plus_file(project_config_dir);
 }
 
 String EditorSettings::get_text_editor_themes_dir() const {
@@ -1138,7 +1128,7 @@ void EditorSettings::load_favorites() {
 
 void EditorSettings::list_text_editor_themes() {
 	String themes = "Adaptive,Default";
-	DirAccess *d = DirAccess::open(get_settings_dir().plus_file("text_editor_themes"));
+	DirAccess *d = DirAccess::open(get_text_editor_themes_dir());
 	if (d) {
 		d->list_dir_begin();
 		String file = d->get_next();
@@ -1160,7 +1150,7 @@ void EditorSettings::load_text_editor_theme() {
 		return;
 	}
 
-	String theme_path = get_settings_dir().plus_file("text_editor_themes").plus_file((String)get("text_editor/theme/color_theme") + ".tet");
+	String theme_path = get_text_editor_themes_dir().plus_file((String)get("text_editor/theme/color_theme") + ".tet");
 
 	Ref<ConfigFile> cf = memnew(ConfigFile);
 	Error err = cf->load(theme_path);
@@ -1198,9 +1188,9 @@ bool EditorSettings::import_text_editor_theme(String p_file) {
 			return false;
 		}
 
-		DirAccess *d = DirAccess::open(get_settings_dir().plus_file("text_editor_themes"));
+		DirAccess *d = DirAccess::open(get_text_editor_themes_dir());
 		if (d) {
-			d->copy(p_file, get_settings_dir().plus_file("text_editor_themes").plus_file(p_file.get_file()));
+			d->copy(p_file, get_text_editor_themes_dir().plus_file(p_file.get_file()));
 			memdelete(d);
 			return true;
 		}
@@ -1215,7 +1205,7 @@ bool EditorSettings::save_text_editor_theme() {
 	if (p_file.get_file().to_lower() == "default" || p_file.get_file().to_lower() == "adaptive") {
 		return false;
 	}
-	String theme_path = get_settings_dir().plus_file("text_editor_themes").plus_file(p_file + ".tet");
+	String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet");
 	return _save_text_editor_theme(theme_path);
 }
 
@@ -1233,7 +1223,7 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) {
 		list_text_editor_themes();
 		String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
 
-		if (p_file.get_base_dir() == get_settings_dir().plus_file("text_editor_themes")) {
+		if (p_file.get_base_dir() == get_text_editor_themes_dir()) {
 			_initial_set("text_editor/theme/color_theme", theme_name);
 			load_text_editor_theme();
 		}
@@ -1245,7 +1235,7 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) {
 Vector<String> EditorSettings::get_script_templates(const String &p_extension) {
 
 	Vector<String> templates;
-	DirAccess *d = DirAccess::open(get_settings_dir().plus_file("script_templates"));
+	DirAccess *d = DirAccess::open(get_script_templates_dir());
 	if (d) {
 		d->list_dir_begin();
 		String file = d->get_next();
@@ -1261,6 +1251,11 @@ Vector<String> EditorSettings::get_script_templates(const String &p_extension) {
 	return templates;
 }
 
+String EditorSettings::get_editor_layouts_config() const {
+
+	return get_settings_dir().plus_file("editor_layouts.cfg");
+}
+
 // Shortcuts
 
 void EditorSettings::add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut) {

+ 1 - 0
editor/editor_settings.h

@@ -173,6 +173,7 @@ public:
 	bool save_text_editor_theme_as(String p_file);
 
 	Vector<String> get_script_templates(const String &p_extension);
+	String get_editor_layouts_config() const;
 
 	void add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut);
 	bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const;

+ 5 - 4
editor/export_template_manager.cpp

@@ -35,6 +35,7 @@
 #include "io/zip_io.h"
 #include "os/dir_access.h"
 #include "version.h"
+
 void ExportTemplateManager::_update_template_list() {
 
 	while (current_hb->get_child_count()) {
@@ -46,7 +47,7 @@ void ExportTemplateManager::_update_template_list() {
 	}
 
 	DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
-	Error err = d->change_dir(EditorSettings::get_singleton()->get_settings_dir().plus_file("templates"));
+	Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());
 
 	d->list_dir_begin();
 	Set<String> templates;
@@ -142,7 +143,7 @@ void ExportTemplateManager::_uninstall_template(const String &p_version) {
 void ExportTemplateManager::_uninstall_template_confirm() {
 
 	DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
-	Error err = d->change_dir(EditorSettings::get_singleton()->get_settings_dir().plus_file("templates"));
+	Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());
 
 	ERR_FAIL_COND(err != OK);
 
@@ -244,7 +245,7 @@ void ExportTemplateManager::_install_from_file(const String &p_file) {
 		return;
 	}
 
-	String template_path = EditorSettings::get_singleton()->get_settings_dir().plus_file("templates").plus_file(version);
+	String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version);
 
 	DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
 	Error err = d->make_dir_recursive(template_path);
@@ -393,7 +394,7 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int
 			if (p_code != 200) {
 				template_list_state->set_text(TTR("Failed:") + " " + itos(p_code));
 			} else {
-				String path = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp").plus_file("tmp_templates.tpz");
+				String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_templates.tpz");
 				FileAccess *f = FileAccess::open(path, FileAccess::WRITE);
 				if (!f) {
 					template_list_state->set_text(TTR("Can't write file."));

+ 4 - 4
editor/plugins/asset_library_editor_plugin.cpp

@@ -445,7 +445,7 @@ void EditorAssetLibraryItemDownload::_install() {
 
 void EditorAssetLibraryItemDownload::_make_request() {
 	download->cancel_request();
-	download->set_download_file(EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp").plus_file("tmp_asset_" + itos(asset_id)) + ".zip");
+	download->set_download_file(EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_asset_" + itos(asset_id)) + ".zip");
 
 	Error err = download->request(host);
 	if (err != OK) {
@@ -680,7 +680,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt
 		PoolByteArray image_data = p_data;
 
 		if (use_cache) {
-			String cache_filename_base = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
+			String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
 
 			FileAccess *file = FileAccess::open(cache_filename_base + ".data", FileAccess::READ);
 
@@ -738,7 +738,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons
 		if (p_code != HTTPClient::RESPONSE_NOT_MODIFIED) {
 			for (int i = 0; i < headers.size(); i++) {
 				if (headers[i].findn("ETag:") == 0) { // Save etag
-					String cache_filename_base = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
+					String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
 					String new_etag = headers[i].substr(headers[i].find(":") + 1, headers[i].length()).strip_edges();
 					FileAccess *file;
 
@@ -786,7 +786,7 @@ void EditorAssetLibrary::_update_image_queue() {
 	for (Map<int, ImageQueue>::Element *E = image_queue.front(); E; E = E->next()) {
 		if (!E->get().active && current_images < max_images) {
 
-			String cache_filename_base = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp").plus_file("assetimage_" + E->get().image_url.md5_text());
+			String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + E->get().image_url.md5_text());
 			Vector<String> headers;
 
 			if (FileAccess::exists(cache_filename_base + ".etag") && FileAccess::exists(cache_filename_base + ".data")) {

+ 1 - 1
editor/plugins/editor_preview_plugins.cpp

@@ -184,7 +184,7 @@ Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from) {
 
 Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) {
 
-	String temp_path = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp");
+	String temp_path = EditorSettings::get_singleton()->get_cache_dir();
 	String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text();
 	cache_base = temp_path.plus_file("resthumb-" + cache_base);
 

+ 1 - 1
editor/plugins/script_editor_plugin.cpp

@@ -855,7 +855,7 @@ void ScriptEditor::_menu_option(int p_option) {
 			file_dialog_option = FILE_SAVE_THEME_AS;
 			file_dialog->clear_filters();
 			file_dialog->add_filter("*.tet");
-			file_dialog->set_current_path(EditorSettings::get_singleton()->get_settings_dir() + "/text_editor_themes/" + EditorSettings::get_singleton()->get("text_editor/theme/color_theme"));
+			file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme")));
 			file_dialog->popup_centered_ratio();
 			file_dialog->set_title(TTR("Save Theme As.."));
 		} break;

+ 3 - 3
editor/pvrtc_compress.cpp

@@ -62,12 +62,12 @@ static void _compress_image(Image::CompressMode p_mode, Image *p_image) {
 		}
 		return;
 	}
-	String spath = EditorSettings::get_singleton()->get_settings_dir();
+	String tmppath = EditorSettings::get_singleton()->get_cache_dir();
 
 	List<String> args;
 
-	String src_img = spath + "/" + "_tmp_src_img.png";
-	String dst_img = spath + "/" + "_tmp_dst_img.pvr";
+	String src_img = tmppath.plus_file("_tmp_src_img.png");
+	String dst_img = tmppath.plus_file("_tmp_dst_img.pvr");
 
 	args.push_back("-i");
 	args.push_back(src_img);

+ 1 - 1
editor/script_create_dialog.cpp

@@ -128,7 +128,7 @@ void ScriptCreateDialog::_template_changed(int p_template) {
 	}
 	String ext = ScriptServer::get_language(language_menu->get_selected())->get_extension();
 	String name = template_list[p_template - 1] + "." + ext;
-	script_template = EditorSettings::get_singleton()->get_settings_dir() + "/script_templates/" + name;
+	script_template = EditorSettings::get_singleton()->get_script_templates_dir().plus_file(name);
 }
 
 void ScriptCreateDialog::ok_pressed() {

+ 2 - 2
platform/android/export/export.cpp

@@ -1066,7 +1066,7 @@ public:
 		if (use_reverse)
 			p_debug_flags |= DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST;
 
-		String export_to = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/tmpexport.apk";
+		String export_to = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk");
 		Error err = export_project(p_preset, true, export_to, p_debug_flags);
 		if (err) {
 			device_lock->unlock();
@@ -1291,7 +1291,7 @@ public:
 		zlib_filefunc_def io2 = io;
 		FileAccess *dst_f = NULL;
 		io2.opaque = &dst_f;
-		String unaligned_path = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/tmpexport-unaligned.apk";
+		String unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk");
 		zipFile unaligned_apk = zipOpen2(unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
 
 		bool export_x86 = p_preset->get("architecture/x86");

+ 1 - 1
platform/javascript/export/export.cpp

@@ -319,7 +319,7 @@ int EditorExportPlatformJavaScript::get_device_count() const {
 
 Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
 
-	String path = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/tmp_export.html";
+	String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_export.html");
 	Error err = export_project(p_preset, true, path, p_debug_flags);
 	if (err) {
 		return err;

+ 3 - 3
platform/osx/export/export.cpp

@@ -160,7 +160,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
 		copy->convert(Image::FORMAT_RGBA8);
 		copy->resize(size, size);
 		it->create_from_image(copy);
-		String path = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/icon.png";
+		String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
 		ResourceSaver::save(path, it);
 
 		FileAccess *f = FileAccess::open(path, FileAccess::READ);
@@ -344,7 +344,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 
 	if (use_dmg()) {
 		// We're on OSX so we can export to DMG, but first we create our application bundle
-		tmp_app_path_name = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/" + pkg_name + ".app";
+		tmp_app_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".app");
 		print_line("Exporting to " + tmp_app_path_name);
 		DirAccess *tmp_app_path = DirAccess::create_for_path(tmp_app_path_name);
 		if (!tmp_app_path) {
@@ -539,7 +539,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 			OS::get_singleton()->move_to_trash(tmp_app_path_name);
 		} else {
 
-			String pack_path = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/" + pkg_name + ".pck";
+			String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck");
 			Error err = save_pack(p_preset, pack_path);
 
 			if (err == OK) {

+ 3 - 3
platform/uwp/export/export.cpp

@@ -456,8 +456,8 @@ void AppxPackager::init(FileAccess *p_fa) {
 	package = p_fa;
 	central_dir_offset = 0;
 	end_of_central_dir_offset = 0;
-	tmp_blockmap_file_path = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/tmpblockmap.xml";
-	tmp_content_types_file_path = EditorSettings::get_singleton()->get_settings_dir() + "/tmp/tmpcontenttypes.xml";
+	tmp_blockmap_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpblockmap.xml");
+	tmp_content_types_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml");
 }
 
 void AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) {
@@ -886,7 +886,7 @@ class EditorExportUWP : public EditorExportPlatform {
 
 		if (!image) return data;
 
-		String tmp_path = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp/uwp_tmp_logo.png");
+		String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("uwp_tmp_logo.png");
 
 		Error err = image->get_data()->save_png(tmp_path);