bool QOrmAttributeInfo::writeForeingKey(QOrmObject *obj, QOrmObject *fko) { if (!isForeignKey()) return false; //if (!fko) return false; if (obj->signalsBlocked()) { QOrmObject *old = obj->d->oldFks.at(d->fkindex); obj->d->oldFks.replace(d->fkindex, fko); if (old) { old->deref(); old->disconnect(obj); } if (fko) { fko->ref(); writeIndex(obj, refAttribute().readIndex(fko)); connect(fko, &QObject::destroyed, obj, &QOrmObject::fkDestroyed); } else writeIndex(obj, QVariant()); } d->metaProperty.write(obj, QVariant::fromValue<QOrmObject*>(fko)); return true; }
void flush() { assert ( rc != re ); if ( currun.rlen ) { *(rc++) = currun; currun.rlen = 0; currun.sym = std::numeric_limits<int64_t>::min(); } implicitFlush(); // std::cerr << "Index size " << index.size()*2*sizeof(uint64_t) << " for " << this << std::endl;; if ( ! indexwritten ) { writer.flushBitStream(); uint64_t const indexpos = writer.getPos(); writeIndex(writer,index,indexpos); indexwritten = true; } writer.flush(); }
void Indexer::buildIndex() { if (path == "") return; // Path must be set clearIndex(); // Index all files in path QDir dir(path); QFileInfoList list = dir.entryInfoList(); emit startedIndexing(list.size()); for (int i = 0; i < list.size(); i++) { QFileInfo fileInfo = list.at(i); if (!fileInfo.isFile()) continue; if (fileInfo.suffix().toLower() != "jpg") continue; //qDebug() << "Indexing "<<fileInfo.fileName(); emit indexingFile(fileInfo.fileName()); FeatureVector fv; fv=getFV(fileInfo.filePath()); putInIndex(fileInfo.fileName(), fv); } // Initialize whatever datastructures need to be initialized after putting in index indexPostInit(); // Serialize index to an index file writeIndex(); pathIndexed = true; emit finishedIndexing(); }
void flush() { assert ( pc != pe ); if ( curcnt ) { *(pc++) = rl_pair(cursym,curcnt); curcnt = 0; } implicitFlush(); // std::cerr << "Index size " << index.size()*2*sizeof(uint64_t) << " for " << this << std::endl;; if ( ! indexwritten ) { writer.flushBitStream(); uint64_t const indexpos = writer.getPos(); writeIndex(writer,index,indexpos,numsyms); indexwritten = true; } writer.flush(); }
void write_htmlHomePage::writePage(void) { htmlpage.open (HTMLfilesRegister::homePage); pageTitle = "Home Page"; writeHead(); writeIndex(); htmlpage << "In these pages we show the results of the analisys of " << "the NAST (New Abstract Syntax Tree) built by the " << "application XOgastan from the xml file " << xmlFile << ".<br><br>\n"; htmlpage << "<ol>"; htmlpage << "\t<li>" << "<a href=\"" << HTMLfilesRegister::fnctIndex << "\">Index of the functions</a><br><br>\n\n"; htmlpage << "\t<ol>"; htmlpage << "\t\t<li>" << "<a href=\"" << HTMLfilesRegister::fnctWithBodyIndex << "\">Functions with body</a><br><br>\n\n"; htmlpage << "\t\t<li>" << "<a href=\"" << HTMLfilesRegister::fnctWithParmIndex << "\">Functions with parameters</a><br><br>\n\n"; htmlpage << "\t\t<li>" << "<a href=\"" << HTMLfilesRegister::fnctIsStdCIndex << "\">List of functions of the C standard library</a><br><br>\n\n"; htmlpage << "\t</ol>\n\n"; htmlpage << "\t<li>" << "<a href=\"" << HTMLfilesRegister::nastStatistics << "\">Statistics information of the NAST</a><br><br>\n\n"; htmlpage << "</ol>\n\n"; writeIndex(); writeFoot(); htmlpage.close(); return; }
static void concatenate(std::vector<std::string> const & infilenames, std::string const & outfilename, bool const removeinput = false) { uint64_t const n = ::libmaus2::gamma::GammaRLDecoder::getLength(infilenames); unsigned int const albits = infilenames.size() ? ::libmaus2::gamma::GammaRLDecoder::getAlBits(infilenames[0]) : 0; ::libmaus2::aio::OutputStreamInstance COS(outfilename); ::libmaus2::aio::SynchronousGenericOutput<uint64_t> SGO(COS,64); SGO.put(n); SGO.put(albits); SGO.flush(); uint64_t const headerlen = 2*sizeof(uint64_t); std::vector < ::libmaus2::huffman::IndexEntry > index; uint64_t ioff = headerlen; for ( uint64_t i = 0; i < infilenames.size(); ++i ) { uint64_t const indexpos = ::libmaus2::huffman::IndexLoaderBase::getIndexPos(infilenames[i]); uint64_t const datalen = indexpos-headerlen; // copy data ::libmaus2::aio::InputStreamInstance CIS(infilenames[i]); CIS.seekg(headerlen); ::libmaus2::util::GetFileSize::copy(CIS,COS,datalen); // add entries to index ::libmaus2::huffman::IndexLoaderSequential indexdata(infilenames[i]); ::libmaus2::huffman::IndexEntry ij = indexdata.getNext(); // ::libmaus2::huffman::IndexDecoderData indexdata(infilenames[i]); for ( uint64_t j = 0; j < indexdata.numentries; ++j ) { ::libmaus2::huffman::IndexEntry ij1 = indexdata.getNext(); /* ::libmaus2::huffman::IndexEntry const ij = indexdata.readEntry(j); ::libmaus2::huffman::IndexEntry const ij1 = indexdata.readEntry(j+1); */ index.push_back(::libmaus2::huffman::IndexEntry((ij.pos - headerlen) + ioff, ij1.kcnt - ij.kcnt, ij1.vcnt - ij.vcnt)); ij = ij1; } // update position pointer ioff += datalen; if ( removeinput ) libmaus2::aio::FileRemoval::removeFile(infilenames[i]); } // write index ::libmaus2::aio::SynchronousGenericOutput<uint8_t> SGO8(COS,64*1024); ::libmaus2::aio::SynchronousGenericOutput<uint8_t>::iterator_type it(SGO8); ::libmaus2::bitio::FastWriteBitWriterStream8Std FWBWS(it); writeIndex(index,FWBWS,ioff); FWBWS.flush(); SGO8.flush(); COS.flush(); }
void WEXPORT WObjectFile::writeObject( WObject* obj, bool force ) { bool firstTime = writeIndex( obj, force ); if( firstTime && (obj != NULL) ) { puts( obj->className() ); writeEOItem(); obj->writeSelf( *this ); } }
void chromToPos(char *sizesText, char *posBin, char *posIndex) /* chromToPos - Given list of chromosomes and sizes, create files that index them by position via * a b+ tree. */ { struct chromInfo *chrom, *chromList = readChromSizes(sizesText); int chromCount = slCount(chromList); writeBinSaveOffsets(chromList, chromCount, posBin); writeIndex(chromList, chromCount, posIndex); }
void KMFolderIndex::truncateIndex() { if ( mHeaderOffset ) truncate(QFile::encodeName(indexLocation()), mHeaderOffset); else // The index file wasn't opened, so we don't know the header offset. // So let's just create a new empty index. writeIndex( true ); }
void ImageExportSerializer::writeGroup(pugi::xml_node _parent, DataPtr _data) { pugi::xml_node node = _parent.append_child("Group"); node.append_attribute("name").set_value(_data->getPropertyValue("Name").c_str()); node.append_attribute("texture").set_value(_data->getPropertyValue("Texture").c_str()); node.append_attribute("size").set_value(MyGUI::IntCoord::parse(_data->getPropertyValue("Size")).size().print().c_str()); for (Data::VectorData::const_iterator child = _data->getChilds().begin(); child != _data->getChilds().end(); child ++) writeIndex(node, (*child)); }
u32 SimpleXP3::save() { SFileHeader head; //seek to end of file and write index fseek(m_pFile, 0, SEEK_END); head.indexHeaderPos = ftell(m_pFile); u64 indexSize = 0; writeIndex(m_pFile, &indexSize, true); fseek(m_pFile, 0, SEEK_SET); head.write(m_pFile); return XP3_OK; }
void IndexPager::processKey(int key) { if(key == 'f') { TopLine += 20; if(TopLine > (int) Text.size()) TopLine = Text.size(); writeIndex(); } // if key is 'f' else // go back if(key == 'b') { TopLine -= 20; if(TopLine < 0) TopLine = 0; writeIndex(); } // if key is 'b' } // ProcessKey() should never be called
void write_htmlNastStat::writePage(void) { pageTitle = "NAST statistics"; htmlpage.open (HTMLfilesRegister::nastStatistics); writeHead(); writeIndex(); // Global statistics writeSectionTitle("Statistics about all the NAST"); writeGlobalStatistics(); // Partial statistics writeSectionTitle("Statistics about the functions with body"); writePartialStatistics(); writeIndex(); writeFoot(); htmlpage.close(); return; }
//线程1:抓包分析,保存至xml文件 void *thread1(void *arg){ //写入索引文件 writeIndex(); //初始化 hotspot_records_count = 0; sta_records_count = 0; //检测是否能成功进行抓包 if (myPcapCatchAndAnaly() == 0) { printf("device error!!\n"); //产生错误,结束该线程 pthread_exit(NULL); } return NULL; }
void flush() { if ( curcnt ) { *(pc++) = ptype(cursym,curcnt); implicitFlush(); curcnt = 0; } SGO.flush(); uint64_t const indexpos = SGO.getWrittenBytes(); writeIndex(indexpos); }
void QOrmAttributeInfo::load(QOrmObject *obj, QVariant value) { if (!d->valid) return; if (!d->f_ld) { if (isForeignKey() || isPrimaryKey()) writeIndex(obj, value); if (d->metaProperty.type() < QVariant::UserType) //d->metaProperty.write(obj, value); obj->setProperty(d->property, value); return; } (obj->*(d->f_ld))(value); }
void writeIndex(uint64_t const indexpos) { if ( ! indexwritten ) { ::libmaus::aio::SynchronousGenericOutput<uint8_t> SGO(COS,64*1024); ::libmaus::aio::SynchronousGenericOutput<uint8_t>::iterator_type it(SGO); ::libmaus::bitio::FastWriteBitWriterStream8Std FWBWS(it); writeIndex(index,FWBWS,indexpos); FWBWS.flush(); SGO.flush(); COS.flush(); indexwritten = true; } }
bool NetDemo::stopRecording() { if (!isRecording()) { return false; } state = NetDemo::stopped; byte marker = svc_netdemostop; uint32_t len = sizeof(marker); len = LONG(len); uint32_t tic = LONG(gametic); fwrite(&len, sizeof(len), 1, demofp); fwrite(&tic, sizeof(tic), 1, demofp); // write the end-of-demo marker fwrite(&marker, sizeof(marker), 1, demofp); // tack the snapshot index onto the end of the recording header.snapshot_index_offset = ftell(demofp); header.snapshot_index_size = snapshot_index.size() * NetDemo::INDEX_ENTRY_SIZE; if (!writeIndex()) { error("Unable to write netdemo index."); return false; } // rewrite the header since snapsnot_index_offset and // snapshot_index_size are now known if (!writeHeader()) { error("Unable to write updated netdemo header."); return false; } fclose(demofp); demofp = NULL; Printf(PRINT_HIGH, "Demo recording has stopped.\n"); return true; }
void SaveableFlannBasedMatcher::store() { // Save the matches IndexParams & SearchParams std::string treeFilename(filename); treeFilename += "-tree.xml.gz"; cv::FileStorage store(treeFilename.c_str(), cv::FileStorage::WRITE); write(store); store.release(); // Save the matcher index std::string indexFilename(filename); indexFilename += ".flannindex"; writeIndex(indexFilename.c_str()); // Save the descriptors std::vector<Mat> descs = getTrainDescriptors(); std::string descriptorsFilename(filename); descriptorsFilename += "-descriptors.bin"; writeDescriptors(descs, descriptorsFilename.c_str()); }
int KMFolderIndex::updateIndex( bool aboutToClose ) { Q_UNUSED( aboutToClose ); if (!mAutoCreateIndex) return 0; bool dirty = mDirty; mDirtyTimer->stop(); for ( int i = 0; !dirty && i < mMsgList.high(); i++ ) { if ( mMsgList.at(i) ) { if ( !mMsgList.at(i)->syncIndexString() ) { dirty = true; } } } if (!dirty) { // Update successful touchFolderIdsFile(); return 0; } return writeIndex(); }
// Write the file void Document::write( std::FILE *out ) { hdr->write( out ); //write the header hdr->panelCount = static_cast< STD1::uint16_t>( resMap.size() ); hdr->panelOffset = writeResMap( out ); hdr->nameCount = !isInf() ? static_cast< STD1::uint16_t >( nameMap.size() ) : 0; hdr->nameOffset = writeNameMap( out ); eHdr->gNameOffset = gnames->write( out ); eHdr->gNameCount = gnames->size(); hdr->imageOffset = writeBitmaps( out ); hdr->tocCount = static_cast< STD1::uint16_t >( pages.size() ); hdr->tocOffset = writeTOCs( out ); hdr->tocOffsetOffset = writeTOCOffsets( out ); writeSynonyms( out ); hdr->indexOffset = writeIndex( out ); hdr->icmdOffset = writeICmd( out ); hdr->nlsOffset = nls->write( out ); hdr->nlsSize = nls->length(); eHdr->stringsOffset = strings->write( out ); eHdr->stringsSize = static_cast< STD1::uint16_t >( strings->length() ); eHdr->dbOffset = extfiles->write( out ); eHdr->dbCount = static_cast< STD1::uint16_t >( extfiles->size() ); eHdr->dbSize = extfiles->length(); eHdr->fontOffset = fonts->write( out ); eHdr->fontCount = static_cast< STD1::uint16_t >( fonts->size() ); eHdr->ctrlOffset = controls->write( out ); eHdr->ctrlSize = controls->length(); hdr->dictOffset = dict->write( out ); hdr->dictSize = dict->length(); hdr->dictCount = dict->size(); writeCells( out ); hdr->cellCount = static_cast< STD1::uint16_t >( cells.size() ); hdr->cellOffsetOffset = writeCellOffsets( out ); eHdr->childPagesOffset = writeChildWindows( out ); if( compiler.searchable() ) { hdr->searchOffset = dict->writeFTS( out, hdr->recSize ); hdr->searchSize = dict->ftsLength(); } hdr->extOffset = eHdr->write( out ); hdr->write( out ); //rewrite the header to update the offsets }
//----------------------------------------------------------------------------- int KMFolder::create(void) { int rc; int old_umask; assert(name() != ""); assert(mOpenCount == 0); if (access(location(), F_OK) == 0) return EEXIST; old_umask = umask(077); mStream = fopen(location(), "w+"); //sven; open RW umask(old_umask); if (!mStream) return errno; if (!path().isEmpty()) { old_umask = umask(077); mIndexStream = fopen(indexLocation(), "w+"); //sven; open RW umask(old_umask); if (!mIndexStream) return errno; } else { //debug("Folder `" + name() + // "' has no path specified -- turning autoCreateIndex off"); mAutoCreateIndex = FALSE; } mOpenCount++; mQuiet = 0; rc = writeIndex(); if (!rc) lock(); return rc; }
//----------------------------------------------------------------------------- void KMFolder::close(bool aForced) { if (mOpenCount <= 0 || !mStream) return; if (mOpenCount > 0) mOpenCount--; if (mOpenCount > 0 && !aForced) return; if (mAutoCreateIndex) { if (mDirty) writeIndex(); else sync(); } unlock(); mMsgList.clear(TRUE); if (mStream) fclose(mStream); if (mIndexStream) fclose(mIndexStream); mOpenCount = 0; mStream = NULL; mIndexStream = NULL; mFilesLocked = FALSE; mMsgList.reset(INIT_MSGS); }
/** * main... : * sets the CLI parameters * startup operations * kicks off the indexing * writes the results * frees the large data structures in use * done! */ int main (int argc, char **argv) { gchar* inFileName = NULL; gchar* outFileName = NULL; if (! checkCLIParams (argc, argv, &inFileName, &outFileName)) { //failed to parse the CLI opts return (1); } // count of articles found in collection int articleCount = 0; // array of judy arrays for the index Pvoid_t wikiIndex[lastNgram] = {(Pvoid_t) NULL}; indexWiki (inFileName, wikiIndex, &articleCount); writeNgramStats (wikiIndex, articleCount); if (writeFiles) {writeIndex (wikiIndex, articleCount, outFileName);} freeIndex (wikiIndex); optionalPrint ("%s", "Finished!\n"); return(0); }
void write_htmlFnctPages::writePage(void) { // most of the informations can be write only if the function has a body ! dataDrawerListIterator p; // browse the list string fnctName; // name of the function // Browse list one function for time p = dataBL->begin(); while (p != dataBL->end()) { dataB = *p; p++; fData = dataB->getFnctData(); cout << "Generating html page for function " << (fnctName = fData->getName()) << "...\n"; htmlpage.open((HTMLfilesRegister::htmlFile(*fData)).c_str()); // begin of the page pageTitle = fnctName ; writeHead(); writeIndex(); htmlpage << "<br><br>\n"; if (fnctName != "") htmlpage << "This is the page of the function " << fnctName << ".<br><br>\n"; htmlpage << *fData << "<br><l><br>\n\n"; if (fData->hasBody()) { writePageIndex(); // write body graph if (!noBodyGraph) { htmlpage << "<A name=\"bodyGraph\">\n"; writeSectionTitle("Graph of the body"); writeBodyGraph(); } // write CFG if (!noCFG) { htmlpage << "<A name=\"CFG\">\n"; writeSectionTitle("Control flow graph"); writeCFG(); } // write stmt stat if (!noStmtStat) { htmlpage << "<A name=\"stmtStatistics\">\n"; writeSectionTitle("Statements statistics"); htmlpage << *(dataB->getStmtNumData()); } // write decl list if ( (!noDeclsList) && (dataB->hasDeclsList()) ) { htmlpage << "<A name=\"declsList\">\n"; writeSectionTitle("Declarations into the function"); htmlpage << *(dataB->getDeclsList()); } // write var used if ( (!noVarUsed) && (dataB->hasVarUsedList()) ) { htmlpage << "<A name=\"varUsedList\">\n"; writeSectionTitle("Variables used by the function"); htmlpage << *(dataB->getVarUsedList()); } // write exprs list if ( (!noExprsList) && (dataB->hasExprsList()) ) { htmlpage << "<A name=\"exprsList\">\n"; writeSectionTitle("List of the expressions"); htmlpage << *(dataB->getExprsList()); } // write expr stat if (!noExprStat) { htmlpage << "<A name=\"exprStatistics\">\n"; writeSectionTitle("Expression statistics"); htmlpage << *(dataB->getExprNumData()); } // write call graph if (!noCallGraph) { htmlpage << "<A name=\"callGraph\">\n"; writeSectionTitle("Call graph"); writeCallGraph(); } } // end of the page writeIndex(); writeFoot(); htmlpage.close(); } return; }
//----------------------------------------------------------------------------- int KMFolder::createIndexFromContents(void) { char line[MAX_LINE]; char status[8], xstatus[8]; QString subjStr, dateStr, fromStr, toStr, xmarkStr, *lastStr=NULL; QString whoFieldName; unsigned long offs, size, pos; bool atEof = FALSE; bool inHeader = TRUE; KMMsgInfo* mi; QString msgStr(256); QRegExp regexp(MSG_SEPERATOR_REGEX); int i, num, numStatus, whoFieldLen; short needStatus; assert(mStream != NULL); rewind(mStream); mMsgList.clear(); num = -1; numStatus= 11; offs = 0; size = 0; dateStr = ""; fromStr = ""; toStr = ""; subjStr = ""; *status = '\0'; *xstatus = '\0'; xmarkStr = ""; needStatus = 3; whoFieldName = QString(whoField()) + ':'; //unused (sven) whoFieldLen = whoFieldName.length(); //unused (sven) //debug("***whoField: %s (%d)", // (const char*)whoFieldName, whoFieldLen); while (!atEof) { pos = ftell(mStream); if (!fgets(line, MAX_LINE, mStream)) atEof = TRUE; if (atEof || (strncmp(line,MSG_SEPERATOR_START, msgSepLen)==0 && regexp.match(line) >= 0)) { size = pos - offs; pos = ftell(mStream); if (num >= 0) { if (numStatus <= 0) { msgStr.sprintf(i18n("Creating index file: %d messages done"), num); emit statusMsg(msgStr); numStatus = 10; } if (size > 0) { mi = new KMMsgInfo(this); mi->init(subjStr, fromStr, toStr, 0, KMMsgStatusNew, xmarkStr, offs, size); mi->setStatus(status,xstatus); mi->setDate(dateStr); mi->setDirty(FALSE); mMsgList.append(mi); *status = '\0'; *xstatus = '\0'; needStatus = 3; xmarkStr = ""; dateStr = ""; fromStr = ""; subjStr = ""; } else num--,numStatus++; } offs = ftell(mStream); num++; numStatus--; inHeader = TRUE; continue; } // Is this a long header line? if (inHeader && (line[0]=='\t' || line[0]==' ')) { i = 0; while (line [i]=='\t' || line [i]==' ') i++; if (line [i] < ' ' && line [i]>0) inHeader = FALSE; else if (lastStr) *lastStr += line + i; } else lastStr = NULL; if (inHeader && (line [0]=='\n' || line [0]=='\r')) inHeader = FALSE; if (!inHeader) continue; if ((needStatus & 1) && strncasecmp(line, "Status:", 7) == 0 && isblank(line[7])) { for(i=0; i<4 && line[i+8] > ' '; i++) status[i] = line[i+8]; status[i] = '\0'; needStatus &= ~1; } else if ((needStatus & 2) && strncasecmp(line, "X-Status:", 9)==0 && isblank(line[9])) { for(i=0; i<4 && line[i+10] > ' '; i++) xstatus[i] = line[i+10]; xstatus[i] = '\0'; needStatus &= ~2; } else if (strncasecmp(line,"X-KMail-Mark:",13)==0 && isblank(line[13])) xmarkStr = QString(line+14).copy(); else if (strncasecmp(line,"Date:",5)==0 && isblank(line[5])) { dateStr = QString(line+6).copy(); lastStr = &dateStr; } else if (strncasecmp(line,"From:", 5)==0 && isblank(line[5])) { fromStr = QString(line+6).copy(); lastStr = &fromStr; } else if (strncasecmp(line,"To:", 3)==0 && isblank(line[3])) { toStr = QString(line+4).copy(); lastStr = &toStr; } else if (strncasecmp(line,"Subject:",8)==0 && isblank(line[8])) { subjStr = QString(line+9).copy(); lastStr = &subjStr; } } if (mAutoCreateIndex) { emit statusMsg(i18n("Writing index file")); writeIndex(); } else mHeaderOffset = 0; return 0; }
bool KMFolderIndex::readIndex() { qint32 len; KMMsgInfo* mi; assert(mIndexStream != 0); rewind(mIndexStream); clearIndex(); int version; setDirty( false ); if (!readIndexHeader(&version)) return false; mUnreadMsgs = 0; mTotalMsgs = 0; mHeaderOffset = KDE_ftell(mIndexStream); clearIndex(); while (!feof(mIndexStream)) { mi = 0; if(version >= 1505) { if(!fread(&len, sizeof(len), 1, mIndexStream)) break; if (mIndexSwapByteOrder) len = kmail_swap_32(len); off_t offs = KDE_ftell(mIndexStream); if(KDE_fseek(mIndexStream, len, SEEK_CUR)) break; mi = new KMMsgInfo(folder(), offs, len); } else { QByteArray line( MAX_LINE, '\0' ); fgets(line.data(), MAX_LINE, mIndexStream); if (feof(mIndexStream)) break; if (*line.data() == '\0') { fclose(mIndexStream); //kDebug( KMKernel::storageDebug() ) << "fclose(mIndexStream = " << mIndexStream << ")"; mIndexStream = 0; clearIndex(); return false; } mi = new KMMsgInfo(folder()); mi->compat_fromOldIndexString(line, mConvertToUtf8); } if(!mi) break; if (mi->status().isDeleted()) { delete mi; // skip messages that are marked as deleted setDirty( true ); needsCompact = true; //We have deleted messages - needs to be compacted continue; } #ifdef OBSOLETE else if (mi->isNew()) { mi->setStatus(KMMsgStatusUnread); mi->setDirty(false); } #endif if ((mi->status().isNew()) || (mi->status().isUnread()) || (folder() == kmkernel->outboxFolder())) { ++mUnreadMsgs; if (mUnreadMsgs == 0) ++mUnreadMsgs; } mMsgList.append(mi, false); } if( version < 1505) { mConvertToUtf8 = false; setDirty( true ); writeIndex(); } mTotalMsgs = mMsgList.count(); return true; }
AutomapTerrainRuleRecorder::AutomapTerrainRuleRecorder() { std::vector<std::string> types = Consts::get("terrainTypes", "Flared").toVector<std::string>(); d_outputLayerName = (std::string)Consts::get("terrainOutputLayer", "Flared"); d_inputTilesetName = (std::string)Consts::get("terrainInputTileset", "Flared"); for(auto& i : types) { if(i.empty()) continue; d_terrainTypeName = i; std::vector<size_t> from = Consts::get("from", "flared_" + d_terrainTypeName).toVector<size_t>(); std::vector<size_t> to = Consts::get("to", "flared_" + d_terrainTypeName).toVector<size_t>(); d_tilesetToName = (std::string)Consts::get("file", "flared_" + d_terrainTypeName); size_t animation_frames = 0; size_t animation_shift = 0; if(Consts::isExist("animation_frames", "flared_" + d_terrainTypeName)) animation_frames = Consts::get("animation_frames", "flared_" + d_terrainTypeName); if(Consts::isExist("animation_shift", "flared_" + d_terrainTypeName)) animation_shift = Consts::get("animation_shift", "flared_" + d_terrainTypeName); cocos2d::FileUtils::getInstance()->getWritablePath(); const std::string fname = cocos2d::FileUtils::getInstance()->getWritablePath() + d_terrainTypeName + ".automap"; cocos2d::FileUtils::getInstance()->removeFile(fname); std::ofstream F(fname); //center writeGroupHeader(F, RULE_MAKER_STR(crName, d_terrainTypeName, crCenterName)); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 128, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift); //edge writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crEdgeName, crTopName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 192, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 3); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crEdgeName, crLeftName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {128, 128, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 2); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crEdgeName, crRightName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {0, 128, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 0); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crEdgeName, crBottomName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 64, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 1); //corner writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crCornerName, crRightName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {128, 32, 32, 32} ); writeIndex(F, d_tilesetToName, {64, 192, 64, 64} ); writeIndex(F, d_tilesetToName, {0, 128, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 128, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 0); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crCornerName, crTopName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {128, 0, 32, 32} ); writeIndex(F, d_tilesetToName, {0, 128, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 64, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 128, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 1); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crCornerName, crLeftName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {160, 0, 32, 32} ); writeIndex(F, d_tilesetToName, {64, 64, 64, 64} ); writeIndex(F, d_tilesetToName, {128, 128, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 128, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 2); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crCornerName, crBottomName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {160, 32, 32, 32} ); writeIndex(F, d_tilesetToName, {128, 128, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 192, 64, 64} ); writeIndex(F, d_tilesetToName, {64, 128, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 3); //inside corner writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crInsideconrnerName, crRightName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {128, 64, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 0); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crInsideconrnerName, crTopName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {128, 192, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 1); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crInsideconrnerName, crLeftName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {0, 192, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 2); writeGroupHeader(F, RULE_MAKER_STR4(crName, d_terrainTypeName, crInsideconrnerName, crBottomName)); writeIndex(F, d_inputTilesetName, from ); writeIndex(F, d_inputTilesetName, to ); writeIndex(F, d_tilesetToName, {64, 0, 64, 64} ); writeIndex(F, d_tilesetToName, {0, 64, 64, 64} ); writeGroupFooter(F, animation_frames, animation_shift, 3); F.close(); Consts::loadAdditionalConsts(fname); } }
void Plugin::addFile(const std::string filepath) { logger().debug("Adding file"); // Check if file exists and it's not a directory File file(filepath); if (!file.exists()) { std::cout << "Failed to add file " << filepath.c_str() << ": file does not exist" << std::endl; return; } if (file.isDirectory()) { std::cout << "Failed to add file " << filepath.c_str() << ": file is a directory" << std::endl; return; } File index(Plugin::GIT_BIN_INDEX); if (!index.exists()) { index.createFile(); } // Find this file in the index if (isFileIndexed(filepath) && file.isLink()) { logger().debug("File already in cache"); auto entry = getIndexEntry(filepath); if (entry == nullptr) { std::cout << "Failed to retrieve index meta data for " << filepath << std::endl; return; } // Not fresh. Update existing index file // Remove file from index before recalculating everything for (auto it = _index.begin(); it != _index.end();) { if ((*it).filepath == filepath) { // Remove link std::cout << "Replacing link with original file" << std::endl; file.remove(); Process::Args restoreArgs; std::string restorePath(Plugin::GIT_CACHE_DIR); restorePath.append("/wf/"); restorePath.append((*it).uuid); restoreArgs.push_back(restorePath); restoreArgs.push_back(filepath); Process::launch("mv", restoreArgs, 0, 0, 0); it = _index.erase(it); } else { it++; } } } // Add new file into index UUIDGenerator gen; IndexEntry e; e.filepath = filepath; e.md5 = getFileMd5(filepath); e.uuid = gen.createRandom().toString(); do { e.uuid = gen.createRandom().toString(); } while (!isUuidUnique(e.uuid)); _index.push_back(e); writeIndex(); // Place two copies of this file into cache // One copy is original file and don't tracked in any way // Second copy is a file we will create link to Process::Args args; args.push_back(filepath); std::string origPath(Plugin::GIT_CACHE_DIR); origPath.append("/of/").append(e.uuid); args.push_back(origPath); Poco::ProcessHandle copyProcess = Process::launch("cp", args, 0, 0, 0); if (copyProcess.wait() != 0) { std::cout << "Failed to move file into git-bin cache" << std::endl; return; } // Second stage copy args.clear(); args.push_back(filepath); std::string workPath(Plugin::GIT_CACHE_DIR); workPath.append("/wf/").append(e.uuid); args.push_back(workPath); copyProcess = Process::launch("mv", args, 0, 0, 0); if (copyProcess.wait() != 0) { std::cout << "Failed to move file on stage 2" << std::endl; return; } // Make a link args.clear(); args.push_back("-s"); Path rel(filepath); std::string relPath; for (int i = 0; i < rel.depth(); i++) { relPath.append("../"); } relPath.append(workPath); args.push_back(relPath); args.push_back(filepath); Poco::ProcessHandle linkProcess = Process::launch("ln", args, 0, 0, 0); if (linkProcess.wait() != 0) { std::cout << "Failed to create link to file" << std::endl; return; } args.clear(); args.push_back("add"); args.push_back(filepath); Poco::ProcessHandle gitAddProcess = Process::launch("git", args, 0, 0, 0); if (gitAddProcess.wait() != 0) { std::cout << "Failed to add file into git index (git add)" << std::endl; return; } }