void _import() {

		Vector<String> meshes = import_path->get_text().split(",");
		if (meshes.size()==0) {
			error_dialog->set_text(TTR("No meshes to import!"));
			error_dialog->popup_centered_minsize();
			return;
		}

		String dst = save_path->get_text();
		if (dst=="") {
			error_dialog->set_text(TTR("Save path is empty!"));
			error_dialog->popup_centered_minsize();
			return;
		}

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

			Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );

			List<PropertyInfo> pl;
			options->_get_property_list(&pl);
			for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {

				Variant v;
				String opt=E->get().name;
				options->_get(opt,v);
				imd->set_option(opt,v);

			}

			imd->add_source(EditorImportPlugin::validate_source_path(meshes[i]));

			String file_path = dst.plus_file(meshes[i].get_file().get_basename()+".msh");

			plugin->import(file_path,imd);
		}

		hide();
	}
Exemple #2
0
	void ok_pressed() {

		if (!_test_path())
			return;

		String dir;

		if (mode==MODE_IMPORT) {
			dir=project_path->get_text();


		} else {
			DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);

			if (d->change_dir(project_path->get_text())!=OK) {
				error->set_text(TTR("Invalid project path (changed anything?)."));
				memdelete(d);
				return;
			}

			dir=d->get_current_dir();
			memdelete(d);

			if (mode==MODE_NEW) {




				FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE);
				if (!f) {
					error->set_text(TTR("Couldn't create engine.cfg in project path."));
				} else {

					f->store_line("; Engine configuration file.");
					f->store_line("; It's best edited using the editor UI and not directly,");
					f->store_line("; since the parameters that go here are not all obvious.");
					f->store_line("; ");
					f->store_line("; Format: ");
					f->store_line(";   [section] ; section goes between []");
					f->store_line(";   param=value ; assign values to parameters");
					f->store_line("\n");
					f->store_line("[application]");
					f->store_line("\n");
					f->store_line("name=\""+project_name->get_text()+"\"");
					f->store_line("icon=\"res://icon.png\"");

					memdelete(f);

					ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons"));
				}

			} else if (mode==MODE_INSTALL) {


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

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

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

				int ret = unzGoToFirstFile(pkg);

				Vector<String> failed_files;

				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 path=fname;

					int depth=1; //stuff from github comes with tag
					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()) {
						//
					} else if (path.ends_with("/")) { // a dir

						path=path.substr(0,path.length()-1);

						DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
						da->make_dir(dir.plus_file(path));
						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(dir.plus_file(path),FileAccess::WRITE);

						if (f) {
							f->store_buffer(data.ptr(),data.size());
							memdelete(f);
						} else {
							failed_files.push_back(path);
						}


					}

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

				unzClose(pkg);

				if (failed_files.size()) {
					String msg=TTR("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]+"\n";
					}

					dialog_error->set_text(msg);
					dialog_error->popup_centered_minsize();

				} else {
					dialog_error->set_text(TTR("Package Installed Successfully!"));
					dialog_error->popup_centered_minsize();
				}

			}



		}

		dir=dir.replace("\\","/");
		if (dir.ends_with("/"))
			dir=dir.substr(0,dir.length()-1);
		String proj=dir.replace("/","::");
		EditorSettings::get_singleton()->set("projects/"+proj,dir);
		EditorSettings::get_singleton()->save();



		hide();
		emit_signal("project_created");

	}