Example #1
0
MonoAssembly *gdmono_MonoAssemblyPreLoad(MonoAssemblyName *aname, char **assemblies_path, void *user_data) {

	(void)user_data; // UNUSED

	MonoAssembly *assembly_loaded = mono_assembly_loaded(aname);
	if (assembly_loaded) // Already loaded
		return assembly_loaded;

	static Vector<String> search_dirs;

	if (search_dirs.empty()) {
		search_dirs.push_back(GodotSharpDirs::get_res_temp_assemblies_dir());
		search_dirs.push_back(GodotSharpDirs::get_res_assemblies_dir());
		search_dirs.push_back(OS::get_singleton()->get_resource_dir());
		search_dirs.push_back(OS::get_singleton()->get_executable_path().get_base_dir());

		const char *rootdir = mono_assembly_getrootdir();
		if (rootdir) {
			search_dirs.push_back(String(rootdir).plus_file("mono").plus_file("4.5"));
		}

		while (assemblies_path) {
			if (*assemblies_path)
				search_dirs.push_back(*assemblies_path);
			++assemblies_path;
		}
	}

	String name = mono_assembly_name_get_name(aname);
	bool has_extension = name.ends_with(".dll") || name.ends_with(".exe");

	String path;

	for (int i = 0; i < search_dirs.size(); i++) {
		const String &search_dir = search_dirs[i];

		if (has_extension) {
			path = search_dir.plus_file(name);
			if (FileAccess::exists(path))
				return gdmono_load_assembly_from(name.get_basename(), path);
		} else {
			path = search_dir.plus_file(name + ".dll");
			if (FileAccess::exists(path))
				return gdmono_load_assembly_from(name, path);

			path = search_dir.plus_file(name + ".exe");
			if (FileAccess::exists(path))
				return gdmono_load_assembly_from(name, path);
		}
	}

	return NULL;
}
Example #2
0
void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) {

	Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
	ERR_FAIL_COND(current.is_null());
	Ref<EditorExportPlatform> platform = current->get_platform();
	ERR_FAIL_COND(platform.is_null());

	if (p_path.ends_with(".zip")) {
		platform->save_zip(current, p_path);
	} else if (p_path.ends_with(".pck")) {
		platform->save_pack(current, p_path);
	}
}
Example #3
0
void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) {

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

	if (p_path.ends_with(".zip")) {
		platform->export_zip(current, export_pck_zip_debug->is_pressed(), p_path);
	} else if (p_path.ends_with(".pck")) {
		platform->export_pack(current, export_pck_zip_debug->is_pressed(), p_path);
	}
}
Example #4
0
Error DocData::load_classes(const String &p_dir) {

	Error err;
	DirAccessRef da = DirAccess::open(p_dir, &err);
	if (!da) {
		return err;
	}

	da->list_dir_begin();
	String path;
	bool isdir;
	path = da->get_next(&isdir);
	while (path != String()) {
		if (!isdir && path.ends_with("xml")) {
			Ref<XMLParser> parser = memnew(XMLParser);
			Error err = parser->open(p_dir.plus_file(path));
			if (err)
				return err;

			_load(parser);
		}
		path = da->get_next(&isdir);
	}

	da->list_dir_end();

	return OK;
}
Example #5
0
void RotatedFileLogger::clear_old_backups() {
	int max_backups = max_files - 1; // -1 for the current file

	String basename = base_path.get_file().get_basename();
	String extension = "." + base_path.get_extension();

	DirAccess *da = DirAccess::open(base_path.get_base_dir());
	if (!da) {
		return;
	}

	da->list_dir_begin();
	String f = da->get_next();
	Set<String> backups;
	while (f != String()) {
		if (!da->current_is_dir() && f.begins_with(basename) && f.ends_with(extension) && f != base_path.get_file()) {
			backups.insert(f);
		}
		f = da->get_next();
	}
	da->list_dir_end();

	if (backups.size() > max_backups) {
		// since backups are appended with timestamp and Set iterates them in sorted order,
		// first backups are the oldest
		int to_delete = backups.size() - max_backups;
		for (Set<String>::Element *E = backups.front(); E && to_delete > 0; E = E->next(), --to_delete) {
			da->remove(E->get());
		}
	}

	memdelete(da);
}
Example #6
0
Error DocData::erase_classes(const String &p_dir) {

	Error err;
	DirAccessRef da = DirAccess::open(p_dir, &err);
	if (!da) {
		return err;
	}

	List<String> to_erase;

	da->list_dir_begin();
	String path;
	bool isdir;
	path = da->get_next(&isdir);
	while (path != String()) {
		if (!isdir && path.ends_with("xml")) {
			to_erase.push_back(path);
		}
		path = da->get_next(&isdir);
	}
	da->list_dir_end();

	while (to_erase.size()) {
		da->remove(to_erase.front()->get());
		to_erase.pop_front();
	}

	return OK;
}
Example #7
0
void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) {

	static const uint64_t MAX_SECS = 5 * 86400;

	DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	ERR_FAIL_COND(!da);

	Error err = da->change_dir(p_logs_dir);
	ERR_FAIL_COND(err != OK);

	ERR_FAIL_COND(da->list_dir_begin() != OK);

	String current;
	while ((current = da->get_next()).length()) {
		if (da->current_is_dir())
			continue;
		if (!current.ends_with(".txt"))
			continue;

		String name = current.get_basename();
		uint64_t unixtime = (uint64_t)name.to_int64();

		if (OS::get_singleton()->get_unix_time() - unixtime > MAX_SECS) {
			da->remove(current);
		}
	}

	da->list_dir_end();
}
Example #8
0
String FilePath::create(const char * directory, const char * base)
{
    if (!directory || StringLength(directory) == 0) return base;
    if (!base || StringLength(base) == 0) return directory;

    String result = directory;
    if (!result.ends_with(separator) && base[0] != separator[0]) {
        result += separator;
    }
    result += base;
    return result;
}
Example #9
0
EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String& p_path) {

    if (!filesystem || scanning)
    	return NULL;


    String f = GlobalConfig::get_singleton()->localize_path(p_path);

    if (!f.begins_with("res://"))
    	return NULL;


    f=f.substr(6,f.length());
    f=f.replace("\\","/");
    if (f==String())
    	return filesystem;

    if (f.ends_with("/"))
	f=f.substr(0,f.length()-1);

    Vector<String> path = f.split("/");

    if (path.size()==0)
    	return NULL;

    EditorFileSystemDirectory *fs=filesystem;

    for(int i=0;i<path.size();i++) {


	int idx=-1;
	for(int j=0;j<fs->get_subdir_count();j++) {

	    if (fs->get_subdir(j)->get_name()==path[i]) {
		idx=j;
		break;
	    }
	}

	if (idx==-1) {
		return NULL;
	} else {

	    fs=fs->get_subdir(idx);
	}
    }

    return fs;
}
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 #11
0
void godot_icall_BuildInstance_get_MSBuildInfo(MonoString **r_msbuild_path, MonoString **r_framework_path) {

	GodotSharpBuilds::BuildTool build_tool = GodotSharpBuilds::BuildTool(int(EditorSettings::get_singleton()->get("mono/builds/build_tool")));

#if defined(WINDOWS_ENABLED)
	switch (build_tool) {
		case GodotSharpBuilds::MSBUILD: {
			static String msbuild_tools_path = MonoRegUtils::find_msbuild_tools_path();

			if (msbuild_tools_path.length()) {
				if (!msbuild_tools_path.ends_with("\\"))
					msbuild_tools_path += "\\";

				// FrameworkPathOverride
				const MonoRegInfo &mono_reg_info = GDMono::get_singleton()->get_mono_reg_info();
				if (mono_reg_info.assembly_dir.length()) {
					*r_msbuild_path = GDMonoMarshal::mono_string_from_godot(msbuild_tools_path + "MSBuild.exe");

					String framework_path = path_join(mono_reg_info.assembly_dir, "mono", "4.5");
					*r_framework_path = GDMonoMarshal::mono_string_from_godot(framework_path);
				} else {
					ERR_PRINT("Cannot find Mono's assemblies directory in the registry");
				}

				return;
			}

			if (OS::get_singleton()->is_stdout_verbose())
				OS::get_singleton()->print("Cannot find System's MSBuild. Trying with Mono's...\n");
		} // fall through
		case GodotSharpBuilds::MSBUILD_MONO: {
			String msbuild_path = GDMono::get_singleton()->get_mono_reg_info().bin_dir.plus_file("msbuild.bat");

			if (!FileAccess::exists(msbuild_path)) {
				WARN_PRINTS("Cannot find msbuild ('mono/builds/build_tool'). Tried with path: " + msbuild_path);
			}

			*r_msbuild_path = GDMonoMarshal::mono_string_from_godot(msbuild_path);

			return;
		} break;
		default:
			ERR_EXPLAIN("You don't deserve to live");
			CRASH_NOW();
	}
#elif defined(UNIX_ENABLED)
	static String msbuild_path = _find_build_engine_on_unix("msbuild");
	static String xbuild_path = _find_build_engine_on_unix("xbuild");

	if (build_tool != GodotSharpBuilds::XBUILD) {
		if (msbuild_path.empty()) {
			WARN_PRINT("Cannot find msbuild ('mono/builds/build_tool').");
			return;
		}
	} else {
		if (xbuild_path.empty()) {
			WARN_PRINT("Cannot find xbuild ('mono/builds/build_tool').");
			return;
		}
	}

	*r_msbuild_path = GDMonoMarshal::mono_string_from_godot(build_tool != GodotSharpBuilds::XBUILD ? msbuild_path : xbuild_path);

	return;
#else
	ERR_PRINT("Not implemented on this platform");
	return;
#endif
}
Example #12
0
void EditorHelpSearch::_update_search() {

	search_options->clear();
	search_options->set_hide_root(true);

	/*
	TreeItem *root = search_options->create_item();
	_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
*/

	List<StringName> type_list;
	ObjectTypeDB::get_type_list(&type_list);

	DocData *doc=EditorHelp::get_doc_data();
	String term = search_box->get_text();
	if (term.length()<2)
		return;

	TreeItem *root = search_options->create_item();



	Ref<Texture> def_icon = get_icon("Node","EditorIcons");
	//classes first
	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {

		if (E->key().findn(term)!=-1) {

			TreeItem *item = search_options->create_item(root);
			item->set_metadata(0,"class_name:"+E->key());
			item->set_text(0,E->key()+" (Class)");
			if (has_icon(E->key(),"EditorIcons"))
				item->set_icon(0,get_icon(E->key(),"EditorIcons"));
			else
				item->set_icon(0,def_icon);


		}

	}

	//class methods, etc second
	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {


		DocData::ClassDoc & c = E->get();

		Ref<Texture> cicon;
		if (has_icon(E->key(),"EditorIcons"))
			cicon=get_icon(E->key(),"EditorIcons");
		else
			cicon=def_icon;


		for(int i=0;i<c.methods.size();i++) {
			if( (term.begins_with(".") && c.methods[i].name.begins_with(term.right(1)))
				|| (term.ends_with("(") && c.methods[i].name.ends_with(term.left(term.length()-1).strip_edges()))
				|| (term.begins_with(".") && term.ends_with("(") && c.methods[i].name==term.substr(1,term.length()-2).strip_edges())
				|| c.methods[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_method:"+E->key()+":"+c.methods[i].name);
				item->set_text(0,E->key()+"."+c.methods[i].name+" (Method)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.signals.size();i++) {

			if (c.signals[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
				item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.constants.size();i++) {

			if (c.constants[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
				item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.properties.size();i++) {

			if (c.properties[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_property:"+E->key()+":"+c.properties[i].name);
				item->set_text(0,E->key()+"."+c.properties[i].name+" (Property)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.theme_properties.size();i++) {

			if (c.theme_properties[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_theme_item:"+E->key()+":"+c.theme_properties[i].name);
				item->set_text(0,E->key()+"."+c.theme_properties[i].name+" (Theme Item)");
				item->set_icon(0,cicon);
			}
		}


	}

	//same but descriptions

	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {


		DocData::ClassDoc & c = E->get();

		Ref<Texture> cicon;
		if (has_icon(E->key(),"EditorIcons"))
			cicon=get_icon(E->key(),"EditorIcons");
		else
			cicon=def_icon;

		if (c.description.findn(term)!=-1) {


			TreeItem *item = search_options->create_item(root);
			item->set_metadata(0,"class_desc:"+E->key());
			item->set_text(0,E->key()+" (Class Description)");
			item->set_icon(0,cicon);

		}

		for(int i=0;i<c.methods.size();i++) {

			if (c.methods[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_method_desc:"+E->key()+":"+c.methods[i].name);
				item->set_text(0,E->key()+"."+c.methods[i].name+" (Method Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.signals.size();i++) {

			if (c.signals[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
				item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.constants.size();i++) {

			if (c.constants[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
				item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.properties.size();i++) {

			if (c.properties[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_property_desc:"+E->key()+":"+c.properties[i].name);
				item->set_text(0,E->key()+"."+c.properties[i].name+" (Property Description)");
				item->set_icon(0,cicon);
			}
		}

	}

	get_ok()->set_disabled(root->get_children()==NULL);

}
Example #13
0
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< String, Ref<Texture> > > &list) {

	if (!add_directories) {
		for(int i=0;i<efsd->get_subdir_count();i++) {

			_parse_fs(efsd->get_subdir(i), list);
		}
	}

	String search_text = search_box->get_text();

	if (add_directories) {
		String path = efsd->get_path();
		if (!path.ends_with("/"))
			path+="/";
		if (path!="res://") {
			path=path.substr(6,path.length());
			if (search_text.is_subsequence_ofi(path)) {
				Pair< String, Ref<Texture> > pair;
				pair.first = path;
				pair.second = get_icon("folder", "FileDialog");

				if (search_text != String() && list.size() > 0) {

					float this_sim = _path_cmp(search_text, path);
					float other_sim = _path_cmp(list[0].first, path);
					int pos = 1;

					while (pos < list.size() && this_sim <= other_sim) {
						other_sim = _path_cmp(list[pos++].first, path);
					}

					pos = this_sim >= other_sim ? pos - 1 : pos;
					list.insert(pos, pair);

				} else {
					list.push_back(pair);
				}
			}
		}
	}
	for(int i=0;i<efsd->get_file_count();i++) {

		String file = efsd->get_file_path(i);
		file=file.substr(6,file.length());

		if (ClassDB::is_parent_class(efsd->get_file_type(i),base_type) && (search_text.is_subsequence_ofi(file))) {
			Pair< String, Ref<Texture> > pair;
			pair.first = file;
			pair.second = get_icon((has_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei);

			if (search_text != String() && list.size() > 0) {

				float this_sim = _path_cmp(search_text, file);
				float other_sim = _path_cmp(list[0].first, file);
				int pos = 1;

				while (pos < list.size() && this_sim <= other_sim) {
					other_sim = _path_cmp(list[pos++].first, file);
				}

				pos = this_sim >= other_sim ? pos - 1 : pos;
				list.insert(pos, pair);

			} else {

				list.push_back(pair);
			}
		}
	}


	if (add_directories) {
		for(int i=0;i<efsd->get_subdir_count();i++) {

			_parse_fs(efsd->get_subdir(i), list);
		}
	}

}
Example #14
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 #15
0
Error EditorExportPlatformBB10::export_project(const String& p_path, bool p_debug, int p_flags) {


	EditorProgress ep("export","Exporting for BlackBerry 10",104);

	String src_template=custom_package;

	if (src_template=="") {
		String err;
		src_template = find_export_template("bb10.zip", &err);
		if (src_template=="") {
			EditorNode::add_io_error(err);
			return ERR_FILE_NOT_FOUND;
		}
	}

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

	ep.step("Creating FileSystem for BAR",0);

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

		EditorNode::add_io_error("Could not find template zip to export:\n"+src_template);
		return ERR_FILE_NOT_FOUND;
	}

	DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	da->change_dir(EditorSettings::get_singleton()->get_settings_path());


	if (da->change_dir("tmp")!=OK) {
		da->make_dir("tmp");
		if (da->change_dir("tmp")!=OK)
			return ERR_CANT_CREATE;
	}

	if (da->change_dir("bb10_export")!=OK) {
		da->make_dir("bb10_export");
		if (da->change_dir("bb10_export")!=OK) {
			return ERR_CANT_CREATE;
		}
	}


	String bar_dir = da->get_current_dir();
	if (bar_dir.ends_with("/")) {
		bar_dir=bar_dir.substr(0,bar_dir.length()-1);
	}

	//THIS IS SUPER, SUPER DANGEROUS!!!!
	//CAREFUL WITH THIS CODE, MIGHT DELETE USERS HARD DRIVE OR HOME DIR
	//EXTRA CHECKS ARE IN PLACE EVERYWERE TO MAKE SURE NOTHING BAD HAPPENS BUT STILL....
	//BE SUPER CAREFUL WITH THIS PLEASE!!!
	//BLACKBERRY THIS IS YOUR FAULT FOR NOT MAKING A BETTER WAY!!

	bool berr = bar_dir.ends_with("bb10_export");
	if (berr) {
		if (da->list_dir_begin()) {
			EditorNode::add_io_error("Can't ensure that dir is empty:\n"+bar_dir);
			ERR_FAIL_COND_V(berr,FAILED);
		};

		String f = da->get_next();
		while (f != "") {

			if (f == "." || f == "..") {
				f = da->get_next();
				continue;
			};
			Error err = da->remove(bar_dir + "/" + f);
			if (err != OK) {
				EditorNode::add_io_error("Can't ensure that dir is empty:\n"+bar_dir);
				ERR_FAIL_COND_V(err!=OK,err);
			};
			f = da->get_next();
		};

		da->list_dir_end();

	} else {
		print_line("ARE YOU CRAZY??? THIS IS A SERIOUS BUG HERE!!!");
		ERR_FAIL_V(ERR_OMFG_THIS_IS_VERY_VERY_BAD);
	}


	ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN);
	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 file=fname;

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

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

		//write

		if (file=="bar-descriptor.xml") {

			_fix_descriptor(data);
		}

		if (file=="icon.png") {
			bool found=false;

			if (this->icon!="" && this->icon.ends_with(".png")) {

				FileAccess *f = FileAccess::open(this->icon,FileAccess::READ);
				if (f) {

					data.resize(f->get_len());
					f->get_buffer(data.ptr(),data.size());
					memdelete(f);
					found=true;
				}

			}

			if (!found) {

				String appicon = GlobalConfig::get_singleton()->get("application/icon");
				if (appicon!="" && appicon.ends_with(".png")) {
					FileAccess*f = FileAccess::open(appicon,FileAccess::READ);
					if (f) {
						data.resize(f->get_len());
						f->get_buffer(data.ptr(),data.size());
						memdelete(f);
					}
				}
			}
		}


		if (file.find("/")) {

			da->make_dir_recursive(file.get_base_dir());
		}

		FileAccessRef wf = FileAccess::open(bar_dir.plus_file(file),FileAccess::WRITE);
		wf->store_buffer(data.ptr(),data.size());

		ret = unzGoToNextFile(pkg);
	}

	ep.step("Adding Files..",2);

	FileAccess* dst = FileAccess::open(bar_dir+"/data.pck", FileAccess::WRITE);
	if (!dst) {
		EditorNode::add_io_error("Can't copy executable file to:\n "+p_path);
		return ERR_FILE_CANT_WRITE;
	}
	save_pack(dst, false, 1024);
	dst->close();
	memdelete(dst);

	ep.step("Creating BAR Package..",104);

	String bb_packager=EditorSettings::get_singleton()->get("export/blackberry/host_tools");
	bb_packager=bb_packager.plus_file("blackberry-nativepackager");
	if (OS::get_singleton()->get_name()=="Windows")
		bb_packager+=".bat";


	if (!FileAccess::exists(bb_packager)) {
		EditorNode::add_io_error("Can't find packager:\n"+bb_packager);
		return ERR_CANT_OPEN;
	}

	List<String> args;
	args.push_back("-package");
	args.push_back(p_path);
	if (p_debug) {

		String debug_token=EditorSettings::get_singleton()->get("export/blackberry/debug_token");
		if (!FileAccess::exists(debug_token)) {
			EditorNode::add_io_error("Debug token not found!");
		} else {
			args.push_back("-debugToken");
			args.push_back(debug_token);
		}
		args.push_back("-devMode");
		args.push_back("-configuration");
		args.push_back("Device-Debug");
	} else {

		args.push_back("-configuration");
		args.push_back("Device-Release");
	}
	args.push_back(bar_dir.plus_file("bar-descriptor.xml"));

	int ec;

	Error err = OS::get_singleton()->execute(bb_packager,args,true,NULL,NULL,&ec);

	if (err!=OK)
		return err;
	if (ec!=0)
		return ERR_CANT_CREATE;

	return OK;

}
Example #16
0
void EditorAssetInstaller::ok_pressed() {

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

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

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

	int ret = unzGoToFirstFile(pkg);

	Vector<String> failed_files;

	ProgressDialog::get_singleton()->add_task("uncompress","Uncompressing Assets",status_map.size());

	int idx=0;
	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;

		if (status_map.has(name) && status_map[name]->is_checked(0)) {

			String path = status_map[name]->get_metadata(0);
			if (path==String()) { // a dir

				String dirpath;
				TreeItem *t = status_map[name];
				while(t) {
					dirpath=t->get_text(0)+dirpath;
					t=t->get_parent();
				}

				if (dirpath.ends_with("/")) {
					dirpath=dirpath.substr(0,dirpath.length()-1);
				}

				DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
				da->make_dir(dirpath);
				memdelete(da);

			} else {

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

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

				FileAccess *f=FileAccess::open(path,FileAccess::WRITE);
				if (f) {
					f->store_buffer(data.ptr(),data.size());
					memdelete(f);
				} else {
					failed_files.push_back(path);
				}

				ProgressDialog::get_singleton()->task_step("uncompress",path,idx);
			}

		}

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

	ProgressDialog::get_singleton()->end_task("uncompress");
	unzClose(pkg);

	if (failed_files.size()) {
		String msg="The following files failed extraction from package:\n\n";
		for(int i=0;i<failed_files.size();i++) {

			if (i>15) {
				msg+="\nAnd "+itos(failed_files.size()-i)+" more files.";
				break;
			}
			msg+=failed_files[i];
		}
		if (EditorNode::get_singleton() != NULL)
			EditorNode::get_singleton()->show_warning(msg);
	} else {
		if (EditorNode::get_singleton() != NULL)
			EditorNode::get_singleton()->show_warning("Package Installed Successfully!","Success!");
	}




}
Example #17
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;
}
Example #18
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 #19
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;

}