Beispiel #1
0
 void _applyOpToDataFiles( const string& database, FileOp &fo, bool afterAllocator, const string& path ) {
     if ( afterAllocator )
         FileAllocator::get()->waitUntilFinished();
     string c = database;
     c += '.';
     boost::filesystem::path p(path);
     if (storageGlobalParams.directoryperdb)
         p /= database;
     boost::filesystem::path q;
     q = p / (c+"ns");
     bool ok = false;
     MONGO_ASSERT_ON_EXCEPTION( ok = fo.apply( q ) );
     if ( ok ) {
         LOG(2) << fo.op() << " file " << q.string() << endl;
     }
     int i = 0;
     int extra = 10; // should not be necessary, this is defensive in case there are missing files
     while ( 1 ) {
         verify( i <= DiskLoc::MaxFiles );
         stringstream ss;
         ss << c << i;
         q = p / ss.str();
         MONGO_ASSERT_ON_EXCEPTION( ok = fo.apply(q) );
         if ( ok ) {
             if ( extra != 10 ) {
                 LOG(1) << fo.op() << " file " << q.string() << endl;
                 log() << "  _applyOpToDataFiles() warning: extra == " << extra << endl;
             }
         }
         else if ( --extra <= 0 )
             break;
         i++;
     }
 }
Beispiel #2
0
// this function is shared by chmod/utime/chown maybe others
// it's here for directories which may span multiple backends
// returns PLFS_SUCCESS or PLFS_E*
static plfs_error_t plfs_flatfile_operation(struct plfs_physpathinfo *ppip,
                                   FileOp& op, IOStore *ios) {
    plfs_error_t ret = PLFS_SUCCESS; 
    vector<plfs_pathback> dirs;
    struct stat st;
    mode_t mode = 0;

    ret = ppip->canback->store->Lstat(ppip->canbpath.c_str(), &st);
    if (ret != PLFS_SUCCESS){
        mode = 0;
    } else {
        mode = st.st_mode;
    }
    
    //perform operation on ALL directories
    if (S_ISDIR(mode)){
        ret = generate_backpaths(ppip, dirs);
        vector<plfs_pathback>::reverse_iterator ritr;
        for(ritr = dirs.rbegin(); ritr != dirs.rend() && ret == PLFS_SUCCESS; ++ritr) {
            ret = op.op(ritr->bpath.c_str(),DT_DIR,ritr->back->store);
        }
    }
    //we hit a regular flat file
    else if(S_ISREG(mode)){
        ret = op.op(ppip->canbpath.c_str(), DT_REG, ios);
    }
    //symlink
    else if (S_ISLNK(mode)){
        ret = op.op(ppip->canbpath.c_str(), DT_LNK, ios);
    }
    return(ret);
}
Beispiel #3
0
int main() {
	// Start Object
	FileOp test = FileOp("test", "test");
	test.run("C:\\Users\\super_000\\Code\\ClassDev\\ProgLang\\Python\\initial_file.txt");
	
	// Exit Program
	system("PAUSE");
	return 0;
}
Beispiel #4
0
// Disabled this function as it is currently not used.
// If we decide to use, we should check on the usage of fileop.getFileName().
// With iteration 17, the more common version of this getFileName() takes a
// partition and segment number in addition to an OID.  openColumnFile
// should perhaps be changed to use this updated version of getFileName().
  bool DDLIndexPopulator::openColumnFile(WriteEngine::OID oid)
  {
    FileOp fileOp;
    char fileName[WriteEngine::FILE_NAME_SIZE];
    if (WriteEngine::NO_ERROR == fileOp.getFileName(oid, fileName) )
    {	
	fColumnFile.open(fileName);
	return true;
    }
    else
    {	
	logError("Could not get column file name for data");
	return false;
    }
  }
/**
 * plfs_backends_op: apply a fileop to all the backends in a mount.
 * currently used by readdir, rmdir, mkdir
 * this doesn't require the dires to already exist
 *
 * @param ppip the phyiscal path we are operating on
 * @param op the file op to apply
 * @return PLFS_SUCCESS or PLFS_E*
 */
plfs_error_t
plfs_backends_op(struct plfs_physpathinfo *ppip, FileOp& op)
{
    plfs_error_t ret = PLFS_SUCCESS;
    vector<plfs_pathback> exps;
    vector<plfs_pathback>::iterator itr;
    if ( (ret = generate_backpaths(ppip, exps)) != PLFS_SUCCESS ) {
        return(ret);
    }
    for(itr = exps.begin(); itr != exps.end() && ret == PLFS_SUCCESS; itr++ ) {
        ret = op.op(itr->bpath.c_str(),DT_DIR,itr->back->store);
        mlog(INT_DCOMMON, "%s on %s: %d",op.name(),itr->bpath.c_str(),ret);
    }
    return(ret);
}
Palette* load_palette(const char *filename)
{
  std::string ext = base::string_to_lower(base::get_file_extension(filename));
  Palette* pal = NULL;

  if (ext == "col") {
    pal = doc::file::load_col_file(filename);
  }
  else if (ext == "gpl") {
    pal = doc::file::load_gpl_file(filename);
  }
  else {
    FileFormat* ff = FileFormatsManager::instance()->getFileFormatByExtension(ext.c_str());
    if (ff->support(FILE_SUPPORT_LOAD)) {
      FileOp* fop = fop_to_load_document(NULL, filename,
        FILE_LOAD_SEQUENCE_NONE |
        FILE_LOAD_ONE_FRAME);
      if (fop && !fop->has_error()) {
        fop_operate(fop, NULL);
        fop_post_load(fop);

        if (fop->document &&
            fop->document->sprite() &&
            fop->document->sprite()->getPalette(FrameNumber(0))) {
          pal = new Palette(
            *fop->document->sprite()->getPalette(FrameNumber(0)));

          // TODO remove this line when support for palettes with less
          // than 256 colors is added.
          pal->resize(Palette::MaxColors);
        }

        delete fop->document;
        fop_done(fop);
      }
    }
  }

  if (pal)
    pal->setFilename(filename);

  return pal;
}
Beispiel #7
0
int main(int argc, char **argv)
{
    if(argc != MAX_PARAMETERS)
    {
        std::cout << "Invalid number of arguments \n";
        return FAILURE;
    }
    else
    {
        if(argv[1] == INVALID_FIE_NAME)
        {
            std::cout << "Invalid file name \n";
            return FAILURE;
        }

        /*Read equations from file and store each equation*/
        FileOp *fp = new FileOp(argv[1]);
        if(fp)
        {
            fp->getEqFromFile();

            int eqCount = (int)(fp->getEqCount());
            Parser *pp = new Parser();
            while(eqCount--)
            {
                int retVal;
                std::string eq = fp->getNextEq();
                /*Parse the equation and validate*/
                retVal = pp->parseEq(eq);
            }
            /*evaluate the equations and store the value*/
            pp->evalEq();
            /*Print the sorted out put of the list of variables used*/
            pp->printValues();
            delete pp;
            delete fp;
        }
    }

    return SUCCESS;
}
Beispiel #8
0
// this function is shared by chmod/utime/chown maybe others
// it's here for directories which may span multiple backends
// returns 0 or -err
int plfs_flatfile_operation(const char *logical, FileOp& op, IOStore *ios) {
    FLAT_ENTER;
    vector<plfs_pathback> dirs;
    mode_t mode = 0;
    ret = is_plfs_file(logical, &mode);
    //perform operation on ALL directories
    if (S_ISDIR(mode)){

        ret = find_all_expansions(logical, dirs);
        vector<plfs_pathback>::reverse_iterator ritr;
        for(ritr = dirs.rbegin(); ritr != dirs.rend() && ret == 0; ++ritr) {
            ret = op.op(ritr->bpath.c_str(),DT_DIR,ritr->back->store);
        }
    }
    //we hit a regular flat file
    else if(S_ISREG(mode)){
        ret = op.op(path.c_str(), DT_REG, ios);
    }
    //symlink
    else{
        ret = op.op(path.c_str(), DT_LNK, ios);
    }
    FLAT_EXIT(ret);
}
Beispiel #9
0
void NDMapData::decode(FILE* pkStream)
{
	FileOp kFileOp;

	//<-------------------地图名
	m_strName = kFileOp.readUTF8String(pkStream);//[self readUTF8String:stream];
	CCLog(m_strName.c_str());
	
	//<-------------------单元格尺寸
	int nUnitSize_DontUseIt = kFileOp.readByte(pkStream); //not used.
// 	int nTileWidth = m_nUnitSize;
// 	int nTileHeight = m_nUnitSize; //@del
	int nTileWidth = MAP_UNITSIZE_X;
	int nTileHeight = MAP_UNITSIZE_Y;

	//------------------->层数
	m_nLayerCount = kFileOp.readByte(pkStream);
	
	//<-------------------列数
	m_nColumns = kFileOp.readByte(pkStream);
	
	//------------------->行数
	m_nRows = kFileOp.readByte(pkStream);
	
	//<-------------------使用到的图块资源
	std::vector < std::string > kTileImages;
	int nTileImageCount = kFileOp.readShort(pkStream);

	for (int i = 0; i < nTileImageCount; i++)
	{
		int nIDx = kFileOp.readShort(pkStream);
		char pszImageName[256] =
		{ 0 };
		sprintf(pszImageName, "%st%d.png",
				NDEngine::NDPath::GetImagePath().c_str(), nIDx);
		FILE* pkFile = fopen(pszImageName, "rb");

		if (pkFile)
		{
			kTileImages.push_back(pszImageName);
		}
		else
		{
			return;
		}
	}

	//------------------->瓦片	
	m_kMapTiles = CCArray::array();
	m_kMapTiles->retain();
	for (int lay = 0; lay < m_nLayerCount; lay++)
	{
		for (unsigned int r = 0; r < m_nRows; r++)
		{
			for (unsigned int c = 0; c < m_nColumns; c++)
			{
				int nImageIndex = kFileOp.readByte(pkStream) - 1;	//资源下标

				if (nImageIndex == -1)
				{
					nImageIndex = 0;
				}

				int nTileIndex = kFileOp.readByte(pkStream);		//图块下标
				bool reverse = kFileOp.readByte(pkStream) == 1;	//翻转

				if (nImageIndex == -1)
				{
					nImageIndex = 0;
				}

				if (kTileImages.size() > nImageIndex)
				{
					std::string strImageName = kTileImages[nImageIndex];

					NDTile* pkTile = new NDTile;
					pkTile->setTexture(
							NDPicturePool::DefaultPool()->AddTexture(
									strImageName.c_str()));

					int nPicParts = pkTile->getTexture()->getPixelsWide()
							* pkTile->getTexture()->getMaxS() / nTileWidth;

					pkTile->setCutRect(
							CCRectMake(nTileWidth * (nTileIndex % nPicParts),
									nTileHeight * (nTileIndex / nPicParts),
									nTileWidth, nTileHeight));

					pkTile->setDrawRect(
							CCRectMake(nTileWidth * c, nTileHeight * r,
									nTileWidth, nTileHeight));

					pkTile->setReverse(reverse);
					m_kMapTiles->addObject(pkTile);
					pkTile->release();
				}
			}
		}
	}
	//<-------------------通行
	m_pkObstacles = new std::vector<bool>();
	for (unsigned int i = 0; i < m_nColumns * m_nRows; i++)
	{
		m_pkObstacles->push_back(true);
	}

	int nNotPassCount = kFileOp.readShort(pkStream);

	for (int i = 0; i < nNotPassCount; i++)
	{
		int nRowIndex = kFileOp.readByte(pkStream);
		int nColumnIndex = kFileOp.readByte(pkStream);

		int nIndex = nRowIndex * m_nColumns + nColumnIndex;

		if (m_pkObstacles->size() > nIndex)
		{
			(*m_pkObstacles)[nIndex] = false;	
		}
	}
	//------------------->切屏
	m_pkSwitchs = CCArray::array();
	m_pkSwitchs->retain();
	int nSwitchsCount = kFileOp.readByte(pkStream);

	for (int i = 0; i < nSwitchsCount; i++)
	{
		kFileOp.readByte(pkStream); //切屏点x
		kFileOp.readByte(pkStream); //切屏点y
		kFileOp.readByte(pkStream); //目标地图
		kFileOp.readByte(pkStream); //目标点
	}
	//<---------------------使用到的背景资源
	std::vector < std::string > kBackGroundImages;
	std::vector<int> _bgOrders;
	int bgImageCount = (kFileOp.readByte(pkStream) << 8)
			+ kFileOp.readByte(pkStream);

	for (int i = 0; i < bgImageCount; i++)
	{
		int idx = kFileOp.readShort(pkStream);
		char imageName[256] =
		{ 0 };
		sprintf(imageName, "%sb%d.png",
				NDEngine::NDPath::GetImagePath().c_str(), idx);
		FILE* pkFile = fopen(imageName, "rb");
		if (pkFile)
		{
			kBackGroundImages.push_back(imageName);
		}
		else
		{
			kBackGroundImages.push_back(imageName);
		}

		int v = kFileOp.readShort(pkStream);
		_bgOrders.push_back(v);
	}
	//---------------------->背景
	m_pkBackgroundTiles = CCArray::array();
	m_pkBackgroundTiles->retain();
	int bgCount = (kFileOp.readByte(pkStream) << 8)
			+ kFileOp.readByte(pkStream);

	for (int i = 0; i < bgCount; i++)
	{
		int nResourceIndex = kFileOp.readByte(pkStream);				//资源下标
		int nX = kFileOp.readShort(pkStream);	//x坐标
		int nY = kFileOp.readShort(pkStream);	//y坐标
		bool nReverse = kFileOp.readByte(pkStream) > 0;						//翻转

		if (kBackGroundImages.size() <= nResourceIndex
				|| _bgOrders.size() <= nResourceIndex)
		{
			continue;
		}

		std::string strImageName = kBackGroundImages[nResourceIndex];
		NDSceneTile* pkTile = new NDSceneTile;

		pkTile->setOrderID(_bgOrders[nResourceIndex] + nY);
		pkTile->setTexture(
				CCTextureCache::sharedTextureCache()->addImage(
						strImageName.c_str()));

		int picWidth = pkTile->getTexture()->getPixelsWide()
				* pkTile->getTexture()->getMaxS();

		int picHeight = pkTile->getTexture()->getPixelsHigh()
				* pkTile->getTexture()->getMaxT();


		pkTile->setMapSize(	CCSizeMake(m_nColumns * nTileWidth, m_nRows * nTileHeight));
		pkTile->SetCutRect_Android( CCRectMake(0, 0, picWidth, picHeight), getBattleMapFlag() || getDramaMapFlag()); //@android
		pkTile->SetDrawRect_Android(CCRectMake(nX, nY, picWidth, picHeight), getBattleMapFlag() || getDramaMapFlag()); //@android
		pkTile->setReverse(nReverse);
		pkTile->make();

		m_pkBackgroundTiles->addObject(pkTile);
		pkTile->release();
	}
	//<-------------------使用到的布景资源
	std::vector < std::string > kSceneImages;
	std::vector<int> kSceneOrders;
	int nSceneImageCount = (kFileOp.readByte(pkStream) << 8)
			+ kFileOp.readByte(pkStream);

	for (int i = 0; i < nSceneImageCount; i++)
	{
		int nIDx = kFileOp.readShort(pkStream);
		char szImageName[256] =
		{ 0 };
		sprintf(szImageName, "%ss%d.png",
				NDEngine::NDPath::GetImagePath().c_str(), nIDx);
		FILE* pkFile = fopen(szImageName, "rb");

		if (pkFile)
		{
			kSceneImages.push_back(szImageName);
		}
		else
		{
			//NDLog("布景资源%@没有找到!!!", imageName);
			kSceneImages.push_back(szImageName);
		}

		int v = static_cast<short>(kFileOp.readShort(pkStream));
		kSceneOrders.push_back(v);
	}
	//------------------->布景
	m_pkSceneTiles = CCArray::array();
	m_pkSceneTiles->retain();
	int nSceneCount = kFileOp.readShort(pkStream);

	for (int i = 0; i < nSceneCount; i++)
	{
		int nResourceIndex = kFileOp.readByte(pkStream);				//资源下标
		
		int x = (short) ((kFileOp.readByte(pkStream) << 8)
				+ kFileOp.readByte(pkStream));	//x坐标
		
		int y = (short) ((kFileOp.readByte(pkStream) << 8)
				+ kFileOp.readByte(pkStream));	//y坐标
		
		BOOL bReverse = kFileOp.readByte(pkStream) > 0;						//翻转

		if (kSceneImages.size() <= nResourceIndex
				|| kSceneOrders.size() <= nResourceIndex)
		{
			continue;
		}

		NDSceneTile* pkTile = new NDSceneTile;
		pkTile->setOrderID(kSceneOrders[nResourceIndex] + y);

		std::string strImagePath = kSceneImages[nResourceIndex];

		pkTile->setTexture(
				CCTextureCache::sharedTextureCache()->addImage(
						strImagePath.c_str()));

		int nPicWidth = pkTile->getTexture()->getPixelsWide()
				* pkTile->getTexture()->getMaxS();

		int nPicHeight = pkTile->getTexture()->getPixelsHigh()
				* pkTile->getTexture()->getMaxT();

		pkTile->setMapSize( CCSizeMake(m_nColumns * nTileWidth, m_nRows * nTileHeight));
		pkTile->SetCutRect_Android( CCRectMake(0, 0, nPicWidth, nPicHeight), getBattleMapFlag() || getDramaMapFlag()); //@android
		pkTile->SetDrawRect_Android( CCRectMake(x, y, nPicWidth, nPicHeight), getBattleMapFlag() || getDramaMapFlag()); //@android
		pkTile->setReverse(bReverse);
		pkTile->make();

		m_pkSceneTiles->addObject(pkTile);
		pkTile->release();
	}
	//<-------------------动画
	m_pkAnimationGroups = CCArray::array();
	m_pkAnimationGroups->retain();
	m_pkAniGroupParams = CCArray::array();
	m_pkAniGroupParams->retain();
	int m_AniGroupCount = kFileOp.readShort(pkStream);

	for (int i = 0; i < m_AniGroupCount; i++)
	{
		int nIdentifer = kFileOp.readShort(pkStream);			//动画id
		NDAnimationGroup *pkAniGroup =
				NDAnimationGroupPool::defaultPool()->addObjectWithSceneAnimationId(
						nIdentifer);
		if (!pkAniGroup)
		{
			continue;
		}

		m_pkAnimationGroups->addObject(pkAniGroup);
		pkAniGroup->release();

		int x = kFileOp.readShort(pkStream);		//x坐标
		int y = kFileOp.readShort(pkStream);		//y坐标
		int nAniOrder = y + kFileOp.readShort(pkStream);	//排序重心

		anigroup_param* pkDict = new anigroup_param;

		pkDict->insert(std::make_pair("reverse", 0));
		pkDict->insert(std::make_pair("positionX", x));
		pkDict->insert(std::make_pair("positionY", y));
		pkDict->insert(std::make_pair("mapSizeW", m_nColumns * MAP_UNITSIZE_X));
		pkDict->insert(std::make_pair("mapSizeH", m_nRows * MAP_UNITSIZE_Y));
		pkDict->insert(std::make_pair("orderId", nAniOrder));
		pkDict->insert(std::make_pair("reverse", 0));
		pkDict->insert(std::make_pair("reverse", 0));

		m_pkAniGroupParams->addObject(pkDict);
		pkDict->release();
	}
	//------------------->刷怪区
// 	NSMutableArray	*_monsterRanges = [[NSMutableArray alloc] init];
// 	int monsterRangeCount = [stream readByte];
// 	for (int i = 0; i < monsterRangeCount; i++) 
// 	{
// 		NDMapMonsterRange *monsterRange = [[NDMapMonsterRange alloc] init];
// 		
// 		monsterRange.typeId = [stream readInt];
// 		monsterRange.column = [stream readByte];
// 		monsterRange.row = [stream readByte];
// 		monsterRange.boss = [stream readByte] != 0;
// 		
// 		[_monsterRanges addObject:monsterRange];
// 		[monsterRange release];
// 	}
// 	
// 	[_tileImages release];
// 	[_sceneImages release];
// 	[_sceneOrders release];
// 	[_monsterRanges release];
// 	[_bgImages release];
// 	[_bgOrders release];
}
Beispiel #10
0
/**
 * plfs_file_operation: this function is shared by
 * chmod/utime/chown/etc.  anything that needs to operate on possibly
 * a lot of items either on a bunch of dirs across the backends or on
 * a bunch of entries within a container Be careful.  This performs a
 * stat.  Do not use for performance critical operations.  If needed,
 * then you'll have to figure out how to cheaply pass the mode_t in
 *
 * @param ppip the phyiscal path we are working with
 * @param op the FileOp operation we are going to perform
 * @return PLFS_SUCCESS or PLFS_E*
 */
static plfs_error_t
plfs_file_operation(struct plfs_physpathinfo *ppip, FileOp& op)
{
    plfs_error_t ret = PLFS_SUCCESS;
    vector<plfs_pathback> files, dirs, links;
    string accessfile;
    struct plfs_pathback pb;

    // first go through and find the set of physical files and dirs
    // that need to be operated on
    // if it's a PLFS file, then maybe we just operate on
    // the access file, or maybe on all subentries
    // if it's a directory, then we operate on all backend copies
    // else just operate on whatever it is (ENOENT, symlink)
    mode_t mode = 0;
    ret = (is_container_file(ppip,&mode) == false) ? PLFS_SUCCESS : PLFS_TBD;
    bool is_container = false; // differentiate btwn logical dir and container

    if (S_ISREG(mode)) { // it's a PLFS file
        if (op.onlyAccessFile()) {
            pb.bpath = Container::getAccessFilePath(ppip->canbpath);
            pb.back = ppip->canback;
            files.push_back(pb);
            ret = PLFS_SUCCESS;    // ret was one from is_container_file
        } else {
            // everything
            is_container = true;
            accessfile = Container::getAccessFilePath(ppip->canbpath);
            ret = plfs_collect_from_containers(ppip,files,dirs,links);
        }
    } else if (S_ISDIR(mode)) { // need to iterate across dirs
        ret = generate_backpaths(ppip, dirs);
    } else {
        // ENOENT, a symlink, somehow a flat file in here
        pb.bpath = ppip->canbpath;
        pb.back = ppip->canback;
        files.push_back(pb);  // we might want to reset ret to 0 here
    }
    // now apply the operation to each operand so long as ret==0.  dirs must be
    // done in reverse order and files must be done first.  This is necessary
    // for when op is unlink since children must be unlinked first.  for the
    // other ops, order doesn't matter.
    vector<plfs_pathback>::reverse_iterator ritr;
    for(ritr = files.rbegin(); ritr != files.rend() && ret == PLFS_SUCCESS; ++ritr) {
        // In container mode, we want to special treat accessfile deletion,
        // because once accessfile deleted, the top directory will no longer
        // be viewed as a container. Defer accessfile deletion until last moment
        // so that if anything fails in the middle, the container information
        // remains.
        if (is_container && accessfile == ritr->bpath) {
            mlog(INT_DCOMMON, "%s skipping accessfile %s",
                              __FUNCTION__, ritr->bpath.c_str());
            continue;
        }
        mlog(INT_DCOMMON, "%s on %s",__FUNCTION__,ritr->bpath.c_str());
        ret = op.op(ritr->bpath.c_str(),DT_REG,ritr->back->store); 
    }
    for(ritr = links.rbegin(); ritr != links.rend() && ret == PLFS_SUCCESS; ++ritr) {
        op.op(ritr->bpath.c_str(),DT_LNK,ritr->back->store);
    }
    for(ritr = dirs.rbegin(); ritr != dirs.rend() && ret == PLFS_SUCCESS; ++ritr) {
        if (is_container && ritr->bpath == ppip->canbpath) {
            mlog(INT_DCOMMON, "%s skipping canonical top directory%s",
                              __FUNCTION__, ppip->canbpath.c_str());
            continue;
        }
        ret = op.op(ritr->bpath.c_str(),
                    is_container?(unsigned char)DT_CONTAINER:(unsigned char)DT_DIR,
                    ritr->back->store);
    }
    if (is_container) {
        mlog(INT_DCOMMON, "%s processing access file and canonical top dir",
                          __FUNCTION__);
        ret = op.op(accessfile.c_str(), DT_REG, ppip->canback->store);
        if (ret == PLFS_SUCCESS)
            ret = op.op(ppip->canbpath.c_str(), DT_CONTAINER,
                        ppip->canback->store);
    }
    mlog(INT_DAPI, "%s: ret %d", __FUNCTION__,ret);
    return(ret);
}