コード例 #1
0
ファイル: Curl.cpp プロジェクト: bgbotond/Cinder-Curl
bool Curl::ftpUpload( const std::string &ftpUrl, const std::string &userName, const std::string &password, const ci::fs::path &path )
{
	bool ret = true;
	CURL *curl = curl_easy_init();
	CURLcode  res;

	if( ! curl )
		return false;

	FILE        *fileSource;
	curl_off_t   fileSize;
	std::string  fileName = path.filename().string();
	std::string  tempName = fileName + ".uploading";
	std::string  renameFromCommand = "RNFR " + tempName;
	std::string  renameToCommand   = "RNTO " + fileName;
	std::string  urlFullPath   = ftpUrl + "/" + tempName;
	std::string  userPass = userName + ":" + password;

	struct curl_slist *headerList = NULL;

	if( ! ci::fs::exists( path ))
	{
		cerr << "error: " << "Couldn't open file: " << path << endl;
		curl_easy_cleanup( curl );
		curl_global_cleanup();
		return false;
	}

	fileSize = (curl_off_t)ci::fs::file_size( path );

	fileSource = fopen( path.string().c_str(), "rb" ); // get a FILE * of the same file

	curl_global_init( CURL_GLOBAL_ALL ); // In windows, this will init the winsock stuff

	// build a list of commands to pass to libcurl
	headerList = curl_slist_append( headerList, renameFromCommand.c_str());
	headerList = curl_slist_append( headerList, renameToCommand.c_str());

	curl_easy_setopt( curl, CURLOPT_UPLOAD          , 1L                        ); // enable uploading
	curl_easy_setopt( curl, CURLOPT_URL             , urlFullPath.c_str()       ); // specify target
	curl_easy_setopt( curl, CURLOPT_USERPWD         , userPass.c_str()          ); // specify user/password
	curl_easy_setopt( curl, CURLOPT_POSTQUOTE       , headerList                ); // pass in that last of FTP commands to run after the transfer
	curl_easy_setopt( curl, CURLOPT_READDATA        , fileSource                ); // now specify which file to upload
	curl_easy_setopt( curl, CURLOPT_INFILESIZE_LARGE, fileSize                  ); // Set the size of the file to upload (optional).  If you give a *_LARGE option you MUST make sure that the type of the passed-in argument is a curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must make sure that to pass in a type 'long' argument

	res = curl_easy_perform( curl );

	if( res != CURLE_OK )
	{
		cerr << "error: " << curl_easy_strerror( res ) << endl;
		ret = false;
	}

	curl_slist_free_all( headerList ); // clean up the FTP commands list
	curl_easy_cleanup( curl );
	fclose( fileSource );
	curl_global_cleanup();

	return ret;
}
コード例 #2
0
string AudioDevice::registerSound(ci::fs::path pathToSound, bool looping, bool is3d, bool asStream)
{
    if ( !boost::filesystem::exists( pathToSound ) ) {
        app::console() << "[NOTICE] " << pathToSound << " doesn't exist" << endl;
        return "";
    }

    std::stringstream namestream;
    namestream << deviceName << "-" << pathToSound.filename().string() << "-" << mSounds.size();
    string name = namestream.str();

    app::console() << "Adding " << name << endl;

    if(mSounds.find(name)!=mSounds.end()) {
        app::console() << "[WARNING] " << name << " already exists on this device. Re-adding." << endl;
    }

    if( asStream ) {
        FMODErrorCheck( mSystem->createStream( pathToSound.string().c_str(), FMOD_DEFAULT, NULL, &mSounds[name]) );
    } else {
        FMODErrorCheck( mSystem->createSound( pathToSound.string().c_str(), FMOD_DEFAULT, NULL, &mSounds[name]) );
    }

    FMOD_MODE mode;
    mode = is3d ? FMOD_3D|FMOD_3D_LINEARSQUAREROLLOFF : FMOD_2D;
    mode |= looping ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF;
    FMODErrorCheck( mSounds.at(name)->setMode( mode ) );

    return name;
}