Example #1
0
float EditorQuickOpen::_path_cmp(String search, String path) const {

	if (search == path) {
		return 1.2f;
	}
	if (path.findn(search) != -1) {
		return 1.1f;
	}
	return path.to_lower().similarity(search.to_lower());
}
Example #2
0
void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers) {

	for (int i = 0; i < importers.size(); i++) {
		List<String> local_exts;
		importers[i]->get_recognized_extensions(&local_exts);
		for (List<String>::Element *F = local_exts.front(); F; F = F->next()) {
			if (p_extension.to_lower() == F->get()) {
				r_importers->push_back(importers[i]);
			}
		}
	}
}
Example #3
0
String RenameDialog::_postprocess(const String &subject) {

	int style_id = opt_style->get_selected();

	String result = subject;

	if (style_id == 1) {

		// CamelCase to Under_Line
		result = result.camelcase_to_underscore(true);
		result = _regex("_+", result, "_");

	} else if (style_id == 2) {

		// Under_Line to CamelCase
		RegEx pattern("_+(.?)");
		Array matches = pattern.search_all(result);

		// _ name would become empty. Ignore
		if (matches.size() && result != "_") {
			String buffer;
			int start = 0;
			int end = 0;
			for (int i = 0; i < matches.size(); ++i) {
				start = ((Ref<RegExMatch>)matches[i])->get_start(1);
				buffer += result.substr(end, start - end - 1);
				buffer += result.substr(start, 1).to_upper();
				end = start + 1;
			}
			buffer += result.substr(end, result.size() - (end + 1));
			result = buffer.replace("_", "").capitalize();
		}
	}

	int case_id = opt_case->get_selected();

	if (case_id == 1) {
		// To Lowercase
		result = result.to_lower();
	} else if (case_id == 2) {
		// To Upercase
		result = result.to_upper();
	}

	return result;
}
Example #4
0
Color Color::named(const String &p_name) {
	if (_named_colors.empty()) _populate_named_colors(); // from color_names.inc
	String name = p_name;
	// Normalize name
	name = name.replace(" ", "");
	name = name.replace("-", "");
	name = name.replace("_", "");
	name = name.replace("'", "");
	name = name.replace(".", "");
	name = name.to_lower();

	const Map<String, Color>::Element *color = _named_colors.find(name);
	if (color) {
		return color->value();
	} else {
		ERR_EXPLAIN("Invalid Color Name: " + p_name);
		ERR_FAIL_V(Color());
	}
}
Example #5
0
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const {

	Ref<ResourceImporter> importer;
	float priority = 0;

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

		List<String> local_exts;
		importers[i]->get_recognized_extensions(&local_exts);
		for (List<String>::Element *F = local_exts.front(); F; F = F->next()) {
			if (p_extension.to_lower() == F->get() && importers[i]->get_priority() > priority) {
				importer = importers[i];
				priority = importers[i]->get_priority();
			}
		}
	}

	return importer;
}
Error EditorSceneImporterFBXConv::_parse_fbx(State& state,const String& p_path) {

	state.base_path=p_path.get_base_dir();

	if (p_path.to_lower().ends_with("g3dj")) {
		return _parse_json(state,p_path.basename()+".g3dj");
	}

	String tool = EDITOR_DEF("fbxconv/path","");
	ERR_FAIL_COND_V( !FileAccess::exists(tool),ERR_UNCONFIGURED);
	String wine = EDITOR_DEF("fbxconv/use_wine","");

	List<String> args;
	String path=p_path;
	if (wine!="") {
		List<String> wpargs;
		wpargs.push_back("-w");
		wpargs.push_back(p_path);
		String pipe; //winepath to convert to windows path
		int wpres;
		Error wperr = OS::get_singleton()->execute(wine+"path",wpargs,true,NULL,&pipe,&wpres);
		ERR_FAIL_COND_V(wperr!=OK,ERR_CANT_CREATE);
		ERR_FAIL_COND_V(wpres!=0,ERR_CANT_CREATE);
		path=pipe.strip_edges();
		args.push_back(tool);
		tool=wine;
	}

	args.push_back("-o");
	args.push_back("G3DJ");
	args.push_back(path);

	int res;
	Error err = OS::get_singleton()->execute(tool,args,true,NULL,NULL,&res);
	ERR_FAIL_COND_V(err!=OK,ERR_CANT_CREATE);
	ERR_FAIL_COND_V(res!=0,ERR_CANT_CREATE);

	return _parse_json(state,p_path.basename()+".g3dj");


}
Example #7
0
void
dmz::ArchivePluginObject::_init (Config &local) {

   RuntimeContext *context (get_plugin_runtime_context ());

   init_archive_scope (local);

   if (is_archive_scope_empty ()) { add_archive_scope ("archive"); }

   _defaultHandle = _defs.create_named_handle (ObjectAttributeDefaultName);

   Config filterList;

   if (local.lookup_all_config ("archive", filterList)) {

      ConfigIterator it;
      Config filter;

      // Read list in reverse order so they are stored in the correct order in the 
      // filter list.
      while (filterList.get_prev_config (it, filter)) {

         const String ArchiveName (config_to_string ("name", filter, ArchiveDefaultName));

         const Handle ArchiveHandle (activate_archive (ArchiveName));

         _log.info << "Activating archive: " << ArchiveName << endl;

         FilterStruct *fs (filter.has_children () ? new FilterStruct : 0);

         if (fs) {

            const String ModeStr = config_to_string ("mode", filter, "export|import");

            if (ModeStr) {

               StringTokenizer st (ModeStr, '|');
               String value;

               while (st.get_next (value)) {

                  trim_ascii_white_space (value);
                  value.to_lower ();

                  if (value == "import") { fs->mode |= LocalImportMask; }
                  else if (value == "export") { fs->mode |= LocalExportMask; }
                  else { _log.error << "Unknown archive mode: " << value << endl; }
               }
            }

            Config objects;

            if (filter.lookup_all_config ("object-type-set.object-type", objects)) {

               ConfigIterator typesIt;
               Config typeConfig;

               while (objects.get_next_config (typesIt, typeConfig)) {

                  const String Name (config_to_string ("name", typeConfig));
                  const Boolean Exclude (config_to_boolean ("exclude", typeConfig, True));

                  if (Exclude) {

                     if (!fs->exTypes.add_object_type (Name, context)) {

                        _log.error << "Unable to add object type: '" << Name
                           << "' to archive filter for archive: "
                           << _defs.lookup_named_handle_name (ArchiveHandle) << endl;
                     }
                     else {

                        _log.info << "Excluding object type: " << Name << endl;
                     }
                  }
                  else if (!fs->inTypes.add_object_type (Name, context)) {

                     _log.error << "Unable to add object type: '" << Name
                        << "' to archive filter for archive: "
                        << _defs.lookup_named_handle_name (ArchiveHandle) << endl;
                  }
                  else {

                     _log.info << "Including object type: " << Name << endl;
                  }
               }
            }
            else { _log.info << "No object types filtered for: " << ArchiveName << endl; }

            Config attrConfig;

            if (filter.lookup_all_config ("attribute", attrConfig)) {

               ConfigIterator attrIt;
               Config currentAttr;

               while (attrConfig.get_next_config (attrIt, currentAttr)) {

                  const String Name (
                     config_to_string ("name", currentAttr, ObjectAttributeDefaultName));

                  const Boolean Contains (
                     config_to_boolean ("contains", currentAttr, False));

                  const Mask AttrMask (local_config_to_mask (currentAttr, _log));

                  if (Contains) {

                     FilterAttrStruct *fas (new FilterAttrStruct (Name, AttrMask));

                     if (fas) { fas->next = fs->list; fs->list = fas; }
                  }
                  else {

                     const Handle AttrHandle (_defs.create_named_handle (Name));

                     Mask *ptr (new Mask (AttrMask));

                     if (ptr && !fs->attrTable.store (AttrHandle, ptr)) {

                        delete ptr; ptr = 0;
                        _log.error << "Unable to store mask for object attribute: "
                           << Name << ". Possible duplicate?" << endl;
                     }
                  }
               }
            }

            Config stateConfig;

            if (filter.lookup_all_config ("state", stateConfig)) {

               ConfigIterator stateIt;
               Config state;

               while (stateConfig.get_next_config (stateIt, state)) {

                  Handle attrHandle (_defaultHandle);

                  const String AttrName (config_to_string ("attribute", state));

                  if (AttrName) { attrHandle = _defs.create_named_handle (AttrName); }

                  Mask stateMask;
                  _defs.lookup_state (config_to_string ("name", state), stateMask);

                  if (stateMask) {

                     Mask *ptr (fs->stateTable.lookup (attrHandle));

                     if (ptr) { (*ptr) |= stateMask; }
                     else {

                        ptr = new Mask (stateMask);

                        if (ptr && !fs->stateTable.store (attrHandle, ptr)) {

                           delete ptr; ptr = 0;
                        }
                     }
                  }
               }
            }

            FilterListStruct *fls = _filterTable.lookup (ArchiveHandle);

            if (!fls) {

               fls = new FilterListStruct (ArchiveHandle);

               if (!_filterTable.store (ArchiveHandle, fls)) { delete fls; fls = 0; }
            }

            if (fls) { fs->next = fls->list; fls->list = fs; }
         }
      }
   }
   else {

      _log.info << "Activating default archive" << endl;
      activate_default_archive ();
   }
}
Example #8
0
Error HTTPClient::poll() {

	switch (status) {

		case STATUS_RESOLVING: {
			ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG);

			IP::ResolverStatus rstatus = IP::get_singleton()->get_resolve_item_status(resolving);
			switch (rstatus) {
				case IP::RESOLVER_STATUS_WAITING:
					return OK; // Still resolving

				case IP::RESOLVER_STATUS_DONE: {

					IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving);
					Error err = tcp_connection->connect_to_host(host, conn_port);
					IP::get_singleton()->erase_resolve_item(resolving);
					resolving = IP::RESOLVER_INVALID_ID;
					if (err) {
						status = STATUS_CANT_CONNECT;
						return err;
					}

					status = STATUS_CONNECTING;
				} break;
				case IP::RESOLVER_STATUS_NONE:
				case IP::RESOLVER_STATUS_ERROR: {

					IP::get_singleton()->erase_resolve_item(resolving);
					resolving = IP::RESOLVER_INVALID_ID;
					close();
					status = STATUS_CANT_RESOLVE;
					return ERR_CANT_RESOLVE;
				} break;
			}
		} break;
		case STATUS_CONNECTING: {

			StreamPeerTCP::Status s = tcp_connection->get_status();
			switch (s) {

				case StreamPeerTCP::STATUS_CONNECTING: {
					return OK;
				} break;
				case StreamPeerTCP::STATUS_CONNECTED: {
					if (ssl) {
						Ref<StreamPeerSSL> ssl;
						if (!handshaking) {
							// Connect the StreamPeerSSL and start handshaking
							ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create());
							ssl->set_blocking_handshake_enabled(false);
							Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, conn_host);
							if (err != OK) {
								close();
								status = STATUS_SSL_HANDSHAKE_ERROR;
								return ERR_CANT_CONNECT;
							}
							connection = ssl;
							handshaking = true;
						} else {
							// We are already handshaking, which means we can use your already active SSL connection
							ssl = static_cast<Ref<StreamPeerSSL> >(connection);
							ssl->poll(); // Try to finish the handshake
						}

						if (ssl->get_status() == StreamPeerSSL::STATUS_CONNECTED) {
							// Handshake has been successful
							handshaking = false;
							status = STATUS_CONNECTED;
							return OK;
						} else if (ssl->get_status() != StreamPeerSSL::STATUS_HANDSHAKING) {
							// Handshake has failed
							close();
							status = STATUS_SSL_HANDSHAKE_ERROR;
							return ERR_CANT_CONNECT;
						}
						// ... we will need to poll more for handshake to finish
					} else {
						status = STATUS_CONNECTED;
					}
					return OK;
				} break;
				case StreamPeerTCP::STATUS_ERROR:
				case StreamPeerTCP::STATUS_NONE: {

					close();
					status = STATUS_CANT_CONNECT;
					return ERR_CANT_CONNECT;
				} break;
			}
		} break;
		case STATUS_BODY:
		case STATUS_CONNECTED: {
			// Check if we are still connected
			if (ssl) {
				Ref<StreamPeerSSL> tmp = connection;
				tmp->poll();
				if (tmp->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
					status = STATUS_CONNECTION_ERROR;
					return ERR_CONNECTION_ERROR;
				}
			} else if (tcp_connection->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
				status = STATUS_CONNECTION_ERROR;
				return ERR_CONNECTION_ERROR;
			}
			// Connection established, requests can now be made
			return OK;
		} break;
		case STATUS_REQUESTING: {

			while (true) {
				uint8_t byte;
				int rec = 0;
				Error err = _get_http_data(&byte, 1, rec);
				if (err != OK) {
					close();
					status = STATUS_CONNECTION_ERROR;
					return ERR_CONNECTION_ERROR;
				}

				if (rec == 0)
					return OK; // Still requesting, keep trying!

				response_str.push_back(byte);
				int rs = response_str.size();
				if (
						(rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') ||
						(rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) {

					// End of response, parse.
					response_str.push_back(0);
					String response;
					response.parse_utf8((const char *)response_str.ptr());
					Vector<String> responses = response.split("\n");
					body_size = -1;
					chunked = false;
					body_left = 0;
					chunk_left = 0;
					read_until_eof = false;
					response_str.clear();
					response_headers.clear();
					response_num = RESPONSE_OK;

					// Per the HTTP 1.1 spec, keep-alive is the default, but in practice
					// it's safe to assume it only if the explicit header is found, allowing
					// to handle body-up-to-EOF responses on naive servers; that's what Curl
					// and browsers do
					bool keep_alive = false;

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

						String header = responses[i].strip_edges();
						String s = header.to_lower();
						if (s.length() == 0)
							continue;
						if (s.begins_with("content-length:")) {
							body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int();
							body_left = body_size;

						} else if (s.begins_with("transfer-encoding:")) {
							String encoding = header.substr(header.find(":") + 1, header.length()).strip_edges();
							if (encoding == "chunked") {
								chunked = true;
							}
						} else if (s.begins_with("connection: keep-alive")) {
							keep_alive = true;
						}

						if (i == 0 && responses[i].begins_with("HTTP")) {

							String num = responses[i].get_slicec(' ', 1);
							response_num = num.to_int();
						} else {

							response_headers.push_back(header);
						}
					}

					if (body_size != -1 || chunked) {

						status = STATUS_BODY;
					} else if (!keep_alive) {

						read_until_eof = true;
						status = STATUS_BODY;
					} else {

						status = STATUS_CONNECTED;
					}
					return OK;
				}
			}
			// Wait for response
			return OK;
		} break;
		case STATUS_DISCONNECTED: {
			return ERR_UNCONFIGURED;
		} break;
		case STATUS_CONNECTION_ERROR:
		case STATUS_SSL_HANDSHAKE_ERROR: {
			return ERR_CONNECTION_ERROR;
		} break;
		case STATUS_CANT_CONNECT: {
			return ERR_CANT_CONNECT;
		} break;
		case STATUS_CANT_RESOLVE: {
			return ERR_CANT_RESOLVE;
		} break;
	}

	return OK;
}
Example #9
0
Error HTTPClient::poll() {

	switch (status) {

		case STATUS_RESOLVING: {
			ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG);

			IP::ResolverStatus rstatus = IP::get_singleton()->get_resolve_item_status(resolving);
			switch (rstatus) {
				case IP::RESOLVER_STATUS_WAITING:
					return OK; //still resolving

				case IP::RESOLVER_STATUS_DONE: {

					IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving);
					Error err = tcp_connection->connect_to_host(host, conn_port);
					IP::get_singleton()->erase_resolve_item(resolving);
					resolving = IP::RESOLVER_INVALID_ID;
					if (err) {
						status = STATUS_CANT_CONNECT;
						return err;
					}

					status = STATUS_CONNECTING;
				} break;
				case IP::RESOLVER_STATUS_NONE:
				case IP::RESOLVER_STATUS_ERROR: {

					IP::get_singleton()->erase_resolve_item(resolving);
					resolving = IP::RESOLVER_INVALID_ID;
					close();
					status = STATUS_CANT_RESOLVE;
					return ERR_CANT_RESOLVE;
				} break;
			}
		} break;
		case STATUS_CONNECTING: {

			StreamPeerTCP::Status s = tcp_connection->get_status();
			switch (s) {

				case StreamPeerTCP::STATUS_CONNECTING: {
					return OK; //do none
				} break;
				case StreamPeerTCP::STATUS_CONNECTED: {
					if (ssl) {
						Ref<StreamPeerSSL> ssl = StreamPeerSSL::create();
						Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, ssl_verify_host ? conn_host : String());
						if (err != OK) {
							close();
							status = STATUS_SSL_HANDSHAKE_ERROR;
							return ERR_CANT_CONNECT;
						}
						//print_line("SSL! TURNED ON!");
						connection = ssl;
					}
					status = STATUS_CONNECTED;
					return OK;
				} break;
				case StreamPeerTCP::STATUS_ERROR:
				case StreamPeerTCP::STATUS_NONE: {

					close();
					status = STATUS_CANT_CONNECT;
					return ERR_CANT_CONNECT;
				} break;
			}
		} break;
		case STATUS_CONNECTED: {
			//request something please
			return OK;
		} break;
		case STATUS_REQUESTING: {

			while (true) {
				uint8_t byte;
				int rec = 0;
				Error err = _get_http_data(&byte, 1, rec);
				if (err != OK) {
					close();
					status = STATUS_CONNECTION_ERROR;
					return ERR_CONNECTION_ERROR;
				}

				if (rec == 0)
					return OK; //keep trying!

				response_str.push_back(byte);
				int rs = response_str.size();
				if (
						(rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') ||
						(rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) {

					//end of response, parse.
					response_str.push_back(0);
					String response;
					response.parse_utf8((const char *)response_str.ptr());
					//print_line("END OF RESPONSE? :\n"+response+"\n------");
					Vector<String> responses = response.split("\n");
					body_size = 0;
					chunked = false;
					body_left = 0;
					chunk_left = 0;
					response_str.clear();
					response_headers.clear();
					response_num = RESPONSE_OK;

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

						String header = responses[i].strip_edges();
						String s = header.to_lower();
						if (s.length() == 0)
							continue;
						if (s.begins_with("content-length:")) {
							body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int();
							body_left = body_size;
						}

						if (s.begins_with("transfer-encoding:")) {
							String encoding = header.substr(header.find(":") + 1, header.length()).strip_edges();
							//print_line("TRANSFER ENCODING: "+encoding);
							if (encoding == "chunked") {
								chunked = true;
							}
						}

						if (i == 0 && responses[i].begins_with("HTTP")) {

							String num = responses[i].get_slicec(' ', 1);
							response_num = num.to_int();
						} else {

							response_headers.push_back(header);
						}
					}

					if (body_size == 0 && !chunked) {

						status = STATUS_CONNECTED; //ask for something again?
					} else {
						status = STATUS_BODY;
					}
					return OK;
				}
			}
			//wait for response
			return OK;
		} break;
		case STATUS_DISCONNECTED: {
			return ERR_UNCONFIGURED;
		} break;
		case STATUS_CONNECTION_ERROR: {
			return ERR_CONNECTION_ERROR;
		} break;
		case STATUS_CANT_CONNECT: {
			return ERR_CANT_CONNECT;
		} break;
		case STATUS_CANT_RESOLVE: {
			return ERR_CANT_RESOLVE;
		} break;
	}

	return OK;
}