Example #1
0
	void show_dialog() {


		project_path->clear();
		project_name->clear();

		if (import_mode) {
			set_title("Import Existing Project:");
			pp->set_text("Project Path: (Must exist)");
			pn->set_text("Project Name:");
			pn->hide();
			project_name->hide();

			popup_centered(Size2(500,125));

		} else {
			set_title("Create New Project:");
			pp->set_text("Project Path:");
			pn->set_text("Project Name:");
			pn->show();
			project_name->show();

			popup_centered(Size2(500,145));

		}


		_test_path();
	}
Example #2
0
	void _path_text_changed(const String& p_path) {

		String sp=_test_path();
		if ( sp!="" ) {

			sp=sp.replace("\\","/");
			int lidx=sp.find_last("/");

			if (lidx!=-1) {
				sp=sp.substr(lidx+1,sp.length());
			}
			if (sp=="" && mode==MODE_IMPORT )
				sp=TTR("Imported Project");

			project_name->set_text(sp);
		}
	}
Example #3
0
	void _path_text_changed(const String& p_path) {

		if ( _test_path() ) {

			String sp=p_path;

			sp=sp.replace("\\","/");
			int lidx=sp.find_last("/");

			if (lidx!=-1) {
				sp=sp.substr(lidx+1,sp.length());
			}
			if (sp=="" && import_mode )
				sp="Imported Project";

			project_name->set_text(sp);
		}
	}
Example #4
0
	void show_dialog() {


		project_path->clear();
		project_name->clear();

		if (mode==MODE_IMPORT) {
			set_title(TTR("Import Existing Project"));
			get_ok()->set_text(TTR("Import"));
			pp->set_text(TTR("Project Path (Must Exist):"));
			pn->set_text(TTR("Project Name:"));
			pn->hide();
			project_name->hide();

			popup_centered(Size2(500,125)*EDSCALE);

		} else if (mode==MODE_NEW){

			set_title(TTR("Create New Project"));
			get_ok()->set_text(TTR("Create"));
			pp->set_text(TTR("Project Path:"));
			pn->set_text(TTR("Project Name:"));
			pn->show();
			project_name->show();

			popup_centered(Size2(500,145)*EDSCALE);
		} else if (mode==MODE_INSTALL){

			set_title(TTR("Install Project:")+" "+zip_title);
			get_ok()->set_text(TTR("Install"));
			pp->set_text(TTR("Project Path:"));
			pn->hide();
			project_name->hide();

			popup_centered(Size2(500,125)*EDSCALE);

		}


		_test_path();
	}
Example #5
0
	void ok_pressed() {

		if (!_test_path())
			return;

		String dir;

		if (import_mode) {
			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("Invalid Path for Project (changed anything?)");
				memdelete(d);
				return;
			}

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

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

				f->store_line("; Engine configuration file.");
				f->store_line("; It's best to edit using the editor UI, not directly,");
				f->store_line("; becausethe parameters that go here are not 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("name=\""+project_name->get_text()+"\"");
				f->store_line("icon=\"icon.png\"");

				memdelete(f);

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



		}

		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");

	}
Example #6
0
	void _text_changed(const String& p_text) {
		_test_path();
	}
Example #7
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");

	}