Example #1
0
void DependencyErrorDialog::show(Mode p_mode, const String &p_for_file, const Vector<String> &report) {

	mode = p_mode;
	for_file = p_for_file;
	set_title(TTR("Error loading:") + " " + p_for_file.get_file());
	files->clear();

	TreeItem *root = files->create_item(NULL);
	for (int i = 0; i < report.size(); i++) {

		String dep;
		String type = "Object";
		dep = report[i].get_slice("::", 0);
		if (report[i].get_slice_count("::") > 0)
			type = report[i].get_slice("::", 1);

		Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type);

		TreeItem *ti = files->create_item(root);
		ti->set_text(0, dep);
		ti->set_icon(0, icon);
	}

	popup_centered_minsize(Size2(500, 220));
}
void ResourcePreloaderEditor::_file_load_request(const String& p_path) {


	RES resource;

	resource = ResourceLoader::load(p_path);

	if (resource.is_null()) {
		dialog->set_text("ERROR: Couldn't load resource!");
		dialog->set_title("Error!");
		//dialog->get_cancel()->set_text("Close");
		dialog->get_ok()->set_text("Close");
		dialog->popup_centered_minsize();
		return; ///beh should show an error i guess
	}

	String basename = p_path.get_file().basename();
	String name=basename;
	int counter=1;
	while(preloader->has_resource(name)) {
		counter++;
		name=basename+" "+itos(counter);
	}

	undo_redo->create_action("Add Resource");
	undo_redo->add_do_method(preloader,"add_resource",name,resource);
	undo_redo->add_undo_method(preloader,"remove_resource",name);
	undo_redo->add_do_method(this,"_update_library");
	undo_redo->add_undo_method(this,"_update_library");
	undo_redo->commit_action();
}
Example #3
0
void DependencyEditorOwners::show(const String &p_path) {

	editing = p_path;
	owners->clear();
	_fill_owners(EditorFileSystem::get_singleton()->get_filesystem());
	popup_centered_ratio();

	set_title(TTR("Owners Of:") + " " + p_path.get_file());
}
Example #4
0
void EditorFileSystem::update_file(const String& p_file) {

    EditorFileSystemDirectory *fs=NULL;
    int cpos=-1;

    if (!_find_file(p_file,&fs,cpos)) {

	if (!fs)
		return;
    }

    if (!FileAccess::exists(p_file)) {
	    //was removed
	    memdelete( fs->files[cpos] );
	    fs->files.remove(cpos);
	    call_deferred("emit_signal","filesystem_changed"); //update later
	    return;

    }

    String type = ResourceLoader::get_resource_type(p_file);

    if (cpos==-1) {

	    int idx=0;

	    for(int i=0;i<fs->files.size();i++) {
		if (p_file<fs->files[i]->file)
		    break;
		idx++;
	    }

	    EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo );
	    fi->file=p_file.get_file();

	    if (idx==fs->files.size()) {
		fs->files.push_back(fi);
	    } else {

		fs->files.insert(idx,fi);
	    }
	    cpos=idx;


    }

	//print_line("UPDATING: "+p_file);
	fs->files[cpos]->type=type;
	fs->files[cpos]->modified_time=FileAccess::get_modified_time(p_file);
	fs->files[cpos]->meta=_get_meta(p_file);

	EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation",p_file);
	call_deferred("emit_signal","filesystem_changed"); //update later

}
Example #5
0
void DependencyEditor::edit(const String &p_path) {

	editing = p_path;
	set_title(TTR("Dependencies For:") + " " + p_path.get_file());

	_update_list();
	popup_centered_ratio();

	if (EditorNode::get_singleton()->is_scene_open(p_path)) {
		EditorNode::get_singleton()->show_warning(vformat(TTR("Scene '%s' is currently being edited.\nChanges will only take effect when reloaded."), p_path.get_file()));
	} else if (ResourceCache::has(p_path)) {
		EditorNode::get_singleton()->show_warning(vformat(TTR("Resource '%s' is in use.\nChanges will only take effect when reloaded."), p_path.get_file()));
	}
}
Example #6
0
void DependencyEditor::_update_list() {

	List<String> deps;
	ResourceLoader::get_dependencies(editing, &deps, true);

	tree->clear();
	missing.clear();

	TreeItem *root = tree->create_item();

	Ref<Texture> folder = get_icon("folder", "FileDialog");

	bool broken = false;

	for (List<String>::Element *E = deps.front(); E; E = E->next()) {

		TreeItem *item = tree->create_item(root);

		String n = E->get();
		String path;
		String type;

		if (n.find("::") != -1) {
			path = n.get_slice("::", 0);
			type = n.get_slice("::", 1);
		} else {
			path = n;
			type = "Resource";
		}
		String name = path.get_file();

		Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type);
		item->set_text(0, name);
		item->set_icon(0, icon);
		item->set_metadata(0, type);
		item->set_text(1, path);

		if (!FileAccess::exists(path)) {
			item->set_custom_color(1, Color(1, 0.4, 0.3));
			missing.push_back(path);
			broken = true;
		}

		item->add_button(1, folder, 0);
	}

	fixdeps->set_disabled(!broken);
}
void EditorFileDialog::_post_popup() {

	ConfirmationDialog::_post_popup();
	if (invalidated) {
		update_file_list();
		invalidated=false;
	}
	if (mode==MODE_SAVE_FILE)
		file->grab_focus();
	else
		item_list->grab_focus();

	if (is_visible() && get_current_file()!="")
		_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));

	if (is_visible()) {
		Ref<Texture> folder = get_icon("folder","FileDialog");
		recent->clear();


		bool res = access==ACCESS_RESOURCES;
		Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs();
		for(int i=0;i<recentd.size();i++) {
			bool cres = recentd[i].begins_with("res://");
			if (cres!=res)
				continue;
			String name = recentd[i];
			if (res && name=="res://") {
				name="/";
			} else {
				name=name.get_file()+"/";
			}

			//print_line("file: "+name);
			recent->add_item(name,folder);
			recent->set_item_metadata( recent->get_item_count()-1,recentd[i]);
		}

		local_history.clear();
		local_history_pos=-1;
		_push_history();

		_update_favorites();
	}

	set_process_unhandled_input(true);

}
void EditorFileSystem::update_file(const String& p_file) {

    EditorFileSystemDirectory *fs=NULL;
    int cpos=-1;

    if (!_find_file(p_file,&fs,cpos)) {

	if (!fs)
		return;
    }


    String type = ResourceLoader::get_resource_type(p_file);

    if (cpos==-1) {

	    int idx=0;

	    for(int i=0;i<fs->files.size();i++) {
		if (p_file<fs->files[i].file)
		    break;
		idx++;
	    }

	    EditorFileSystemDirectory::FileInfo fi;
	    fi.file=p_file.get_file();

	    if (idx==fs->files.size()) {
		fs->files.push_back(fi);
	    } else {

		fs->files.insert(idx,fi);
	    }
	    cpos=idx;


    }

	print_line("UPDATING: "+p_file);
	fs->files[cpos].type=type;
	fs->files[cpos].modified_time=FileAccess::get_modified_time(p_file);
	fs->files[cpos].meta=_get_meta(p_file);

	call_deferred("emit_signal","filesystem_changed"); //update later

}
Example #9
0
void ProjectExportDialog::_validate_export_path(const String &p_path) {
	// Disable export via OK button or Enter key if LineEdit has an empty filename
	bool invalid_path = (p_path.get_file().get_basename() == "");

	// Check if state change before needlessly messing with signals
	if (invalid_path && export_project->get_ok()->is_disabled())
		return;
	if (!invalid_path && !export_project->get_ok()->is_disabled())
		return;

	if (invalid_path) {
		export_project->get_ok()->set_disabled(true);
		export_project->get_line_edit()->disconnect("text_entered", export_project, "_file_entered");
	} else {
		export_project->get_ok()->set_disabled(false);
		export_project->get_line_edit()->connect("text_entered", export_project, "_file_entered");
	}
}
void EditorFileDialog::_update_favorites() {

	bool res = access==ACCESS_RESOURCES;

	String current = get_current_dir();
	Ref<Texture> star = get_icon("Favorites","EditorIcons");
	favorites->clear();

	favorite->set_pressed(false);


	Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
	for(int i=0;i<favorited.size();i++) {
		bool cres = favorited[i].begins_with("res://");
		if (cres!=res)
			continue;
		String name = favorited[i];

		bool setthis = name==current;

		if (res && name=="res://") {
			name="/";
		} else {
			name=name.get_file()+"/";
		}


		//print_line("file: "+name);
		favorites->add_item(name,star);
		favorites->set_item_metadata( favorites->get_item_count()-1,favorited[i]);

		if (setthis) {
			favorite->set_pressed(true);
			favorites->set_current(favorites->get_item_count()-1);
		}
	}


}
Example #11
0
void ProjectExportDialog::_export_project_to_path(const String &p_path) {
	// Save this name for use in future exports (but drop the file extension)
	default_filename = p_path.get_file().get_basename();
	EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename);

	Ref<EditorExportPreset> current = get_current_preset();
	ERR_FAIL_COND(current.is_null());
	Ref<EditorExportPlatform> platform = current->get_platform();
	ERR_FAIL_COND(platform.is_null());
	current->set_export_path(p_path);

	Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0);
	if (err != OK) {
		if (err == ERR_FILE_NOT_FOUND) {
			error_dialog->set_text(vformat(TTR("Failed to export the project for platform '%s'.\nExport templates seem to be missing or invalid."), platform->get_name()));
		} else { // Assume misconfiguration. FIXME: Improve error handling and preset config validation.
			error_dialog->set_text(vformat(TTR("Failed to export the project for platform '%s'.\nThis might be due to a configuration issue in the export preset or your export settings."), platform->get_name()));
		}

		ERR_PRINTS(vformat("Failed to export the project for platform '%s'.", platform->get_name()));
		error_dialog->show();
		error_dialog->popup_centered_minsize(Size2(300, 80));
	}
}
Example #12
0
void ExportTemplateManager::_install_from_file(const String &p_file) {

	FileAccess *fa = NULL;
	zlib_filefunc_def io = zipio_create_io_from_file(&fa);

	unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
	if (!pkg) {

		EditorNode::get_singleton()->show_warning(TTR("Can't open export templates zip."));
		return;
	}
	int ret = unzGoToFirstFile(pkg);

	int fc = 0; //count them and find version
	String version;

	while (ret == UNZ_OK) {

		unz_file_info info;
		char fname[16384];
		ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);

		String file = fname;

		if (file.ends_with("version.txt")) {

			Vector<uint8_t> data;
			data.resize(info.uncompressed_size);

			//read
			unzOpenCurrentFile(pkg);
			ret = unzReadCurrentFile(pkg, data.ptr(), data.size());
			unzCloseCurrentFile(pkg);

			String data_str;
			data_str.parse_utf8((const char *)data.ptr(), data.size());
			data_str = data_str.strip_edges();

			if (data_str.get_slice_count("-") != 2 || data_str.get_slice_count(".") != 2) {
				EditorNode::get_singleton()->show_warning(TTR("Invalid version.txt format inside templates."));
				unzClose(pkg);
				return;
			}

			String ver = data_str.get_slice("-", 0);

			int major = ver.get_slice(".", 0).to_int();
			int minor = ver.get_slice(".", 1).to_int();
			String rev = data_str.get_slice("-", 1);

			if (!rev.is_valid_identifier()) {
				EditorNode::get_singleton()->show_warning(TTR("Invalid version.txt format inside templates. Revision is not a valid identifier."));
				unzClose(pkg);
				return;
			}

			version = itos(major) + "." + itos(minor) + "-" + rev;
		}

		fc++;
		ret = unzGoToNextFile(pkg);
	}

	if (version == String()) {
		EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside templates."));
		unzClose(pkg);
		return;
	}

	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);
	if (err != OK) {
		EditorNode::get_singleton()->show_warning(TTR("Error creating path for templates:\n") + template_path);
		unzClose(pkg);
		return;
	}

	memdelete(d);

	ret = unzGoToFirstFile(pkg);

	EditorProgress p("ltask", TTR("Extracting Export Templates"), fc);

	fc = 0;

	while (ret == UNZ_OK) {

		//get filename
		unz_file_info info;
		char fname[16384];
		unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);

		String file = fname;

		Vector<uint8_t> data;
		data.resize(info.uncompressed_size);

		//read
		unzOpenCurrentFile(pkg);
		unzReadCurrentFile(pkg, data.ptr(), data.size());
		unzCloseCurrentFile(pkg);

		print_line(fname);
		/*
		for(int i=0;i<512;i++) {
			print_line(itos(data[i]));
		}
		*/

		file = file.get_file();

		p.step(TTR("Importing:") + " " + file, fc);

		FileAccess *f = FileAccess::open(template_path.plus_file(file), FileAccess::WRITE);

		ERR_CONTINUE(!f);
		f->store_buffer(data.ptr(), data.size());

		memdelete(f);

		ret = unzGoToNextFile(pkg);
		fc++;
	}

	unzClose(pkg);

	_update_template_list();
}
Example #13
0
String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const {

	return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text();
}
Example #14
0
void FileDialog::_action_pressed() {

	if (mode == MODE_OPEN_FILES) {

		TreeItem *ti = tree->get_next_selected(NULL);
		String fbase = dir_access->get_current_dir();

		PoolVector<String> files;
		while (ti) {

			files.push_back(fbase.plus_file(ti->get_text(0)));
			ti = tree->get_next_selected(ti);
		}

		if (files.size()) {
			emit_signal("files_selected", files);
			hide();
		}

		return;
	}

	String f = dir_access->get_current_dir().plus_file(file->get_text());

	if ((mode == MODE_OPEN_ANY || mode == MODE_OPEN_FILE) && dir_access->file_exists(f)) {
		emit_signal("file_selected", f);
		hide();
	} else if (mode == MODE_OPEN_ANY || mode == MODE_OPEN_DIR) {

		String path = dir_access->get_current_dir();

		path = path.replace("\\", "/");
		TreeItem *item = tree->get_selected();
		if (item) {
			Dictionary d = item->get_metadata(0);
			if (d["dir"]) {
				path = path.plus_file(d["name"]);
			}
		}

		emit_signal("dir_selected", path);
		hide();
	}

	if (mode == MODE_SAVE_FILE) {

		bool valid = false;

		if (filter->get_selected() == filter->get_item_count() - 1) {
			valid = true; //match none
		} else if (filters.size() > 1 && filter->get_selected() == 0) {
			// match all filters
			for (int i = 0; i < filters.size(); i++) {

				String flt = filters[i].get_slice(";", 0);
				for (int j = 0; j < flt.get_slice_count(","); j++) {

					String str = flt.get_slice(",", j).strip_edges();
					if (f.match(str)) {
						valid = true;
						break;
					}
				}
				if (valid)
					break;
			}
		} else {
			int idx = filter->get_selected();
			if (filters.size() > 1)
				idx--;
			if (idx >= 0 && idx < filters.size()) {

				String flt = filters[idx].get_slice(";", 0);
				int filterSliceCount = flt.get_slice_count(",");
				for (int j = 0; j < filterSliceCount; j++) {

					String str = (flt.get_slice(",", j).strip_edges());
					if (f.match(str)) {
						valid = true;
						break;
					}
				}

				if (!valid && filterSliceCount > 0) {
					String str = (flt.get_slice(",", 0).strip_edges());
					f += str.substr(1, str.length() - 1);
					file->set_text(f.get_file());
					valid = true;
				}
			} else {
				valid = true;
			}
		}

		if (!valid) {

			exterr->popup_centered_minsize(Size2(250, 80));
			return;
		}

		if (dir_access->file_exists(f)) {
			confirm_save->set_text(RTR("File Exists, Overwrite?"));
			confirm_save->popup_centered(Size2(200, 80));
		} else {

			emit_signal("file_selected", f);
			hide();
		}
	}
}
Example #15
0
void ProjectExportDialog::_edit_preset(int p_index) {

	if (p_index < 0 || p_index >= presets->get_item_count()) {
		name->set_text("");
		name->set_editable(false);
		export_path->hide();
		runnable->set_disabled(true);
		parameters->edit(NULL);
		presets->unselect_all();
		duplicate_preset->set_disabled(true);
		delete_preset->set_disabled(true);
		sections->hide();
		patches->clear();
		export_error->hide();
		export_templates_error->hide();
		return;
	}

	Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(p_index);
	ERR_FAIL_COND(current.is_null());

	updating = true;

	presets->select(p_index);
	sections->show();

	name->set_editable(true);
	export_path->show();
	duplicate_preset->set_disabled(false);
	delete_preset->set_disabled(false);
	name->set_text(current->get_name());

	List<String> extension_list = current->get_platform()->get_binary_extensions(current);
	Vector<String> extension_vector;
	for (int i = 0; i < extension_list.size(); i++) {
		extension_vector.push_back("*." + extension_list[i]);
	}

	export_path->setup(extension_vector, false, true);
	export_path->update_property();
	runnable->set_disabled(false);
	runnable->set_pressed(current->is_runnable());
	parameters->edit(current.ptr());

	export_filter->select(current->get_export_filter());
	include_filters->set_text(current->get_include_filter());
	exclude_filters->set_text(current->get_exclude_filter());

	patches->clear();
	TreeItem *patch_root = patches->create_item();
	Vector<String> patchlist = current->get_patches();
	for (int i = 0; i < patchlist.size(); i++) {
		TreeItem *patch = patches->create_item(patch_root);
		patch->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
		String file = patchlist[i].get_file();
		patch->set_editable(0, true);
		patch->set_text(0, file.get_file().replace("*", ""));
		if (file.ends_with("*"))
			patch->set_checked(0, true);
		patch->set_tooltip(0, patchlist[i]);
		patch->set_metadata(0, i);
		patch->add_button(0, get_icon("Remove", "EditorIcons"), 0);
		patch->add_button(0, get_icon("folder", "FileDialog"), 1);
	}

	TreeItem *patch_add = patches->create_item(patch_root);
	patch_add->set_metadata(0, patchlist.size());
	if (patchlist.size() == 0)
		patch_add->set_text(0, "Add initial export...");
	else
		patch_add->set_text(0, "Add previous patches...");

	patch_add->add_button(0, get_icon("folder", "FileDialog"), 1);

	_fill_resource_tree();

	bool needs_templates;
	String error;
	if (!current->get_platform()->can_export(current, error, needs_templates)) {

		if (error != String()) {

			Vector<String> items = error.split("\n", false);
			error = "";
			for (int i = 0; i < items.size(); i++) {
				if (i > 0)
					error += "\n";
				error += " - " + items[i];
			}

			export_error->set_text(error);
			export_error->show();
		} else {
			export_error->hide();
		}
		if (needs_templates)
			export_templates_error->show();
		else
			export_templates_error->hide();

		export_button->set_disabled(true);

	} else {
		export_error->hide();
		export_templates_error->hide();
		export_button->set_disabled(false);
	}

	custom_features->set_text(current->get_custom_features());
	_update_feature_list();
	_update_export_all();
	minimum_size_changed();

	int script_export_mode = current->get_script_export_mode();
	script_mode->select(script_export_mode);

	String key = current->get_script_encryption_key();
	if (!updating_script_key) {
		script_key->set_text(key);
	}
	if (script_export_mode == EditorExportPreset::MODE_SCRIPT_ENCRYPTED) {
		script_key->set_editable(true);

		bool key_valid = _validate_script_encryption_key(key);
		if (key_valid) {
			script_key_error->hide();
		} else {
			script_key_error->show();
		}
	} else {
		script_key->set_editable(false);
		script_key_error->hide();
	}

	updating = false;
}
Example #16
0
void EditorFileSystem::update_file(const String &p_file) {

	EditorFileSystemDirectory *fs = NULL;
	int cpos = -1;

	if (!_find_file(p_file, &fs, cpos)) {

		if (!fs)
			return;
	}

	if (!FileAccess::exists(p_file)) {
		//was removed
		_delete_internal_files(p_file);
		memdelete(fs->files[cpos]);
		fs->files.remove(cpos);
		call_deferred("emit_signal", "filesystem_changed"); //update later
		return;
	}

	String type = ResourceLoader::get_resource_type(p_file);

	if (cpos == -1) {

		//the file did not exist, it was added

		late_added_files.insert(p_file); //remember that it was added. This mean it will be scanned and imported on editor restart
		int idx = 0;

		for (int i = 0; i < fs->files.size(); i++) {
			if (p_file < fs->files[i]->file)
				break;
			idx++;
		}

		EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
		fi->file = p_file.get_file();
		fi->import_modified_time = 0;

		if (idx == fs->files.size()) {
			fs->files.push_back(fi);
		} else {

			fs->files.insert(idx, fi);
		}
		cpos = idx;
	} else {

		//the file exists and it was updated, and was not added in this step.
		//this means we must force upon next restart to scan it again, to get proper type and dependencies
		late_update_files.insert(p_file);
		_save_late_updated_files(); //files need to be updated in the re-scan
	}

	//print_line("UPDATING: "+p_file);
	fs->files[cpos]->type = type;
	fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
	fs->files[cpos]->deps = _get_dependencies(p_file);
	//if (FileAccess::exists(p_file+".import")) {
	//	fs->files[cpos]->import_modified_time=FileAccess::get_modified_time(p_file+".import");
	//}

	EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation", p_file);
	call_deferred("emit_signal", "filesystem_changed"); //update later
}
Example #17
0
void EditorAutoloadSettings::_autoload_file_callback(const String &p_path) {

	autoload_add_name->set_text(p_path.get_file().get_basename());
}
Example #18
0
void EditorAssetInstaller::open(const String& p_path,int p_depth) {


	package_path=p_path;
	Set<String> files_sorted;

	FileAccess *src_f=NULL;
	zlib_filefunc_def io = zipio_create_io_from_file(&src_f);

	unzFile pkg = unzOpen2(p_path.utf8().get_data(), &io);
	if (!pkg) {

		error->set_text("Error opening package file, not in zip format.");
		return;
	}

	int ret = unzGoToFirstFile(pkg);


	while(ret==UNZ_OK) {

		//get filename
		unz_file_info info;
		char fname[16384];
		ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0);

		String name=fname;
		files_sorted.insert(name);

		ret = unzGoToNextFile(pkg);
	}


	Map<String,Ref<Texture> > extension_guess;
	{
		extension_guess["png"]=get_icon("Texture","EditorIcons");
		extension_guess["jpg"]=get_icon("Texture","EditorIcons");
		extension_guess["tex"]=get_icon("Texture","EditorIcons");
		extension_guess["atex"]=get_icon("Texture","EditorIcons");
		extension_guess["dds"]=get_icon("Texture","EditorIcons");
		extension_guess["scn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["tscn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["xml"]=get_icon("PackedScene","EditorIcons");
		extension_guess["xscn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["mtl"]=get_icon("Material","EditorIcons");
		extension_guess["shd"]=get_icon("Shader","EditorIcons");
		extension_guess["gd"]=get_icon("GDScript","EditorIcons");
	}

	Ref<Texture> generic_extension = get_icon("Object","EditorIcons");


	unzClose(pkg);

	updating=true;
	tree->clear();
	TreeItem *root=tree->create_item();
	root->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
	root->set_checked(0,true);
	root->set_icon(0,get_icon("folder","FileDialog"));
	root->set_text(0,"res://");
	root->set_editable(0,true);
	Map<String,TreeItem*> dir_map;

	for(Set<String>::Element *E=files_sorted.front();E;E=E->next()) {

		String path = E->get();
		int depth=p_depth;
		bool skip=false;
		while(depth>0) {
			int pp = path.find("/");
			if (pp==-1) {
				skip=true;
				break;
			}
			path=path.substr(pp+1,path.length());
			depth--;
		}

		if (skip || path==String())
			continue;

		bool isdir=false;

		if (path.ends_with("/")) {
			//a directory
			path=path.substr(0,path.length()-1);
			isdir=true;
		}

		int pp = path.find_last("/");


		TreeItem *parent;
		if (pp==-1) {
			parent=root;
		} else {
			String ppath=path.substr(0,pp);
			print_line("PPATH IS: "+ppath);
			ERR_CONTINUE(!dir_map.has(ppath));
			parent=dir_map[ppath];

		}

		TreeItem *ti = tree->create_item(parent);
		ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
		ti->set_checked(0,true);
		ti->set_editable(0,true);
		if (isdir) {
			dir_map[path]=ti;
			ti->set_text(0,path.get_file()+"/");
			ti->set_icon(0,get_icon("folder","FileDialog"));
		} else {
			String file = path.get_file();
			String extension = file.extension().to_lower();
			if (extension_guess.has(extension)) {
				ti->set_icon(0,extension_guess[extension]);
			} else {
				ti->set_icon(0,generic_extension);
			}
			ti->set_text(0,file);


			String res_path = "res://"+path;
			if (FileAccess::exists(res_path)) {
				ti->set_custom_color(0,Color(1,0.3,0.2));
				ti->set_tooltip(0,res_path+" (Already Exists)");
				ti->set_checked(0,false);
			} else {
				ti->set_tooltip(0,res_path);

			}

			ti->set_metadata(0,res_path);

		}

		status_map[E->get()]=ti;



	}
	popup_centered_ratio();
	updating=false;

}
Example #19
0
void EditorFileSystem::_scan_scenes() {

	ERR_FAIL_COND(!scanning || scandir);

	//read .fscache
	HashMap<String,FileCache> file_cache;
	HashMap<String,DirCache> dir_cache;
	DirCache *dc=NULL;
	String cpath;

	sources_changed.clear();



	String project=Globals::get_singleton()->get_resource_path();
	FileAccess *f =FileAccess::open(project+"/.fscache",FileAccess::READ);

	if (f) {
		//read the disk cache
		while(!f->eof_reached()) {

			String l = f->get_line().strip_edges();
			if (l==String())
				continue;

			if (l.begins_with("::")) {
				Vector<String> split = l.split("::");
				ERR_CONTINUE( split.size() != 3);
				String name = split[1];

				dir_cache[name]=DirCache();
				dc=&dir_cache[name];
				dc->modification_time=split[2].to_int64();

				if (name!="res://") {

					cpath=name+"/";

					int sp=name.find_last("/");
					if (sp==5)
						sp=6;
					String pd = name.substr(0,sp);
					DirCache *dcp = dir_cache.getptr(pd);
					ERR_CONTINUE(!dcp);
					dcp->subdirs.insert(name.get_file());
				} else {

					cpath=name;
				}


			} else {
				Vector<String> split = l.split("::");
				ERR_CONTINUE( split.size() != 4);
				String name = split[0];
				String file;

				if (!name.begins_with("res://")) {
					file=name;
					name=cpath+name;
				} else {
					file=name.get_file();
				}

				FileCache fc;
				fc.type=split[1];
				fc.modification_time=split[2].to_int64();
				String meta = split[3].strip_edges();
				fc.meta.enabled=false;
				if (meta.find("<>")!=-1){
					Vector<String> spl = meta.split("<>");
					int sc = spl.size()-1;
					if (sc%3==0){
						fc.meta.enabled=true;
						fc.meta.import_editor=spl[0];
						fc.meta.sources.resize(sc/3);
						for(int i=0;i<fc.meta.sources.size();i++) {
							fc.meta.sources[i].path=spl[1+i*3+0];
							fc.meta.sources[i].md5=spl[1+i*3+1];
							fc.meta.sources[i].modified_time=spl[1+i*3+2].to_int64();
						}

					}

				}
				file_cache[name]=fc;

				ERR_CONTINUE(!dc);
				dc->files.insert(file);
			}

		}

		f->close();
		memdelete(f);
	}






	total=0;
	DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	//da->change_dir( Globals::get_singleton()->get_resource_path() );


	List<String> extensionsl;
	ResourceLoader::get_recognized_extensions_for_type("",&extensionsl);
	Set<String> extensions;
	for(List<String>::Element *E = extensionsl.front();E;E=E->next()) {

		extensions.insert(E->get());
	}

	EditorProgressBG scan_progress("efs","ScanFS",100);

	md_count=0;
	scandir=_scan_dir(da,extensions,"",0,1,"",file_cache,dir_cache,scan_progress);
	memdelete(da);
	if (abort_scan && scandir) {
		memdelete(scandir);
		scandir=NULL;

	}


	//save back the findings
	f=FileAccess::open(project+"/.fscache",FileAccess::WRITE);
	_save_type_cache_fs(scandir,f);
	f->close();
	memdelete(f);

	scanning=false;

}
void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_progress) {

	FileAccess *fa = NULL;
	zlib_filefunc_def io = zipio_create_io_from_file(&fa);

	unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
	if (!pkg) {

		EditorNode::get_singleton()->show_warning(TTR("Can't open export templates zip."));
		return;
	}
	int ret = unzGoToFirstFile(pkg);

	int fc = 0; //count them and find version
	String version;

	while (ret == UNZ_OK) {

		unz_file_info info;
		char fname[16384];
		ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);

		String file = fname;

		if (file.ends_with("version.txt")) {

			Vector<uint8_t> data;
			data.resize(info.uncompressed_size);

			//read
			unzOpenCurrentFile(pkg);
			ret = unzReadCurrentFile(pkg, data.ptrw(), data.size());
			unzCloseCurrentFile(pkg);

			String data_str;
			data_str.parse_utf8((const char *)data.ptr(), data.size());
			data_str = data_str.strip_edges();

			// Version number should be of the form major.minor[.patch].status[.module_config]
			// so it can in theory have 3 or more slices.
			if (data_str.get_slice_count(".") < 3) {
				EditorNode::get_singleton()->show_warning(vformat(TTR("Invalid version.txt format inside templates: %s."), data_str));
				unzClose(pkg);
				return;
			}

			version = data_str;
		}

		if (file.get_file().size() != 0) {
			fc++;
		}

		ret = unzGoToNextFile(pkg);
	}

	if (version == String()) {
		EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside templates."));
		unzClose(pkg);
		return;
	}

	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);
	if (err != OK) {
		EditorNode::get_singleton()->show_warning(TTR("Error creating path for templates:") + "\n" + template_path);
		unzClose(pkg);
		return;
	}

	memdelete(d);

	ret = unzGoToFirstFile(pkg);

	EditorProgress *p = NULL;
	if (p_use_progress) {
		p = memnew(EditorProgress("ltask", TTR("Extracting Export Templates"), fc));
	}

	fc = 0;

	while (ret == UNZ_OK) {

		//get filename
		unz_file_info info;
		char fname[16384];
		unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);

		String file = String(fname).get_file();

		if (file.size() == 0) {
			ret = unzGoToNextFile(pkg);
			continue;
		}

		Vector<uint8_t> data;
		data.resize(info.uncompressed_size);

		//read
		unzOpenCurrentFile(pkg);
		unzReadCurrentFile(pkg, data.ptrw(), data.size());
		unzCloseCurrentFile(pkg);

		if (p) {
			p->step(TTR("Importing:") + " " + file, fc);
		}

		FileAccess *f = FileAccess::open(template_path.plus_file(file), FileAccess::WRITE);

		if (!f) {
			ret = unzGoToNextFile(pkg);
			fc++;
			ERR_CONTINUE(!f);
		}

		f->store_buffer(data.ptr(), data.size());

		memdelete(f);

		ret = unzGoToNextFile(pkg);
		fc++;
	}

	if (p) {
		memdelete(p);
	}

	unzClose(pkg);

	_update_template_list();
}
Example #21
0
void ProjectExportDialog::_edit_preset(int p_index) {

	if (p_index < 0 || p_index >= presets->get_item_count()) {
		name->set_text("");
		name->set_editable(false);
		runnable->set_disabled(true);
		parameters->edit(NULL);
		delete_preset->set_disabled(true);
		sections->hide();
		patches->clear();
		export_error->hide();
		export_templates_error->hide();
		return;
	}

	Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(p_index);
	ERR_FAIL_COND(current.is_null());

	updating = true;

	presets->select(p_index);
	sections->show();

	name->set_editable(true);
	delete_preset->set_disabled(false);
	name->set_text(current->get_name());
	runnable->set_disabled(false);
	runnable->set_pressed(current->is_runnable());
	parameters->edit(current.ptr());

	export_filter->select(current->get_export_filter());
	include_filters->set_text(current->get_include_filter());
	exclude_filters->set_text(current->get_exclude_filter());

	patches->clear();
	TreeItem *patch_root = patches->create_item();
	Vector<String> patchlist = current->get_patches();
	for (int i = 0; i < patchlist.size(); i++) {
		TreeItem *patch = patches->create_item(patch_root);
		patch->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
		String file = patchlist[i].get_file();
		patch->set_editable(0, true);
		patch->set_text(0, file.get_file().replace("*", ""));
		if (file.ends_with("*"))
			patch->set_checked(0, true);
		patch->set_tooltip(0, patchlist[i]);
		patch->set_metadata(0, i);
		patch->add_button(0, get_icon("Del", "EditorIcons"), 0);
		patch->add_button(0, get_icon("folder", "FileDialog"), 1);
	}

	TreeItem *patch_add = patches->create_item(patch_root);
	patch_add->set_metadata(0, patchlist.size());
	if (patchlist.size() == 0)
		patch_add->set_text(0, "Add initial export..");
	else
		patch_add->set_text(0, "Add previous patches..");

	patch_add->add_button(0, get_icon("folder", "FileDialog"), 1);

	_fill_resource_tree();

	bool needs_templates;
	String error;
	if (!current->get_platform()->can_export(current, error, needs_templates)) {

		if (error != String()) {

			Vector<String> items = error.split("\n");
			error = "";
			for (int i = 0; i < items.size(); i++) {
				if (i > 0)
					error += "\n";
				error += " - " + items[i];
			}

			export_error->set_text(error);
			export_error->show();
		} else {
			export_error->hide();
		}
		if (needs_templates)
			export_templates_error->show();
		else
			export_templates_error->hide();

		export_button->set_disabled(true);

	} else {
		export_error->hide();
		export_templates_error->hide();
		export_button->set_disabled(false);
	}

	custom_features->set_text(current->get_custom_features());
	_update_feature_list();

	updating = false;
}