NewProjectDialog() { VBoxContainer *vb = memnew( VBoxContainer ); add_child(vb); set_child_rect(vb); Label* l = memnew(Label); l->set_text("Project Path:"); vb->add_child(l); pp=l; project_path = memnew( LineEdit ); MarginContainer *mc = memnew( MarginContainer ); vb->add_child(mc); HBoxContainer *pphb = memnew( HBoxContainer ); mc->add_child(pphb); pphb->add_child(project_path); project_path->set_h_size_flags(SIZE_EXPAND_FILL); Button* browse = memnew( Button ); pphb->add_child(browse); browse->set_text("Browse"); browse->connect("pressed", this,"_browse_path"); l = memnew(Label); l->set_text("Project Name:"); l->set_pos(Point2(5,50)); vb->add_child(l); pn=l; project_name = memnew( LineEdit ); mc = memnew( MarginContainer ); vb->add_child(mc); mc->add_child(project_name); project_name->set_text("New Game Project"); l = memnew(Label); l->set_text("That's a BINGO!"); vb->add_child(l); error=l; l->add_color_override("font_color",Color(1,0.4,0.3,0.8)); l->set_align(Label::ALIGN_CENTER); get_ok()->set_text("Create"); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); project_path->set_text(d->get_current_dir()); memdelete(d); fdialog = memnew( FileDialog ); add_child(fdialog); fdialog->set_access(FileDialog::ACCESS_FILESYSTEM); project_name->connect("text_changed", this,"_text_changed"); project_path->connect("text_changed", this,"_path_text_changed"); fdialog->connect("dir_selected", this,"_path_selected"); fdialog->connect("file_selected", this,"_file_selected"); set_hide_on_ok(false); import_mode=false; }
void OSIPhone::set_data_dir(String p_dir) { DirAccess* da = DirAccess::open(p_dir); data_dir = da->get_current_dir(); memdelete(da); };
void OSIPhone::set_data_dir(String p_dir) { DirAccess *da = DirAccess::open(p_dir); data_dir = da->get_current_dir(); printf("setting data dir to %ls from %ls\n", data_dir.c_str(), p_dir.c_str()); memdelete(da); };
String DirAccess::get_full_path(const String &p_path, AccessType p_access) { DirAccess *d = DirAccess::create(p_access); if (!d) return p_path; d->change_dir(p_path); String full = d->get_current_dir(); memdelete(d); return full; }
void ScenesDock::_go_to_dir(const String& p_dir){ DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (da->change_dir(p_dir)==OK) { path=da->get_current_dir(); _update_files(false); } current_path->set_text(path); memdelete(da); }
String ProjectSettings::localize_path(const String &p_path) const { if (resource_path == "") return p_path; //not initialized yet if (p_path.begins_with("res://") || p_path.begins_with("user://") || (p_path.is_abs_path() && !p_path.begins_with(resource_path))) return p_path.simplify_path(); DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String path = p_path.replace("\\", "/").simplify_path(); if (dir->change_dir(path) == OK) { String cwd = dir->get_current_dir(); cwd = cwd.replace("\\", "/"); memdelete(dir); // Ensure that we end with a '/'. // This is important to ensure that we do not wrongly localize the resource path // in an absolute path that just happens to contain this string but points to a // different folder (e.g. "/my/project" as resource_path would be contained in // "/my/project_data", even though the latter is not part of res://. // `plus_file("")` is an easy way to ensure we have a trailing '/'. const String res_path = resource_path.plus_file(""); if (!cwd.begins_with(res_path)) { return p_path; }; return cwd.replace_first(res_path, "res://"); } else { memdelete(dir); int sep = path.find_last("/"); if (sep == -1) { return "res://" + path; }; String parent = path.substr(0, sep); String plocal = localize_path(parent); if (plocal == "") { return ""; }; return plocal + path.substr(sep, path.size() - sep); }; }
MainLoop *test() { print_line("this is test io"); DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); da->change_dir("."); print_line("Opening current dir " + da->get_current_dir()); String entry; da->list_dir_begin(); while ((entry = da->get_next()) != "") { print_line("entry " + entry + " is dir: " + Variant(da->current_is_dir())); }; da->list_dir_end(); RES texture = ResourceLoader::load("test_data/rock.png"); ERR_FAIL_COND_V(texture.is_null(), NULL); ResourceSaver::save("test_data/rock.xml", texture); print_line("localize paths"); print_line(ProjectSettings::get_singleton()->localize_path("algo.xml")); print_line(ProjectSettings::get_singleton()->localize_path("c:\\windows\\algo.xml")); print_line(ProjectSettings::get_singleton()->localize_path(ProjectSettings::get_singleton()->get_resource_path() + "/something/something.xml")); print_line(ProjectSettings::get_singleton()->localize_path("somedir/algo.xml")); { FileAccess *z = FileAccess::open("test_data/archive.zip", FileAccess::READ); int len = z->get_len(); Vector<uint8_t> zip; zip.resize(len); z->get_buffer(&zip[0], len); z->close(); memdelete(z); FileAccessMemory::register_file("a_package", zip); FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_RESOURCES); FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_FILESYSTEM); FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_USERDATA); print_line("archive test"); }; print_line("test done"); return memnew(TestMainLoop); }
String Globals::localize_path(const String& p_path) const { if (resource_path=="") return p_path; //not initialied yet if (p_path.begins_with("res://") || p_path.begins_with("user://") || (p_path.is_abs_path() && !p_path.begins_with(resource_path))) return p_path.simplify_path(); DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String path = p_path.replace("\\","/").simplify_path(); if (dir->change_dir(path)==OK) { String cwd = dir->get_current_dir(); cwd = cwd.replace("\\","/"); memdelete(dir); if (!cwd.begins_with(resource_path)) { return p_path; }; return cwd.replace_first(resource_path, "res:/"); } else { memdelete(dir); int sep = path.find_last("/"); if (sep == -1) { return "res://"+path; }; String parent = path.substr(0, sep); String plocal = localize_path(parent); if (plocal == "") { return ""; }; return plocal + path.substr(sep, path.size() - sep); }; }
MainLoop* test() { print_line("this is test io"); DirAccess* da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); da->change_dir("."); print_line("Opening current dir "+ da->get_current_dir()); String entry; da->list_dir_begin(); while ( (entry = da->get_next()) != "") { print_line("entry "+entry+" is dir: " + Variant(da->current_is_dir())); }; da->list_dir_end(); RES texture = ResourceLoader::load("test_data/rock.png"); ERR_FAIL_COND_V(texture.is_null(), NULL); ResourceSaver::save("test_data/rock.xml",texture); print_line("localize paths"); print_line(Globals::get_singleton()->localize_path("algo.xml")); print_line(Globals::get_singleton()->localize_path("c:\\windows\\algo.xml")); print_line(Globals::get_singleton()->localize_path(Globals::get_singleton()->get_resource_path()+"/something/something.xml")); print_line(Globals::get_singleton()->localize_path("somedir/algo.xml")); { FileAccess* z = FileAccess::open("test_data/archive.zip", FileAccess::READ); int len = z->get_len(); Vector<uint8_t> zip; zip.resize(len); z->get_buffer(&zip[0], len); z->close(); memdelete(z); FileAccessMemory::register_file("a_package", zip); FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_RESOURCES); FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_FILESYSTEM); FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_USERDATA); print_line("archive test"); #if 0 Archive arch; Archive::get_singleton()->add_package("a_package"); FileAccessArchive f; print_line("opening for read"); f._open("file.txt", FileAccess::READ); int pos = f.get_pos(); printf("file has %i bytes, initial pos %i\n", (int)f.get_len(), pos); do { printf("%c", f.get_8()); } while (!f.eof_reached()); print_line("opening for stored seek"); f.open("seek.bin", FileAccess::READ); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); f.seek(128); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); print_line("opening for deflated seek"); f.open("seek_deflated.bin", FileAccess::READ); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); f.seek(128); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); f.seek(256); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); f.seek(4); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); pos = f.get_pos(); printf("byte at pos %i is %i\n", pos, (int)f.get_8()); f.close(); DirAccessArchive d; String dir = "../blah1/blah2/blahask/../blah3/.//blah4/"; printf("changing dir to %s\n", dir.utf8().get_data()); d.change_dir(dir); printf("current dir is %s\n", d.get_current_dir().utf8().get_data()); FileAccessMemory::cleanup(); #endif }; print_line("test done"); return memnew( TestMainLoop ); }
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"); }
bool Main::start() { ERR_FAIL_COND_V(!_start_success,false); bool editor=false; String doc_tool; bool doc_base=true; String game_path; String script; String test; String screen; String optimize; String optimize_preset; String _export_platform; String _import; String _import_script; String dumpstrings; bool noquit=false; bool convert_old=false; bool export_debug=false; bool project_manager_request = false; List<String> args = OS::get_singleton()->get_cmdline_args(); for (int i=0;i<args.size();i++) { //parameters that do not have an argument to the right if (args[i]=="-nodocbase") { doc_base=false; } else if (args[i]=="-noquit") { noquit=true; } else if (args[i]=="-convert_old") { convert_old=true; } else if (args[i]=="-editor" || args[i]=="-e") { editor=true; } else if (args[i] == "-pm" || args[i] == "-project_manager") { project_manager_request = true; } else if (args[i].length() && args[i][0] != '-' && game_path == "") { game_path=args[i]; } //parameters that have an argument to the right else if (i < (args.size()-1)) { bool parsed_pair=true; if (args[i]=="-doctool") { doc_tool=args[i+1]; } else if (args[i]=="-script" || args[i]=="-s") { script=args[i+1]; } else if (args[i]=="-level" || args[i]=="-l") { OS::get_singleton()->_custom_level=args[i+1]; } else if (args[i]=="-test") { test=args[i+1]; } else if (args[i]=="-optimize") { optimize=args[i+1]; } else if (args[i]=="-optimize_preset") { optimize_preset=args[i+1]; } else if (args[i]=="-export") { editor=true; //needs editor _export_platform=args[i+1]; } else if (args[i]=="-export_debug") { editor=true; //needs editor _export_platform=args[i+1]; export_debug=true; } else if (args[i]=="-import") { editor=true; //needs editor _import=args[i+1]; } else if (args[i]=="-import_script") { editor=true; //needs editor _import_script=args[i+1]; } else if (args[i]=="-dumpstrings") { editor=true; //needs editor dumpstrings=args[i+1]; } else { // The parameter does not match anything known, don't skip the next argument parsed_pair=false; } if (parsed_pair) { i++; } } } if (editor) Globals::get_singleton()->set("editor_active",true); String main_loop_type; #ifdef TOOLS_ENABLED if(doc_tool!="") { DocData doc; doc.generate(doc_base); DocData docsrc; if (docsrc.load(doc_tool)==OK) { print_line("Doc exists. Merging.."); doc.merge_from(docsrc); } else { print_line("No Doc exists. Generating empty."); } doc.save(doc_tool); return false; } if (optimize!="") editor=true; //need editor #endif if (_export_platform!="") { if (game_path=="") { String err="Command line param "; err+=export_debug?"-export_debug":"-export"; err+=" passed but no destination path given.\n"; err+="Please specify the binary's file path to export to. Aborting export."; ERR_PRINT(err.utf8().get_data()); return false; } } if(script=="" && game_path=="" && String(GLOBAL_DEF("application/main_scene",""))!="") { game_path=GLOBAL_DEF("application/main_scene",""); } MainLoop *main_loop=NULL; if (editor) { main_loop = memnew(SceneTree); }; if (test!="") { #ifdef DEBUG_ENABLED main_loop = test_main(test,args); if (!main_loop) return false; #endif } else if (script!="") { Ref<Script> script_res = ResourceLoader::load(script); ERR_EXPLAIN("Can't load script: "+script); ERR_FAIL_COND_V(script_res.is_null(),false); if( script_res->can_instance() /*&& script_res->inherits_from("SceneTreeScripted")*/) { StringName instance_type=script_res->get_instance_base_type(); Object *obj = ObjectTypeDB::instance(instance_type); MainLoop *script_loop = obj?obj->cast_to<MainLoop>():NULL; if (!script_loop) { if (obj) memdelete(obj); ERR_EXPLAIN("Can't load script '"+script+"', it does not inherit from a MainLoop type"); ERR_FAIL_COND_V(!script_loop,false); } script_loop->set_init_script(script_res); main_loop=script_loop; } else { return false; } } else { main_loop_type=GLOBAL_DEF("application/main_loop_type",""); } if (!main_loop && main_loop_type=="") main_loop_type="SceneTree"; if (!main_loop) { if (!ObjectTypeDB::type_exists(main_loop_type)) { OS::get_singleton()->alert("godot: error: MainLoop type doesn't exist: "+main_loop_type); return false; } else { Object *ml = ObjectTypeDB::instance(main_loop_type); if (!ml) { ERR_EXPLAIN("Can't instance MainLoop type"); ERR_FAIL_V(false); } main_loop=ml->cast_to<MainLoop>(); if (!main_loop) { memdelete(ml); ERR_EXPLAIN("Invalid MainLoop type"); ERR_FAIL_V(false); } } } if (main_loop->is_type("SceneTree")) { SceneTree *sml = main_loop->cast_to<SceneTree>(); if (debug_collisions) { sml->set_debug_collisions_hint(true); } if (debug_navigation) { sml->set_debug_navigation_hint(true); } #ifdef TOOLS_ENABLED EditorNode *editor_node=NULL; if (editor) { editor_node = memnew( EditorNode ); sml->get_root()->add_child(editor_node); //root_node->set_editor(editor); //startup editor if (_export_platform!="") { editor_node->export_platform(_export_platform,game_path,export_debug,"",true); game_path=""; //no load anything } } #endif if (!editor) { //standard helpers that can be changed from main config String stretch_mode = GLOBAL_DEF("display/stretch_mode","disabled"); String stretch_aspect = GLOBAL_DEF("display/stretch_aspect","ignore"); Size2i stretch_size = Size2(GLOBAL_DEF("display/width",0),GLOBAL_DEF("display/height",0)); SceneTree::StretchMode sml_sm=SceneTree::STRETCH_MODE_DISABLED; if (stretch_mode=="2d") sml_sm=SceneTree::STRETCH_MODE_2D; else if (stretch_mode=="viewport") sml_sm=SceneTree::STRETCH_MODE_VIEWPORT; SceneTree::StretchAspect sml_aspect=SceneTree::STRETCH_ASPECT_IGNORE; if (stretch_aspect=="keep") sml_aspect=SceneTree::STRETCH_ASPECT_KEEP; else if (stretch_aspect=="keep_width") sml_aspect=SceneTree::STRETCH_ASPECT_KEEP_WIDTH; else if (stretch_aspect=="keep_height") sml_aspect=SceneTree::STRETCH_ASPECT_KEEP_HEIGHT; sml->set_screen_stretch(sml_sm,sml_aspect,stretch_size); sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true)); String appname = Globals::get_singleton()->get("application/name"); appname = TranslationServer::get_singleton()->translate(appname); OS::get_singleton()->set_window_title(appname); } else { GLOBAL_DEF("display/stretch_mode","disabled"); Globals::get_singleton()->set_custom_property_info("display/stretch_mode",PropertyInfo(Variant::STRING,"display/stretch_mode",PROPERTY_HINT_ENUM,"disabled,2d,viewport")); GLOBAL_DEF("display/stretch_aspect","ignore"); Globals::get_singleton()->set_custom_property_info("display/stretch_aspect",PropertyInfo(Variant::STRING,"display/stretch_aspect",PROPERTY_HINT_ENUM,"ignore,keep,keep_width,keep_height")); sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true)); } if (game_path!="" && !project_manager_request) { String local_game_path=game_path.replace("\\","/"); if (!local_game_path.begins_with("res://")) { bool absolute=(local_game_path.size()>1) && (local_game_path[0]=='/' || local_game_path[1]==':'); if (!absolute) { if (Globals::get_singleton()->is_using_datapack()) { local_game_path="res://"+local_game_path; } else { int sep=local_game_path.find_last("/"); if (sep==-1) { DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); local_game_path=da->get_current_dir()+"/"+local_game_path; memdelete(da) ; } else { DirAccess *da = DirAccess::open(local_game_path.substr(0,sep)); if (da) { local_game_path=da->get_current_dir()+"/"+local_game_path.substr(sep+1,local_game_path.length());; memdelete(da); } } } } } local_game_path=Globals::get_singleton()->localize_path(local_game_path); #ifdef TOOLS_ENABLED if (editor) { if (_import!="") { //editor_node->import_scene(_import,local_game_path,_import_script); if (!noquit) sml->quit(); game_path=""; //no load anything } else { Error serr = editor_node->load_scene(local_game_path); if (serr==OK) { if (optimize!="") { editor_node->save_optimized_copy(optimize,optimize_preset); if (!noquit) sml->quit(); } if (dumpstrings!="") { editor_node->save_translatable_strings(dumpstrings); if (!noquit) sml->quit(); } } } OS::get_singleton()->set_context(OS::CONTEXT_EDITOR); //editor_node->set_edited_scene(game); } else { #endif { //autoload List<PropertyInfo> props; Globals::get_singleton()->get_property_list(&props); //first pass, add the constants so they exist before any script is loaded for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { String s = E->get().name; if (!s.begins_with("autoload/")) continue; String name = s.get_slicec('/',1); String path = Globals::get_singleton()->get(s); bool global_var=false; if (path.begins_with("*")) { global_var=true; } if (global_var) { for(int i=0;i<ScriptServer::get_language_count();i++) { ScriptServer::get_language(i)->add_global_constant(name,Variant()); } } } //second pass, load into global constants List<Node*> to_add; for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { String s = E->get().name; if (!s.begins_with("autoload/")) continue; String name = s.get_slicec('/',1); String path = Globals::get_singleton()->get(s); bool global_var=false; if (path.begins_with("*")) { global_var=true; path=path.substr(1,path.length()-1); } RES res = ResourceLoader::load(path); ERR_EXPLAIN("Can't autoload: "+path); ERR_CONTINUE(res.is_null()); Node *n=NULL; if (res->is_type("PackedScene")) { Ref<PackedScene> ps = res; n=ps->instance(); } else if (res->is_type("Script")) { Ref<Script> s = res; StringName ibt = s->get_instance_base_type(); bool valid_type = ObjectTypeDB::is_type(ibt,"Node"); ERR_EXPLAIN("Script does not inherit a Node: "+path); ERR_CONTINUE( !valid_type ); Object *obj = ObjectTypeDB::instance(ibt); ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: "+String(ibt)); ERR_CONTINUE( obj==NULL ); n = obj->cast_to<Node>(); n->set_script(s.get_ref_ptr()); } ERR_EXPLAIN("Path in autoload not a node or script: "+path); ERR_CONTINUE(!n); n->set_name(name); //defer so references are all valid on _ready() //sml->get_root()->add_child(n); to_add.push_back(n); if (global_var) { for(int i=0;i<ScriptServer::get_language_count();i++) { ScriptServer::get_language(i)->add_global_constant(name,n); } } } for(List<Node*>::Element *E=to_add.front();E;E=E->next()) { sml->get_root()->add_child(E->get()); } } Node *scene=NULL; Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path); if (scenedata.is_valid()) scene=scenedata->instance(); ERR_EXPLAIN("Failed loading scene: "+local_game_path); ERR_FAIL_COND_V(!scene,false) //sml->get_root()->add_child(scene); sml->add_current_scene(scene); String iconpath = GLOBAL_DEF("application/icon","Variant()"""); if (iconpath!="") { Image icon; if (icon.load(iconpath)==OK) OS::get_singleton()->set_icon(icon); } //singletons #ifdef TOOLS_ENABLED } #endif } #ifdef TOOLS_ENABLED /*if (_export_platform!="") { sml->quit(); }*/ /* if (sml->get_root_node()) { Console *console = memnew( Console ); sml->get_root_node()->cast_to<RootNode>()->set_console(console); if (GLOBAL_DEF("console/visible_default",false).operator bool()) { console->show(); } else {P console->hide(); }; } */ if (project_manager_request || (script=="" && test=="" && game_path=="" && !editor)) { ProjectManager *pmanager = memnew( ProjectManager ); sml->get_root()->add_child(pmanager); OS::get_singleton()->set_context(OS::CONTEXT_PROJECTMAN); } #endif } OS::get_singleton()->set_main_loop( main_loop ); return true; }
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"); }