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