Exemplo n.º 1
0
bool CrashHandlerImpl::addAttachedFile(const fs::path & file) {
	
	if(file.is_relative()) {
		fs::path absolute = fs::current_path() / file;
		if(absolute.is_relative()) {
			return false;
		}
		return addAttachedFile(absolute);
	}
	
	Autolock autoLock(&m_Lock);

	if(m_pCrashInfo->nbFilesAttached == CrashInfo::MaxNbFiles) {
		LogError << "Too much files already attached to the crash report (" << m_pCrashInfo->nbFilesAttached << ").";
		return false;
	}

	if(file.string().size() >= CrashInfo::MaxFilenameLen) {
		LogError << "File name is too long.";
		return false;
	}

	for(u32 i = 0; i < m_pCrashInfo->nbFilesAttached; i++) {
		if(strcmp(m_pCrashInfo->attachedFiles[i], file.string().c_str()) == 0) {
			LogWarning << "File \"" << file << "\" is already attached.";
			return false;
		}
	}
	
	util::storeStringTerminated(m_pCrashInfo->attachedFiles[m_pCrashInfo->nbFilesAttached], file.string());
	m_pCrashInfo->nbFilesAttached++;

	return true;
}
bool CrashHandlerImpl::addAttachedFile(const fs::path& file) {
	Autolock autoLock(&m_Lock);

	if(m_pCrashInfo->nbFilesAttached == CrashInfo::MaxNbFiles) {
		LogError << "Too much files already attached to the crash report (" << m_pCrashInfo->nbFilesAttached << ").";
		return false;
	}

	if(file.string().size() >= CrashInfo::MaxFilenameLen) {
		LogError << "File name is too long.";
		return false;
	}

	for(int i = 0; i < m_pCrashInfo->nbFilesAttached; i++) {
		if(strcmp(m_pCrashInfo->attachedFiles[i], file.string().c_str()) == 0) {
			LogWarning << "File \"" << file << "\" is already attached.";
			return false;
		}
	}

	strcpy(m_pCrashInfo->attachedFiles[m_pCrashInfo->nbFilesAttached], file.string().c_str());
	m_pCrashInfo->nbFilesAttached++;

	return true;
}
Exemplo n.º 3
0
Cursor::Cursor(fs::path imgPath, float hotSpotX, float hotSpotY) {
	sf::Image gif;
	if(!gif.loadFromFile(imgPath.string())) {
		std::string error = "Error loading cursor from " + imgPath.string();
		throw error;
	}
	// Calculate the AND and XOR masks
	HBITMAP cursorAnd = CreateCompatibleBitmap(GetDC(NULL), gif.getSize().x, gif.getSize().y);
	HBITMAP cursorXor = CreateCompatibleBitmap(GetDC(NULL), gif.getSize().x, gif.getSize().y);
	GetMaskBitmaps(gif, cursorAnd, cursorXor);

	ICONINFO iconinfo = {0};
	iconinfo.fIcon = FALSE;
	iconinfo.xHotspot = hotSpotX;
	iconinfo.yHotspot = hotSpotY;
	iconinfo.hbmMask = cursorAnd;
	iconinfo.hbmColor = cursorXor;

	HCURSOR hCursor = CreateIconIndirect(&iconinfo);
	if(hCursor == NULL) {
		std::string error = "Error creating cursor from " + imgPath.string();
		error += " (error code " + std::to_string(GetLastError()) + ")";
		throw error;
	}
	ptr = hCursor;
	DeleteObject(cursorAnd);
	DeleteObject(cursorXor);
}
void
FileSystemTestSetup::setup_clustercache_device(const fs::path& device,
        uint64_t size) const
{
    int fd = ::open(device.string().c_str(),
                    O_RDWR| O_CREAT | O_EXCL,
                    S_IWUSR | S_IRUSR);
    if(fd < 0)
    {
        LOG_ERROR("Couldn't open file " << device << ", " << strerror(errno));
        throw fungi::IOException("Couldn't open file", device.string().c_str());
    }

    BOOST_SCOPE_EXIT((fd))
    {
        ::close(fd);
    }
    BOOST_SCOPE_EXIT_END;

    int ret = ::posix_fallocate(fd, 0, size);
    if (ret != 0)
    {
        LOG_ERROR("Could not allocate file " << device << " with size " << size << ", " << strerror(ret));
        throw fungi::IOException("Could not allocate file",
                                 device.string().c_str(),
                                 ret);
    }

    ::fchmod(fd, 00600);
}
Exemplo n.º 5
0
bool CMissionManager::DoCopyFile(const fs::path& source, const fs::path& dest, bool overwrite)
{
	if (overwrite)
	{
		try
		{
			// According to docs, remove() doesn't throw if file doesn't exist
			fs::remove(dest);
			DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Destination file %s already exists, has been removed before copying.\r", dest.string().c_str());
		}
		catch (fs::filesystem_error& e)
		{
			// Don't care about removal error
			DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("Caught exception while removing destination file %s: %s\r", dest.string().c_str(), e.what());
		}
	}

	// Copy the source file to the destination
	try
	{
		fs::copy_file(source, dest);
		DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("File successfully copied to %s.\r", dest.string().c_str());

		return true;
	}
	catch (fs::filesystem_error& e)
	{
		DM_LOG(LC_MAINMENU, LT_ERROR)LOGSTRING("Exception while coyping file from %s to %s: %s\r", 
			source.string().c_str(), dest.string().c_str(), e.what());

		return false;
	}
}
/*******************************************************************
 * Function Name: Save
 * Return Type 	: int
 * Created On	: Nov 10, 2013
 * Created By 	: hrushi
 * Comments		: Save SVM
 * Arguments	: const fs::path fs
 *******************************************************************/
int SVMLearning::Save( const fs::path fs) const
{
	cout << "Writing to: " << fs.string() << endl;

	m_SVM.save(fs.string().c_str());

	return EXIT_SUCCESS;
}
void GstVideoServer::load( const fs::path& path )
{
	CI_LOG_I("Load file: " << path.string()  );
	GstPlayer::load(path.string());
	mCurrentFileName = path.filename().string();
    ///> Now that we have loaded we can grab the pipeline..
    mGstPipeline = GstPlayer::getPipeline();
	setupNetworkClock();
    
}
Exemplo n.º 8
0
int remove_hjtremove(fs::path  path, void* data)
{
	if (strstr(path.string().c_str(),".hjtremove") ||
		strstr(path.string().c_str(),".tmp")){
		boost::system::error_code ec;
		fs::remove(path, ec);
		return ec.value();
	}
	return 0;
}
Exemplo n.º 9
0
bool RenameOver(fs::path src, fs::path dest)
{
#ifdef WIN32
    return MoveFileExA(src.string().c_str(), dest.string().c_str(),
                       MOVEFILE_REPLACE_EXISTING) != 0;
#else
    int rc = std::rename(src.string().c_str(), dest.string().c_str());
    return (rc == 0);
#endif /* WIN32 */
}
Exemplo n.º 10
0
bool MDeepFileIteratorImp::Next(
	fs::path&		outFile)
{
	bool result = false;
	
	while (not result and not mStack.empty())
	{
		struct dirent* e = nil;
		
		MInfo& top = mStack.top();
		
		if (top.mDIR != nil)
			THROW_IF_POSIX_ERROR(::readdir_r(top.mDIR, &top.mEntry, &e));
		
		if (e == nil)
		{
			if (top.mDIR != nil)
				closedir(top.mDIR);
			mStack.pop();
		}
		else
		{
			outFile = top.mParent / e->d_name;
			
			struct stat st;
			if (stat(outFile.string().c_str(), &st) < 0 or S_ISLNK(st.st_mode))
				continue;
			
			if (S_ISDIR(st.st_mode))
			{
				if (strcmp(e->d_name, ".") and strcmp(e->d_name, ".."))
				{
					MInfo info;
	
					info.mParent = outFile;
					info.mDIR = opendir(outFile.string().c_str());
					memset(&info.mEntry, 0, sizeof(info.mEntry));
					
					mStack.push(info);
				}
				continue;
			}

			if (mOnlyTEXT and not IsTEXT(outFile))
				continue;

			if (mFilter.length() and not FileNameMatches(mFilter.c_str(), outFile))
				continue;

			result = true;
		}
	}
	
	return result;
}
Exemplo n.º 11
0
TEST_F(FileUtilsTest, copy)
{
    std::string content("content");

    const fs::path a = FileUtils::create_temp_file_in_temp_dir();
    {
        std::ofstream ofs(a.string().c_str());
        ofs << content;
        ofs.close();
    }

    const size_t size = fs::file_size(a);


    const fs::path b = FileUtils::create_temp_file_in_temp_dir("b");
    ASSERT_NO_THROW(fs::remove(b));
    ASSERT_FALSE(fs::exists(b));

    EXPECT_NO_THROW(FileUtils::safe_copy(a, b));
    EXPECT_TRUE(fs::exists(b));
    EXPECT_EQ(size, fs::file_size(b));


    std::string read;
    {
        std::ifstream ifs(b.string().c_str());
        ifs >> read;
        ifs.close();
    }

    EXPECT_EQ(content, read);

    // copy to a larger, existing file
    read = "";
    {
        std::ofstream ofs(a.string().c_str());
        ofs << content << content << content;
        ofs.close();
    }

    EXPECT_LT(size, fs::file_size(a));

    EXPECT_NO_THROW(FileUtils::safe_copy(b, a));

    EXPECT_EQ(size, fs::file_size(a));

    {
        std::ifstream ifs(a.string().c_str());
        ifs >> read;
        ifs.close();
    }

    EXPECT_EQ(content, read);
}
bool CrashHandlerImpl::setReportLocation(const fs::path& location) {
	Autolock autoLock(&m_Lock);

	if(location.string().size() >= CrashInfo::MaxFilenameLen) {
		LogError << "Report location path is too long.";
		return false;
	}

	strcpy(m_pCrashInfo->crashReportFolder, location.string().c_str());

	return true;
}
Exemplo n.º 13
0
static void test_parent(const fs::path & in, const std::string & out) {
	
	fs::path p = in.parent();
	arx_assert_msg(p.string() == out, "\"%s\".parent() -> \"%s\" != \"%s\"",
	               in.string().c_str(), p.string().c_str(), out.c_str());
	
	fs::path temp = in;
	temp.up();
	arx_assert_msg(temp.string() == out, "\"%s\".up() ->\"%s\" != \"%s\"",
	               in.string().c_str(), temp.string().c_str(), out.c_str());
	
}
Exemplo n.º 14
0
bool FileService::deleteFile(const fs::path& file)
{
  try
  {
    os_chmod(file.string().c_str(), S_IRUSR|S_IWUSR);
    return fs::remove(file);
  }
  catch (const std::exception ex)
  {
    std::cout << "ERROR: delete file " << file.string() << "; exception: " << ex.what() << std::endl;
    return false;
  }
}
Exemplo n.º 15
0
void ControleaseApp::loadCanvasFromFile(fs::path file)
{
    console() << "loading patch from: " << file.string() << endl;
    
    if (!exists(file)) {
        console() << "error: cannot find '"<<file.string()<<"'"<<endl;
        return;
    }
    
    // get size of file
    XmlTree xml(loadFile(file));
    
    canvas->initFromXml(xml.getChild("Canvas"));
}
Exemplo n.º 16
0
static void test_resolve(const fs::path & left, const fs::path & right, const std::string & out) {
	
	fs::path result = left / right;
	arx_assert_msg(result.string() == out, "\"%s\" / \"%s\" -> \"%s\" != \"%s\"", 
	               left.string().c_str(), right.string().c_str(), result.string().c_str(),
	               out.c_str());
	
	fs::path temp = left;
	temp /= right;
	
	arx_assert_msg(temp.string() == out, "\"%s\" /= \"%s\" -> \"%s\" != \"%s\"",
	               left.string().c_str(), right.string().c_str(), temp.string().c_str(),
	               out.c_str());
}
Exemplo n.º 17
0
bool copyFile(const fs::path& from, const fs::path& to) {
	std::ifstream in(from.string().c_str(), std::ios::binary);
	if (!in)
		return false;
	std::ofstream out(to.string().c_str(), std::ios::binary);
	if (!out)
		return false;

	out << in.rdbuf();
	if (out.bad())
		return false;
	in.close();
	out.close();
	return true;
}
Exemplo n.º 18
0
bool FileService::copyFile(const fs::path& source, const fs::path& destination)
{
  try
  {
    if (fs::exists(destination))
      os_chmod(destination.string().c_str(), S_IRUSR|S_IWUSR);
    fs::copy_file(source, destination, fs::copy_option::overwrite_if_exists);
    return true;
  }
  catch (const std::exception ex)
  {
    std::cout << "ERROR: copy file " << source.string() << " to " << destination.string() << "; exception: " << ex.what() << std::endl;
    return false;
  }
}
Exemplo n.º 19
0
// calls must be locked by write-lock
void StylesheetManager::onNewStylesheet(const fs::path& stylesheet_path)
{
	// lock the weak_ptr to manager
	shared_ptr<RequestManager> manager = this->manager.lock();
	assert(manager);

	shared_ptr<Stylesheet> stylesheet;
	int timeout = config->get<int>(opt::server::parse_timeout);

	try {
		std::string new_filename = stylesheet_path.filename().string() + ".mapcss";
		fs::path filename(new_filename);
		stylesheet = Stylesheet::Load(stylesheetFolder / filename, manager->getGeodata(), timeout);

	} catch(excp::ParseException& e)
	{
		shared_ptr<ParserLogger> logger = *boost::get_error_info<excp::InfoParserLogger>(e);

		// Something went wrong!
		logger->errorStream() << "Parsing of file \"" << excp::ErrorOut<excp::InfoFileName>(e, stylesheet_path.string()) << "\" failed:";
		logger->errorStream() << excp::ErrorOut<excp::InfoWhat>(e, "unknown reason!");
		logger->errorStream() << "In line " << excp::ErrorOut<excp::InfoFailureLine>(e) << " column " << excp::ErrorOut<excp::InfoFailureColumn>(e) << ":";

		const string* errLine = boost::get_error_info<excp::InfoFailureLineContent>(e);
		const int* errColumn = boost::get_error_info<excp::InfoFailureColumn>(e);

		if(errLine)
			logger->errorStream() << "'" << *errLine << "'";

		if(errColumn)
			logger->errorStream() << string(*errColumn, ' ') << "^-here";

		return;
	} catch(excp::TimeoutException&)
	{
		shared_ptr<ParserLogger> logger = boost::make_shared<ParserLogger>(stylesheet_path.string());

		logger->errorStream() << "Parsing of stylesheet " << stylesheet_path << " took more then " << timeout << " ms!";
		logger->errorStream() << "Parsing canceled!";
		logger->errorStream() << "You can configure the timeout via '--parse-timeout'.";
		return;
	}

	parsedStylesheets[stylesheet_path] = stylesheet;

	// prerenders the upmost tile as well as all higher zoomlevels that are specified in the configuration
	manager->enqueue(boost::make_shared<MetaIdentifier>(TileIdentifier(0, 0, 0, stylesheet_path.string(), TileIdentifier::PNG)));
}
Exemplo n.º 20
0
bool ChooseDirectory(
	fs::path&	outDirectory)
{
	GtkWidget* dialog = nil;
	bool result = false;

	try
	{
		dialog = 
			gtk_file_chooser_dialog_new(_("Select Folder"), nil,
				GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				NULL);
		
		THROW_IF_NIL(dialog);
	
		string currentFolder = gApp->GetCurrentFolder();
	
		if (currentFolder.length() > 0)
		{
			gtk_file_chooser_set_current_folder_uri(
				GTK_FILE_CHOOSER(dialog), currentFolder.c_str());
		}
		
		if (fs::exists(outDirectory) and outDirectory != fs::path())
		{
			gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog),
				outDirectory.string().c_str());
		}
		
		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
		{
			char* uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
			if (uri != nil)
			{
				MFile url(uri, true);
				outDirectory = url.GetPath();
	
				g_free(uri);
	
				result = true;
			}
//
//			gApp->SetCurrentFolder(
//				gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER(dialog)));
		}
	}
	catch (exception& e)
	{
		if (dialog)
			gtk_widget_destroy(dialog);
		
		throw;
	}
	
	gtk_widget_destroy(dialog);

	return result;
}
Exemplo n.º 21
0
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only)
{
    std::lock_guard<std::mutex> ulock(cs_dir_locks);
    fs::path pathLockFile = directory / lockfile_name;

    // If a lock for this directory already exists in the map, don't try to re-lock it
    if (dir_locks.count(pathLockFile.string())) {
        return true;
    }

    // Create empty lock file if it doesn't exist.
    FILE* file = fsbridge::fopen(pathLockFile, "a");
    if (file) fclose(file);

    try {
        auto lock = MakeUnique<boost::interprocess::file_lock>(pathLockFile.string().c_str());
        if (!lock->try_lock()) {
            return false;
        }
        if (!probe_only) {
            // Lock successful and we're not just probing, put it into the map
            dir_locks.emplace(pathLockFile.string(), std::move(lock));
        }
    } catch (const boost::interprocess::interprocess_exception& e) {
        return error("Error while attempting to lock directory %s: %s", directory.string(), e.what());
    }
    return true;
}
Exemplo n.º 22
0
std::vector<fs::path> ListWalletDir()
{
    const fs::path wallet_dir = GetWalletDir();
    const size_t offset = wallet_dir.string().size() + 1;
    std::vector<fs::path> paths;

    for (auto it = fs::recursive_directory_iterator(wallet_dir); it != fs::recursive_directory_iterator(); ++it) {
        // Get wallet path relative to walletdir by removing walletdir from the wallet path.
        // This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
        const fs::path path = it->path().string().substr(offset);

        if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet.dat")) {
            // Found a directory which contains wallet.dat btree file, add it as a wallet.
            paths.emplace_back(path);
        } else if (it.level() == 0 && it->symlink_status().type() == fs::regular_file && IsBerkeleyBtree(it->path())) {
            if (it->path().filename() == "wallet.dat") {
                // Found top-level wallet.dat btree file, add top level directory ""
                // as a wallet.
                paths.emplace_back();
            } else {
                // Found top-level btree file not called wallet.dat. Current bitcoin
                // software will never create these files but will allow them to be
                // opened in a shared database environment for backwards compatibility.
                // Add it to the list of available wallets.
                paths.emplace_back(path);
            }
        }
    }

    return paths;
}
Exemplo n.º 23
0
void QuickTimeSampleApp::loadMovieFile( const fs::path& moviePath )
{
	try {
		// load up the movie, set it to loop, and begin playing
		mMovie = qtime::MovieGl( moviePath );
		mMovie.setLoop();
		mMovie.play();
		
		// create a texture for showing some info about the movie
		TextLayout infoText;
		infoText.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.5f ) );
		infoText.setColor( Color::white() );
		infoText.addCenteredLine( getPathFileName( moviePath.string() ) );
		infoText.addLine( toString( mMovie.getWidth() ) + " x " + toString( mMovie.getHeight() ) + " pixels" );
		infoText.addLine( toString( mMovie.getDuration() ) + " seconds" );
		infoText.addLine( toString( mMovie.getNumFrames() ) + " frames" );
		infoText.addLine( toString( mMovie.getFramerate() ) + " fps" );
		infoText.setBorder( 4, 2 );
		mInfoTexture = gl::Texture( infoText.render( true ) );
	}
	catch( ... ) {
		console() << "Unable to load the movie." << std::endl;
		mMovie.reset();
		mInfoTexture.reset();
	}

	mFrameTexture.reset();
}
Exemplo n.º 24
0
imageHasher::db::table::ImageRecord Database::get_imagerecord(fs::path filepath) {
	ImageRecord ir;

	try {
		transaction t(orm_db->begin());

		std::string *p;

		LOG4CPLUS_DEBUG(logger, "Getting imagerecord for path " << filepath);
		odb::prepared_query<ImageRecord> pq = this->prep_query->get_imagerecord_path_query(p);

		*p = filepath.string();

		result<ImageRecord> r(pq.execute());

		for (result<ImageRecord>::iterator itr(r.begin()); itr != r.end(); ++itr) {
			ir = *itr;
			break;
		}

		t.commit();
	} catch (odb::exception *e) {
		LOG4CPLUS_ERROR(logger, "Failed to get ImageRecord for path " << filepath << " : " << e);
	}

	return ir;
}
Exemplo n.º 25
0
std::list<fs::path> Database::getFilesWithPath(fs::path directoryPath) {
	std::list<fs::path> filePaths;
	std::string path_query(directoryPath.string());
	path_query += "%";

	LOG4CPLUS_INFO(logger, "Looking for files with path " << directoryPath);

	transaction t (orm_db->begin());
	std::string *param;

	odb::prepared_query<ImageRecord> pq = prep_query->get_files_with_path_query(param);

	*param = path_query;

	odb::result<ImageRecord> r(pq.execute());

	for(result<ImageRecord>::iterator itr (r.begin()); itr != r.end(); ++itr) {
		filePaths.push_back(fs::path(itr->getPath()));
	}

	t.commit();

	LOG4CPLUS_INFO(logger, "Found  " << filePaths.size() << " records for path " << directoryPath);
	return filePaths;
}
Exemplo n.º 26
0
Arquivo: cApp.cpp Projeto: stdmtb/n9
/*
       csv file format
       L1:x1, L1:laserOnoff, L2:x1, L2:laserOnoff, ..., R5:x1, R1:laserOnoff
       each line number = frame number (25fps)
 */
void cApp::loadCsv( fs::path path, vector<vector<float>> & array, bool print ){

    ifstream file ( path.string() );
    if( !file.is_open() ){
        cout << "cant open file" << endl;
    }else{
        std::string line;
        while ( std::getline( file, line ) ){
            
            std::istringstream iss{ line };
            std::vector<float> tokens;
            std::string cell;
            while( std::getline(iss, cell, ',') ){
                cell.erase( std::remove(cell.begin(), cell.end(), '\r'), cell.end() );  // erase \r
                float cell_f = fromString<float>(cell);
                tokens.push_back( cell_f );
            }
            
            array.push_back( tokens );
        }
    }
    
    if( print ){
        for (auto & line : array){
            for (auto & val : line){
                printf( "%f ", val);
            }
            printf("\n");
        }
    }
}
Exemplo n.º 27
0
fs::path AppImplMsw::getFolderPath( const fs::path &initialPath )
{
	wstring initialPathWide( toUtf16( initialPath.string() ) );
	string result;

	::BROWSEINFO bi = { 0 };
	bi.lParam = reinterpret_cast<LPARAM>( initialPathWide.c_str() );
	bi.lpfn = getFolderPathBrowseCallbackProc;
	bi.lpszTitle = L"Pick a Directory";
	::LPITEMIDLIST pidl = ::SHBrowseForFolder( &bi );
	if( pidl ) {
		// get the name of the folder
		TCHAR path[MAX_PATH];
		if( ::SHGetPathFromIDList ( pidl, path ) ) {
			result = toUtf8( path );
		}

		// free memory used
		::IMalloc * imalloc = 0;
		if( SUCCEEDED( ::SHGetMalloc( &imalloc ) ) ) {
			imalloc->Free( pidl );
			imalloc->Release();
		}
	}

	return result;
}
Exemplo n.º 28
0
TableRopeScene::TableRopeScene(fs::path ropeFile, bool telekinesis) : GrabbingScene(telekinesis) {
//  vector<double> firstJoints = doubleVecFromFile((KNOT_DATA / "init_joints_train.txt").string());
//  ValuesInds vi = getValuesInds(firstJoints);
//  setupDefaultROSRave();
//  pr2m->pr2->setDOFValues(vi.second, vi.first);
  vector<int> indices(1,pr2m->pr2->robot->GetJointIndex("torso_lift_joint"));
  vector<double> values(1, .31);
  pr2m->pr2->setDOFValues(indices, values);
  vector<btVector3> tableCornersWorld = toBulletVectors(floatMatFromFile((KNOT_DATA / "table_corners.txt").string())) * METERS;
  vector<btVector3> controlPointsWorld = toBulletVectors(floatMatFromFile(ropeFile.string())) * METERS;

  PlotPoints::Ptr corners(new PlotPoints(20));
  corners->setPoints(tableCornersWorld);
  env->add(corners);

  m_table = makeTable(tableCornersWorld, .1*GeneralConfig::scale);
  float seglen = controlPointsWorld[0].distance(controlPointsWorld[1]);

//  m_rope.reset(new CapsuleRope(controlPointsWorld, fmin(seglen/4.1,.0075*METERS)));
  m_rope.reset(new CapsuleRope(controlPointsWorld, .0075*METERS));
  env->add(m_rope);
  env->add(m_table);
  setGrabBodies(m_rope->children);
  
  
}
Exemplo n.º 29
0
void AudioVisualizerApp::playAudio( const fs::path& file )
{
	FMOD_RESULT err;

	// ignore if this is not a file
	if( file.empty() || !fs::is_regular_file( file ) )
		return;

	// if audio is already playing, stop it first
	stopAudio();

	// stream the audio
	err = mFMODSystem->createStream( file.string().c_str(), FMOD_SOFTWARE, NULL, &mFMODSound );
	err = mFMODSystem->playSound( FMOD_CHANNEL_FREE, mFMODSound, false, &mFMODChannel );

	// we want to be notified of channel events
	err = mFMODChannel->setCallback( channelCallback );

	// keep track of the audio file
	mAudioPath = file;
	mIsAudioPlaying = true;

	// 
	console() << "Now playing:" << mAudioPath.filename() << std::endl;
}
Exemplo n.º 30
0
void dir_spec::iterate_dir(const fs::path & dir) {
    LDBG_ << "Parsing dir " << fs::system_complete(dir).string();

    if ( !fs::exists( dir) ) {
        LERR_ << "Dir " << dir.string() << " does not exist anymore!";
        return ;
    }

    for ( fs::directory_iterator b(dir), e; b != e; ++b) {
        if ( fs::is_directory(*b))
            iterate_dir(*b);
        else {
            // file
            bool matches_ext = false;
            for ( extensions::array::const_iterator b_ext = m_ext.vals.begin(), e_ext = m_ext.vals.end(); b_ext != e_ext; ++b_ext)
                if ( fs::extension(*b) == "." + *b_ext) {
                    matches_ext = true;
                    break;
                }

            if ( matches_ext) {
                m_stats += parse_file(*b);
                ++m_file_count;
            }
            else
                LDBG_ << "Ignoring file " << b->string();
        }
    }

}