/// Recursively removing the content of the directory 'path' void emptyFolder(const std::string &path) { if (DIR *folder = opendir(path.c_str())) { while (struct dirent *entry = readdir(folder)) { if (strcmp(entry->d_name,".") == 0 || strcmp(entry->d_name,"..") == 0) continue; std::stringstream buf; buf << path << '/' << entry->d_name; /// std::stringstream::str() returns a temporary string which is destroy when the expression ends. /// So the following expression is wrong and filepath will points to a string destroyed before the next statement. /// const char *filepath = buf.str().c_str(); /// Therefore we have to copy the stringstream buffer in order to used it after the expression is done. /// See. http://stackoverflow.com/questions/24011182/recursive-stdstringstream-and-c-str/24011602#24011602 /// std::string filepath(buf.str()); const std::string filepath = buf.str(); if (entry->d_type == DT_DIR) emptyFolder(filepath); if (remove(filepath.c_str()) == 0) CCLOG("File removed: %s", filepath.c_str()); else CCLOGERROR("Can't delete file %s (%s)", filepath.c_str(), strerror(errno)); } closedir(folder); } else { CCLOGERROR("Can't open directory %s (%s)", path.c_str(), strerror(errno)); } }
/** * \fn void deleteBdd(std::string bddName) * \brief Deletes a BDD * * \param[in] bddName The name of the bdd. */ void deleteBdd(std::string bddName){ string path2bdd("bdd/" + bddName); // On récupère les données des activités préexistantes activitiesMap *am; int nbActivities = mapActivities(path2bdd,&am); int i = 0; while(i < nbActivities){ deleteActivity(am[i].activity, bddName); i++; } delete []am; emptyFolder(path2bdd); rmdir(path2bdd.c_str()); }
bool Assets::enableMutliResolutionSupport() { /// Multi resolution support BEFORE cocos2d-x 2.0.4 /// The correct resolution is enableds using setResourceDirectory which set the resource directory for the current device's resolution /// Shared/common images to all resolutions are stored in the root resources (Resources/GameResources/textures) /// See http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Mechanism_of_loading_resources /**************************************************************************************************************** * * Since 2.0.4, cocos2d-x introduced a new multi-resolution support * http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support * http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation * * Set the design resolution: width, height and policy * * - kResolutionExactFit - * The entire application is visible in the specified area without trying to preserve the original aspect ratio. * Distortion can occur, and the application may appear stretched or compressed. * * - kResolutionNoBorder - * The entire application fills the specified area, without distortion but possibly with some cropping, * while maintaining the original aspect ratio of the application. * * - kResolutionShowAll - * The entire application is visible in the specified area without distortion while maintaining the original * aspect ratio of the application. Borders can appear on two sides of the application. ****************************************************************************************************************/ CCDirector* pDirector = CCDirector::sharedDirector(); CCEGLView* pEGLView = pDirector->getOpenGLView(); CCFileUtils &fileUtils = *CCFileUtils::sharedFileUtils(); pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionExactFit); CCSize frameSize = pEGLView->getFrameSize(); /// We select resource according to the frame's height. /// If the resource size is different from design resolution size, you need to set contentScaleFactor. /// We use the ratio of resource's height to the height of design resolution, /// this can make sure that the resource's height could fit for the height of design resolution. std::vector<std::string> resOrder = fileUtils.getSearchResolutionsOrder(); /// GPU max texture size GLint maxTextureSize = 0; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); CCLOG("GPU max texture size: %d", maxTextureSize); bool scaledGraphics = false; /// set the contentScaleFactor based on the ratio of WIDTH if (frameSize.width > mediumResource.size.width && maxTextureSize >= 2048) { CCLOG("Select LARGE (ipadhd) resource..."); resOrder.insert(resOrder.begin(), largeResource.directory); /// pDirector->setContentScaleFactor(largeResource.size.width/designResolutionSize.width); pDirector->setContentScaleFactor(4.f); } // if the frame's height is larger than the height of small resource size, select medium resource. else if (frameSize.width > smallResource.size.width && maxTextureSize >= 1024) { CCLOG("Select MEDIUM (hd) resource..."); resOrder.insert(resOrder.begin(), mediumResource.directory); /// pDirector->setContentScaleFactor(mediumResource.size.width/designResolutionSize.width); pDirector->setContentScaleFactor(2.f); scaledGraphics = frameSize.width > mediumResource.size.width; // have scale down because of max texture size too small? } // if the frame's height is smaller than the height of medium resource size, select small resource. else { CCLOG("Select SMALL (sd) resource..."); resOrder.insert(resOrder.begin(), smallResource.directory); /// pDirector->setContentScaleFactor(smallResource.size.width/designResolutionSize.width); pDirector->setContentScaleFactor(1.f); scaledGraphics = frameSize.width > smallResource.size.width; // have scale down because of max texture size too small? } /// Show an error message if we scaled down the graphics or the max texture size is too small if (scaledGraphics || maxTextureSize < 512) { CCLOGERROR("Unsupported max texture size: %d",maxTextureSize); CCMessageBox("We detected graphics limitation which might prevent the app to work properly or to use HD graphics (max texture too small)", "ERROR"); } /// Bug fix: the resolution directory must have a trailing slash (e.g. hd/ or sd/) or /// CCFileUtils::getFullPathForDirectoryAndFilename() will not work correclty on iOS if /// both search paths and resolution order are defined (missing slash between directory and filename). /// We now use setSearchResolutionsOrder instead of addSearchResolutionsOrder because /// addSearchResolutionsOrder simply add the string to the list of the resolution order without adding the trailing slash. /// setSearchResolutionOrder takes care of adding the trailing slash if missing. /// See. http://discuss.cocos2d-x.org/t/search-paths-and-resolutions-order-issue-on-ios/14424 fileUtils.setSearchResolutionsOrder(resOrder); /// Set the font sizes for (int i = 0; i < 4; i++) smFontsSize[i] *= designResolutionSize.width / smallResource.size.width; ////////////////// Trace settings... ///////////////// #if COCOS2D_DEBUG > 0 /// Redirect standard output and error stream to file //freopen(fileUtils.getWritablePath().append("cocos2d.log").c_str(), "a+", stdout); //freopen(fileUtils.getWritablePath().append("cocos2d.log").c_str(), "a+", stderr); /// In debug mode we change the default search path to the following. std::vector<std::string> paths; paths.push_back(fileUtils.getWritablePath()); /// First we search the writable path root for assets download on-the-fly (see command.h/cpp) paths.push_back(fileUtils.getWritablePath().append("lua")); /// Secondly we search in the lua folder below the writable root for lua script paths.push_back(""); /// Finally we look in the default resource path (empty string) fileUtils.setSearchPaths(paths); TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform(); if (platform == kTargetAndroid || platform == kTargetIpad || platform == kTargetIphone) { /// Purge the writable folder CCLOG("Removing files from the assets staging area (writable path)..."); /// TODO on mac getWritablePath is "/Users/lzubiaur/Library/Caches/". /// So it should not be wipe out but temporary assets should be written in a subfolder emptyFolder(fileUtils.getWritablePath()); } CCLOG("Real screen size: %.0fx%.0f", pEGLView->getFrameSize().width, pEGLView->getFrameSize().height); CCLOG("Design resolution size: %.0fx%.0f", pEGLView->getDesignResolutionSize().width, pEGLView->getDesignResolutionSize().height); CCLOG("Content scale factor: %f", pDirector->getContentScaleFactor()); CCLOG("Scale x:%f y:%f", pEGLView->getScaleX(), pEGLView->getScaleY()); CCLOG("Visible origin: x:%.0f y:%.0f",pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y); CCLOG("Visible size: %.0fx%.0f", pEGLView->getVisibleSize().width, pEGLView->getVisibleSize().height); /// Log the search paths std::string searchPath; for (const std::string s : fileUtils.getSearchPaths()) searchPath.append(' ' + s); CCLOG("Search path: %s", searchPath.c_str()); /// Log the search resolution order std::string resolutionOrder; for (const std::string s : fileUtils.getSearchResolutionsOrder()) resolutionOrder.append(' ' + s); CCLOG("Search resolution order: %s", resolutionOrder.c_str()); CCLOG("Writeable path: %s", fileUtils.getWritablePath().c_str()); CCLOG("Lua version: %s",LUA_VERSION); /// CCLOG("Websocket version %s",lws_get_library_version()); /* d("top: %f %f", CVisibleRect::top().x, CVisibleRect::top().y ); d("rightTop: %f %f", CVisibleRect::rightTop().x, CVisibleRect::rightTop().y ); d("leftTop: %f %f", CVisibleRect::leftTop().x, CVisibleRect::leftTop().y ); d("left: %f %f", CVisibleRect::left().x, CVisibleRect::left().y ); d("right: %f %f", CVisibleRect::right().x, CVisibleRect::right().y ); d("leftBottom: %f %f", CVisibleRect::leftBottom().x, CVisibleRect::leftBottom().y ); d("rightBottom: %f %f", CVisibleRect::rightBottom().x, CVisibleRect::rightBottom().y ); d("center: %f %f", CVisibleRect::center().x, CVisibleRect::center().y ); d("bottom: %f %f", CVisibleRect::bottom().x, CVisibleRect::bottom().y ); */ #endif return true; }
void GMainEditor::startOneFileOCR(){ pechaImg=LoadImageData(inputData.data["inputFile"],0); cout<<"Start#1 "<<inputData.data["inputFile"]<<END; if(!pechaImg){cout<<"no open file"<<inputData.data["inputFile"]<<endl; return;} inputData.data["ocrData"]="oneStringOCR"; mainString=""; vector<stringOCR>strArray; int border; string str; string xmlString; int print=1; DT("@4_1"); //vectorBase[0].allVectorCount=0; border=0; setBit=GBitset::createResize(pechaImg,1,1,1); DT("@4_2"); setBit->pageStringDetector(strArray,1); // Подпрограмма выделения строк и букв ПЕЧА ( РЕЛЬСЫ ) DT("@4_3"); border=setBit->border_size(); DT("@4_4"); setBit->destroy(); //получили координаты строк. Создаем новый процесс для каждой строки vector<int> pidID(inputData.num_cores); int status,pid; for(int index=0;index<pidID.size();index++){ pidID[index]=0; } for(int a=0;a<strArray.size();a++)strArray[a].selectFlag=0; int i=strArray.size()-1; int processCount=0; while(i>=0){ cout<<"NEW string# "<<i<<endl; for(int index=0;index<pidID.size();index++){ if(pidID[index]==0){ strArray[i].selectFlag=1; processCount++; pidID[index] = fork(); if (pidID[index] < 0) error((char*)"ERROR on fork"); if (pidID[index] == 0) { GBitsetOCR *setOCR=GBitsetOCR::createResize(pechaImg,1,1); //if(NewLetterOnlyBtn->Checked==true) {mode=NEWLETTERINBOOK;}else{mode=ALL_LETTER;} setOCR->setData( aliKali, strArray, correctionTable, logicProcessor, iLeft, iTop, border, ALL_LETTER); mainString=setOCR->mainString; xmlString=setOCR->xmlString; //cout<<"mainString="<<mainString<<endl; ostringstream out; out<<inputData.data["root"]<<"edit/OCR/_DATA/"; out.width(4); out.fill('0'); out<<strArray.size()-i-1<<".html"; string path=out.str(); writeText(mainString,path); out.str(""); out<<inputData.data["root"]<<"edit/OCR/_DATA/"; out.width(4); out.fill('0'); out<<strArray.size()-i-1<<".xml"; path=out.str(); writeText(xmlString,path); setOCR->destroy(); exit(0); } strArray[i].selectFlag=0; i--;if(i==-1)break; } } pid=wait(&status); cout<<"new pecha"; for(int index=0;index<pidID.size();index++){ if(pid==pidID[index]){pidID[index]=0;processCount--;} } } cout<<"start processCount="<<processCount<<endl; while(processCount){pid=wait(&status); if(pid>0){ processCount--; cout<<"pid="<<pid<<" processCount="<<processCount<<endl; } } cout<<"collect all fork result in one file"; vector<string>fileList; string path=inputData.data["root"]+"edit/OCR/_DATA/"; int count=0; while(1){ readDirectoryToArray(fileList, path,"html"); if(fileList.size()!=strArray.size()){ cout<<"data not ready. has"<<fileList.size()<<" files. must be "<<strArray.size()<<" wait 2 sec."<<endl; count++; if(count==11)break; fileList.resize(0); sleep(2); }else break; } for(int a=0;a<fileList.size();a++){ string str; readText(str,fileList[a]); mainString+=str; } //cout<<"mainString="<<mainString<<endl; drawStrArray(strArray,border); xmlString=""; fileList.resize(0); readDirectoryToArray(fileList, path,"xml"); for(int a=0;a<fileList.size();a++){ string str; readText(str,fileList[a]); xmlString+=str; } //cout<<"xmlString="<<xmlString<<endl; writePageXML(xmlString); emptyFolder(path); }//_________________________________