Exemple #1
0
//----------------------------------------------------------------//
bool ZLFileSys::Copy ( cc8* path, cc8* newPath ) {

	zl_stat fileStat;

	if ( !ZLFileSys::GetFileStat ( path, fileStat )) return false;
	if ( !fileStat.mExists ) return false;

	if ( fileStat.mIsDir ) {
		
		bool result = true;
		
		STLString cwd = ZLFileSys::GetCurrentPath ();
		STLString toPath = ZLFileSys::GetAbsoluteDirPath ( newPath );
		
		ZLFileSys::AffirmPath ( toPath );
		
		ZLFileSys::SetCurrentPath ( path );
		
		ZLDIR* itr = zl_dir_open ();
		if ( itr ) {
			while ( zl_dir_read_entry ( itr )) {
				cc8* entry = zl_dir_entry_name ( itr );
				if ( strcmp ( entry, "." ) == 0 ) continue;
				if ( strcmp ( entry, ".." ) == 0 ) continue;
				
				STLString destEntry = toPath;
				destEntry.append ( entry );
				
				if ( !ZLFileSys::Copy ( entry, destEntry )) {
					result = false;
					break;
				}
			}
			zl_dir_close ( itr );
		}
		ZLFileSys::SetCurrentPath ( cwd );
		
		return result;
	}
	else {
		ZLFileStream infile;
		if ( infile.OpenRead ( path )) {
		
			ZLFileStream outfile;
			if ( outfile.OpenWrite ( newPath )) {
				outfile.WriteStream ( infile );
				return true;
			}
		}
	}
	
	return false;
}
//----------------------------------------------------------------//
bool MOAIDataBuffer::Save ( cc8* filename ) {

	ZLFileStream out;

	if ( !out.OpenWrite ( filename )) return false;

	this->mMutex.Lock ();
	out.WriteBytes ( this->mBytes , this->mBytes.Size ());
	this->mMutex.Unlock ();

	return true;
}
//----------------------------------------------------------------//
void _write_png ( MOAIImage& image, cc8* filename ) {

	ZLFileStream out;
	out.OpenWrite ( filename );
	image.WritePNG ( out );
}