bool AssetArchive::fixCase(String& streamName) { String dir = _dir; String patternDir; String filePattern; size_t slashPos = streamName.find_last_of('/'); if (slashPos != streamName.npos) { patternDir = streamName.substr(0, slashPos+1); dir += patternDir; filePattern = streamName.substr(slashPos+1); } else { filePattern = streamName; } // openDir() requires no trailing '/' if (!dir.empty() && dir[dir.length()-1] == '/') dir.resize(dir.length()-1); AAssetDir* assetDir = AAssetManager_openDir(_assetManager, dir.c_str()); if (assetDir == NULL) return false; bool fixed = false; while (true) { const char* filename = AAssetDir_getNextFileName(assetDir); if (filename == NULL) break; // filename returned as all directory part extracted and only the last component if (_strcmpi(filename, filePattern.c_str()) == 0) { LOG(0, "?? fixed case: '%s' -> '%s'\n", makeUrl(streamName).c_str(), makeUrl(patternDir + filename).c_str()); streamName = patternDir + filename; fixed = true; break; } } AAssetDir_close(assetDir); return fixed; }
sqlite3_blob* BlobLocator::openBlob(const String& streamName, bool readonly, bool throwEx) { Database::Query* query = prepareSelect(); query->reset(); query->bind(1, streamName); sqlite3_blob* blob = NULL; if (query->step()) { const char* db = query->getDatabaseName(0); const char* tbl = query->getTableName(0); const char* column = _blobColumnName.c_str(); int64 rowid = query->getInt64(0); blob = openBlob(db, tbl, column, rowid, readonly, throwEx); } query->reset(); if (blob) return blob; if (throwEx) { NIT_THROW_FMT(EX_NOT_FOUND, "can't find blob '%s'", makeUrl(streamName).c_str()); } return NULL; }
UrlT auth2(const StringT& applicationName, const StringT& formtoken, ParamsT& outPostParams) { paramsAdd(outPostParams, "name", applicationName); paramsAdd(outPostParams, "website", ""); paramsAdd(outPostParams, "formtoken", formtoken); paramsAdd(outPostParams, "json", ""); return makeUrl("/auth_2/"); }
UrlT auth1(const StringT& applicationName) { ParamsT params; paramsAdd(params, "name", applicationName); paramsAdd(params, "website", ""); paramsAdd(params, "json", ""); return makeUrl("/auth_1/", params); }
// qid optional // rql optional UrlT boffinTagcloud(const StringT& cometSession, const StringT& qid = StringT(), const StringT& rql = StringT()) { ParamsT params; paramsAdd(params, "auth", m_token); paramsAdd(params, "comet", cometSession); if (qid != "") { paramsAdd(params, "qid", qid); } return makeUrl("/boffin/tagcloud/" + rql, params); }
// qid optional UrlT boffinRql(const StringT& cometSession, const StringT& qid, const StringT& rql) { ParamsT params; paramsAdd(params, "auth", m_token); paramsAdd(params, "comet", cometSession); if (qid != "") { paramsAdd(params, "qid", qid); } return makeUrl("/boffin/rql/" + rql, params); }
std::pair<http::Status, std::string> HttpClient::del(const std::string& path, const std::string& query) { std::pair<http::Status, std::string> r; r.second.reserve(Buffer_Size); setopt(CURLOPT_HEADERFUNCTION, &headerStatusCallback); setopt(CURLOPT_URL, makeUrl(path, query).c_str()); setopt(CURLOPT_WRITEDATA, &r.second); setopt(CURLOPT_HEADERDATA, &r.first); setopt(CURLOPT_HTTPGET, 1l); setopt(CURLOPT_CUSTOMREQUEST, "DELETE"); perform(); return r; }
// powerful because it handles both cases when there is material and when there's not void GeometryExporter::createPolylist(short material_index, bool has_uvs, bool has_color, Object *ob, std::string& geom_id, std::vector<Face>& norind) { Mesh *me = (Mesh*)ob->data; MFace *mfaces = me->mface; int totfaces = me->totface; // <vcount> int i; int faces_in_polylist = 0; std::vector<unsigned long> vcount_list; // count faces with this material for (i = 0; i < totfaces; i++) { MFace *f = &mfaces[i]; if (f->mat_nr == material_index) { faces_in_polylist++; if (f->v4 == 0) { vcount_list.push_back(3); } else { vcount_list.push_back(4); } } } // no faces using this material if (faces_in_polylist == 0) { fprintf(stderr, "%s: no faces use material %d\n", id_name(ob).c_str(), material_index); return; } Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL; COLLADASW::Polylist polylist(mSW); // sets count attribute in <polylist> polylist.setCount(faces_in_polylist); // sets material name if (ma) { std::ostringstream ostr; ostr << translate_id(id_name(ma)) << material_index+1; polylist.setMaterial(ostr.str()); } COLLADASW::InputList &til = polylist.getInputList(); // creates <input> in <polylist> for vertices COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); // creates <input> in <polylist> for normals COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1); til.push_back(input1); til.push_back(input2); // if mesh has uv coords writes <input> for TEXCOORD int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); for (i = 0; i < num_layers; i++) { // char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i); COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD, makeUrl(makeTexcoordSourceId(geom_id, i)), 2, // offset always 2, this is only until we have optimized UV sets i // set number equals UV map index ); til.push_back(input3); } if (has_color) { COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::COLOR), has_uvs ? 3 : 2); til.push_back(input4); } // sets <vcount> polylist.setVCountList(vcount_list); // performs the actual writing polylist.prepareToAppendValues(); // <p> int texindex = 0; for (i = 0; i < totfaces; i++) { MFace *f = &mfaces[i]; if (f->mat_nr == material_index) { unsigned int *v = &f->v1; unsigned int *n = &norind[i].v1; for (int j = 0; j < (f->v4 == 0 ? 3 : 4); j++) { polylist.appendValues(v[j]); polylist.appendValues(n[j]); if (has_uvs) polylist.appendValues(texindex + j); if (has_color) polylist.appendValues(texindex + j); } } texindex += 3; if (f->v4 != 0) texindex++; } polylist.finish(); }
/*! * Поиск ссылок в тексте и автоматическое преобразование их в html ссылки. */ void LinksFilter::parse(QList<HtmlToken> &tokens, const QString &text) const { int index = -1; int last = -1; QString url; /// - http/https/ftp полный список в \p m_scheme. for (int i = 0; i < m_scheme.size(); ++i) { index = text.indexOf(m_scheme.at(i)); if (index != -1) { if (index > 0) tokens.append(HtmlToken(text.left(index))); url = this->url(text, index, last); makeUrl(tokens, url, url); if (last != -1) return parse(tokens, text.mid(last)); return; } } /// - Ссылки вида www.exampe.com в преобразуются в http. index = text.indexOf(LS("www.")); if (index != -1) { url = this->url(text, index, last); if (url.count(LC('.')) > 1) { if (index > 0) tokens.append(HtmlToken(text.left(index))); makeUrl(tokens, LS("http://") + url, url); if (last != -1) return parse(tokens, text.mid(last)); return; } if (last != -1) { tokens.append(HtmlToken(text.left(last))); return parse(tokens, text.mid(last)); } } /// - Ссылки вида [email protected] преобразуются в mailto. index = text.indexOf(LC('@')); if (index != -1) { int start = text.lastIndexOf(LC(' '), index); QString name = text.mid(start + 1, index - start - 1); last = -1; if (!name.isEmpty()) { url = this->url(text, index, last); if (url.contains(LC('.'))) { if (index > 0) { tokens.append(HtmlToken(text.left(index - name.size()))); makeUrl(tokens, LS("mailto:") + name + url, name + url); if (last != -1) return parse(tokens, text.mid(last)); return; } } } if (last != -1) { tokens.append(HtmlToken(text.left(last))); return parse(tokens, text.mid(last)); } } tokens.append(HtmlToken(text)); }
UrlT lanRoster() { return makeUrl("/lan/roster"); }
UrlT apiCall(const ParamsT& params) { return makeUrl("/api/", params); }
UrlT comet(const StringT& session) { ParamsT params; paramsAdd(params, "session", session); return makeUrl("/comet/", params); }
// powerful because it handles both cases when there is material and when there's not void GeometryExporter::createPolylist(short material_index, bool has_uvs, bool has_color, Object *ob, Mesh *me, std::string& geom_id, std::vector<BCPolygonNormalsIndices>& norind) { MPoly *mpolys = me->mpoly; MLoop *mloops = me->mloop; int totpolys = me->totpoly; // <vcount> int i; int faces_in_polylist = 0; std::vector<unsigned long> vcount_list; // count faces with this material for (i = 0; i < totpolys; i++) { MPoly *p = &mpolys[i]; if (p->mat_nr == material_index) { faces_in_polylist++; vcount_list.push_back(p->totloop); } } // no faces using this material if (faces_in_polylist == 0) { fprintf(stderr, "%s: material with index %d is not used.\n", id_name(ob).c_str(), material_index); return; } Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL; COLLADASW::Polylist polylist(mSW); // sets count attribute in <polylist> polylist.setCount(faces_in_polylist); // sets material name if (ma) { std::string material_id = get_material_id(ma); std::ostringstream ostr; ostr << translate_id(material_id); polylist.setMaterial(ostr.str()); } COLLADASW::InputList &til = polylist.getInputList(); // creates <input> in <polylist> for vertices COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); // creates <input> in <polylist> for normals COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1); til.push_back(input1); til.push_back(input2); // if mesh has uv coords writes <input> for TEXCOORD int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE)-1; for (i = 0; i < num_layers; i++) { if (!this->export_settings->active_uv_only || i == active_uv_index) { // char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i); COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD, makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings->active_uv_only)), 2, // this is only until we have optimized UV sets (this->export_settings->active_uv_only) ? 0 : i // only_active_uv exported -> we have only one set ); til.push_back(input3); } } int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); if (totlayer_mcol > 0) { int map_index = 0; for (int a = 0; a < totlayer_mcol; a++) { char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPCOL, a); COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR, makeUrl(makeVertexColorSourceId(geom_id, layer_name)), (has_uvs) ? 3 : 2, // all color layers have same index order map_index // set number equals color map index ); til.push_back(input4); map_index++; } } // sets <vcount> polylist.setVCountList(vcount_list); // performs the actual writing polylist.prepareToAppendValues(); // <p> int texindex = 0; for (i = 0; i < totpolys; i++) { MPoly *p = &mpolys[i]; int loop_count = p->totloop; if (p->mat_nr == material_index) { MLoop *l = &mloops[p->loopstart]; BCPolygonNormalsIndices normal_indices = norind[i]; for (int j = 0; j < loop_count; j++) { polylist.appendValues(l[j].v); polylist.appendValues(normal_indices[j]); if (has_uvs) polylist.appendValues(texindex + j); if (has_color) polylist.appendValues(texindex + j); } } texindex += loop_count; } polylist.finish(); }