Exemple #1
0
fs::path findExecutableMapcrafterDir(fs::path executable) {
	std::string filename = BOOST_FS_FILENAME(executable);
	if ((filename == "testconfig" || filename == "mapcrafter_markers") &&
			BOOST_FS_FILENAME(executable.parent_path()) == "tools")
		return executable.parent_path().parent_path();
	return executable.parent_path();
}
Exemple #2
0
Save::Save(fs::path const& file, bool binary)
: file_name(file)
, tmp_name(unique_path(file.parent_path()/(file.stem().string() + "_tmp_%%%%" + file.extension().string())))
{
	LOG_D("agi/io/save/file") << file;

	fp = agi::make_unique<boost::filesystem::ofstream>(tmp_name, binary ? std::ios::binary : std::ios::out);
	if (!fp->good()) {
		acs::CheckDirWrite(file.parent_path());
		acs::CheckFileWrite(file);
		throw fs::WriteDenied(tmp_name);
	}
}
Exemple #3
0
fs::path uniquify(const fs::path &dest)
{
    std::string ext = dest.extension();
    std::string fname = dest.stem();
    fs::path parent = dest.parent_path();

    unsigned number = 1;
    std::string newfname;
    fs::path newdest;

    boost::smatch match;
    if(boost::regex_search(fname, match, uregex)) {
        // Matches are indexes into fname, so don't change it while reading values
        newfname = match[1];
        number = boost::lexical_cast<short>(match[2]);
        fname = newfname;
    }

    do { 
        newfname = fname + "(" + boost::lexical_cast<std::string>(++number) + ")" + ext;
        newdest = parent / newfname;
    } while(fs::exists(newdest));

    return newdest;
}
void disk_cache_man::writeChunk(const fs::path& path, char* buffer,unsigned int size)
{
	if(path.parent_path().parent_path() != 	cachepath) 
	{
		/*Label*/
		if(!fs::exists(path.parent_path().parent_path()))
			fs::create_directory(path.parent_path().parent_path());
	}
	if(!fs::exists(path.parent_path()))
		fs::create_directory(path.parent_path());
	fs::ofstream os(path,ios::out | ios::binary);
	if(!os.good())
		throw runtime_error("Failed to open chunk file for writing in cache manager");
	os.write(buffer,size);
	os.close();
}
fs::path AudioVisualizerApp::nextAudio( const fs::path& file )
{
	if( file.empty() || !fs::is_regular_file( file ) )
		return fs::path();

	fs::path& directory = file.parent_path();

	// make a list of all audio files in the directory
	vector<fs::path> files;
	listAudio( directory, files );

	// return if there are no audio files in the directory
	if( files.empty() )
		return fs::path();

	// find current audio file
	auto itr = std::find( files.begin(), files.end(), file );

	// if not found, or if it is the last audio file, simply return first audio file
	if( itr == files.end() || *itr == files.back() )
		return files.front();

	// return next file
	return *( ++itr );
}
Exemple #6
0
void Copy(fs::path const& from, fs::path const& to) {
    acs::CheckFileRead(from);
    CreateDirectory(to.parent_path());
    acs::CheckDirWrite(to.parent_path());

    if (!CopyFile(from.wstring().c_str(), to.wstring().c_str(), false)) {
        switch (GetLastError()) {
        case ERROR_FILE_NOT_FOUND:
            throw FileNotFound(from);
        case ERROR_ACCESS_DENIED:
            throw fs::WriteDenied("Could not overwrite " + to.string());
        default:
            throw fs::WriteDenied("Could not copy: " + util::ErrorString(GetLastError()));
        }
    }
}
fs::path FileResolver::resolve(const fs::path &path) const {
	/* First, try to resolve in case-sensitive mode */
	for (size_t i=0; i<m_paths.size(); i++) {
		fs::path newPath = m_paths[i] / path;
		if (fs::exists(newPath))
			return newPath;
	}

	#if defined(__LINUX__)
		/* On Linux, also try case-insensitive mode if the above failed */
		fs::path parentPath = path.parent_path();
		std::string filename = boost::to_lower_copy(path.filename().string());

		for (size_t i=0; i<m_paths.size(); i++) {
			fs::path path = m_paths[i] / parentPath;

			if (!fs::is_directory(path))
				continue;

			fs::directory_iterator end, it(path);
			for (; it != end; ++it) {
				if (boost::algorithm::to_lower_copy(it->path().filename().string()) == filename)
					return it->path();
			}
		}
	#endif

	return path;
}
Exemple #8
0
fs::path	StarsApp::getNextFile( const fs::path &current )
{
	if( !current.empty() ) {
		bool useNext = false;

		fs::directory_iterator end_itr;
		for( fs::directory_iterator i( current.parent_path() ); i != end_itr; ++i )
		{
			// skip if not a file
			if( !fs::is_regular_file( i->status() ) ) continue;

			if(useNext) {
				// skip if extension does not match
				if( std::find( mMusicExtensions.begin(), mMusicExtensions.end(), i->path().extension() ) == mMusicExtensions.end() )
					continue;

				// file matches, return it
				return i->path();
			}
			else if( *i == current ) {
				useNext = true;
			}
		}
	}

	// failed, return empty path
	return fs::path();
}
Exemple #9
0
fs::path	StarsApp::getPrevFile( const fs::path &current )
{
	if( !current.empty() ) {
		fs::path previous;

		fs::directory_iterator end_itr;
		for( fs::directory_iterator i( current.parent_path() ); i != end_itr; ++i )
		{
			// skip if not a file
			if( !fs::is_regular_file( i->status() ) ) continue;

			if( *i == current ) {
				// do we know what file came before this one?
				if( !previous.empty() )
					return previous;
				else
					break;
			}
			else {
				// skip if extension does not match
				if( std::find( mMusicExtensions.begin(), mMusicExtensions.end(), i->path().extension() ) == mMusicExtensions.end() )
					continue;

				// keep track of this file
				previous = *i;
			}
		}
	}

	// failed, return empty path
	return fs::path();
}
Exemple #10
0
static std::string relativeUrl(fs::path const& from, fs::path const& to)
{
    if (to == from)
        return std::string();
    fs::path r = to.lexically_relative(from.parent_path());
    return r == "." ? std::string() : r.string();
}
void DXTencoderApp::loadMovieFile( const fs::path &moviePath )
{
    try {
        mMovie = qtime::MovieSurface::create( moviePath );
        
        console() << "Dimensions:" << mMovie->getWidth() << " x " << mMovie->getHeight() << std::endl;
        console() << "Duration:  " << mMovie->getDuration() << " seconds" << std::endl;
        console() << "Frames:    " << mMovie->getNumFrames() << std::endl;
        console() << "Framerate: " << mMovie->getFramerate() << std::endl;
        console() << "Has audio: " << mMovie->hasAudio() << " Has visuals: " << mMovie->hasVisuals() << std::endl;

        mMovie->setLoop( false );
        mMovie->seekToStart();
        //mMovie->play();
        isStarted = true;
        currentFrame = 0;

        
        std::string basePath = moviePath.parent_path().string();
        string newFilename =   moviePath.filename().string();
        strReplace(newFilename, moviePath.extension().string(), ".dxt5");
                                                  
        mDxtCreator.open(basePath + "/" + newFilename);

    }
    catch( ci::Exception &exc ) {
        console() << "Exception caught trying to load the movie from path: " << moviePath << ", what: " << exc.what() << std::endl;
    }
    
    
    
}
void QuarterlyIndexFileRetriever::UnzipLocalIndexFile (const fs::path& local_zip_file_name)
{
	std::ifstream zipped_file(local_zip_file_name.string(), std::ios::in | std::ios::binary);
	Poco::Zip::Decompress expander(zipped_file, local_zip_file_name.parent_path().string(), true);

	expander.decompressAllFiles();

}		// -----  end of method QuarterlyIndexFileRetriever::UnzipLocalIndexFile  -----
void ReflectionParser::generateModuleFile(
    const fs::path &fileHeader,
    const fs::path &fileSource,
    const std::string &sourceHeader,
    const ModuleFile &file
)
{
    // header file
    {
        TemplateData headerData { TemplateData::Type::Object };

        addGlobalTemplateData( headerData );

        headerData[ "moduleFileName" ] = file.name;

        fs::create_directory( fileHeader.parent_path( ) );

        utils::WriteText( 
            fileHeader.string( ), 
            m_moduleFileHeaderTemplate.render( headerData ) 
        );
    }

    // source file
    {
        TemplateData sourceData { TemplateData::Type::Object };

        addGlobalTemplateData( sourceData );

        sourceData[ "moduleFileName" ] = file.name;
        sourceData[ "moduleFileSourceHeader" ] = sourceHeader;
        sourceData[ "moduleFileHeader" ] = fileHeader.string( );

        COMPILE_TYPE_TEMPLATES( sourceData, "class", file.classes );
        COMPILE_TYPE_TEMPLATES( sourceData, "global", file.globals );
        COMPILE_TYPE_TEMPLATES( sourceData, "globalFunction", file.globalFunctions );
        COMPILE_TYPE_TEMPLATES( sourceData, "enum", file.enums );

        fs::create_directory( fileSource.parent_path( ) );

        utils::WriteText( 
            fileSource.string( ),
            m_moduleFileSourceTemplate.render( sourceData ) 
        );
    }
}
void ASM_Gaze_Tracker::initASM_Gaze_Tracker(const fs::path & trackermodel, const fs::path & cameraProfile) {
    tracker = load_ft<face_tracker>(trackermodel.string());
    tracker.detector.baseDir = trackermodel.parent_path().string() + fs::path("/").make_preferred().native();
    
    if (cameraProfile.empty() == false) {
        findBestFrontalFaceShapeIn3D();
        readCameraProfile(cameraProfile, cameraMatrix, distCoeffs);
        
    }
}
/*******************************************************************
 * Function Name: GetTrackFilePath
 * Return Type 	: const fs::path
 * Created On	: Mar 5, 2014
 * Created By 	: hrushi
 * Comments		: Get the TrackFile path from the given TrackImage path
 * Arguments	: const fs::path TrackChipPath
 *******************************************************************/
const fs::path TrackXML::GetTrackFilePath( const fs::path fsTrackChipPath)
{
	fs::path fsTrackFldrPath = fsTrackChipPath.parent_path().parent_path();
	string stemname = fsTrackChipPath.stem().string();

	UINT TrackNum, FrameNum;
	string VideoBaseName;

	GetTrkChipNameParts(stemname, TrackNum, FrameNum, VideoBaseName);
	fs::path fsTrackFilePath = fsTrackFldrPath.string() + "/" + VideoBaseName + "_track.xml";

	return fsTrackFilePath;
}
void disk_cache_man::checkIfEmpty(fs::path& in)
{
	fs::path upper = in.parent_path();
	while(upper != cachepath)
	{
		if(upper.empty())
		{
			fs::remove(upper);
		}
		upper = upper.parent_path();
	}

}
Exemple #17
0
std::string Shader::parseShader( const fs::path &path, bool optional, int level )
{
	std::stringstream output;

	if( level > 32 ) {
		throw std::runtime_error( "Reached the maximum inclusion depth." );
		return std::string();
	}

	static const std::regex includeRegexp( "^[ ]*#[ ]*include[ ]+[\"<](.*)[\">].*" );

	std::ifstream input( path.c_str() );
	if( !input.is_open() ) {
		if( optional )
			return std::string();

		if( level == 0 ) {
			char msg[512];
			snprintf( msg, 512, "Failed to open shader file '%s'.", path.c_str() );
			throw std::runtime_error( msg );
		}
		else {
			char msg[512];
			snprintf( msg, 512, "Failed to open shader include file '%s'.", path.c_str() );
			throw std::runtime_error( msg );
		}

		return std::string();
	}

	// go through each line and process includes
	std::string line;
	std::smatch matches;

	while( std::getline( input, line ) ) {
		if( std::regex_search( line, matches, includeRegexp ) )
			output << parseShader( path.parent_path() / matches[1].str(), false, level + 1 );
		else
			output << line;

		output << std::endl;
	}

	input.close();

	// make sure #version is the first line of the shader
	if( level == 0 )
		return parseVersion( output.str() );
	else
		return output.str();
}
Exemple #18
0
static void SplitWalletPath(const fs::path& wallet_path, fs::path& env_directory, std::string& database_filename)
{
    if (fs::is_regular_file(wallet_path)) {
        // Special case for backwards compatibility: if wallet path points to an
        // existing file, treat it as the path to a BDB data file in a parent
        // directory that also contains BDB log files.
        env_directory = wallet_path.parent_path();
        database_filename = wallet_path.filename().string();
    } else {
        // Normal case: Interpret wallet path as a directory path containing
        // data and log files.
        env_directory = wallet_path;
        database_filename = "wallet.dat";
    }
}
/*******************************************************************
 * Function Name: GiveSegImgPath
 * Return Type 	: const fs::path
 * Created On	: Aug 21, 2013
 * Created By 	: hrushi
 * Comments		: For the given image path. It creates a segmentation folder and returns the path where the image could be stored
 * Arguments	: const fs::path& ImgPath
 *******************************************************************/
const fs::path Detect::GiveSegImgPath( const fs::path& iPath, const string Suffix)
{
	fs::path SegImgPath;


	fs::path SegFldr = iPath.parent_path().string() + "/Seg";
	fs::create_directory(SegFldr);

	string OutputPath;
	OutputPath = SegFldr.parent_path().string() + "/Seg/";
	OutputPath +=  iPath.stem().string() + Suffix;
	OutputPath +=  iPath.extension().string();

	SegImgPath = OutputPath;

	return SegImgPath;
}
Exemple #20
0
std::shared_ptr<OStreamFile> writeFileStream( const fs::path &path, bool createParents )
{
	if( createParents && path.has_parent_path() ) {
		fs::create_directories( path.parent_path() );
	}
#if defined( CINDER_MSW )
	FILE *f = _wfopen( expandPath( path ).wstring().c_str(), L"wb" );
#else
	FILE *f = fopen( expandPath( path ).string().c_str(), "wb" );
#endif
	if( f ) {
		OStreamFileRef s = OStreamFile::create( f, true );
		s->setFileName( path );
		return s;
	}
	else
		return std::shared_ptr<OStreamFile>();
}
void PostProcessingApp::playNext()
{
	// get directory
	fs::path path = mFile.parent_path();

	// list *.mov files
	vector<string> files;
	string filter( ".mov" );

	fs::directory_iterator end_itr;
	for(fs::directory_iterator itr(path);itr!=end_itr;++itr) {
		// skip if not a file
		if( !boost::filesystem::is_regular_file( itr->status() ) ) continue;
		
		// skip if no match
		if( itr->path().filename().string().find( filter ) == string::npos ) continue;

		// file matches, store it
		files.push_back( itr->path().string() );
	}

	// check if playable files are found
	if( files.empty() ) return;

	// play next file
	vector<string>::iterator itr = find(files.begin(), files.end(), mFile);
	if( itr == files.end() ) {
		play( files[0] );
	}
	else {
		++itr;
		if( itr == files.end() ) 
			play( files[0] );
		else play( *itr );
	}
}
Exemple #22
0
void writeToFile(fs::path _path)
{
	stringstream ss;

	if (fileCount < 0){
		fileCount = 0;
		ss << fileCount;
		outFile.open(fs::path(string(BASE_MODEL_PATH)+"/Data"+ss.str()+".bin"), ios::binary);
		ss.flush();
	}
	else if (byteCount > BYTE_LIMIT){
		outFile.flush();
		outFile.close();
		fileCount++;
		ss << fileCount;
		outFile.open(fs::path(string(BASE_DEST_PATH)+"/Data"+ss.str()+".bin"), ios::binary);
		ss.flush();
		byteCount = 0;
		// close file and open new
	}

	Header head;
	head.id = strToUint64(_path.stem());


	idxFile.open(_path, ios::binary);
	dataFile.open(_path.parent_path() / (_path.stem()+".data"), ios::binary);

	idxFile.seekg(0, ios::beg);
	idxFile.read((char*)&head.indexCount, sizeof(unsigned));
	idxFile.seekg(4, ios::beg);
	dataFile.seekg(0, ios::beg);
	dataFile.read((char*)&head.vertexCount, sizeof(unsigned));
	dataFile.seekg(4, ios::beg);

	indexData = new unsigned[head.indexCount];
	vertexData = new ooctools::V4N4[head.vertexCount];

	idxFile.read((char*)indexData, sizeof(unsigned)*head.indexCount);
	idxFile.close();

	dataFile.read((char*)vertexData, sizeof(V4N4)*head.vertexCount);
	dataFile.close();

	// ------------------------------------
	//write to file

	outFile.seekp(byteCount, ios::beg);
	//writing header-info
	outFile.write((char*)&head, sizeof(Header));
	outFile.seekp(byteCount+sizeof(Header), ios::beg);
	//writing the indices
	outFile.write((char*)indexData, head.indexCount*sizeof(unsigned));
	outFile.seekp(byteCount + sizeof(Header) + head.indexCount*sizeof(unsigned), ios::beg);
	//writing the vertices
	outFile.write((char*)vertexData, head.vertexCount*sizeof(V4N4));
	byteCount += head.sizeOf();
	outFile.flush();

	delete[] vertexData;
	vertexData = 0;
	delete[] indexData;
	indexData = 0;
}
Exemple #23
0
    std::vector<Toolset> find_toolset_instances_preferred_first(const VcpkgPaths& paths)
    {
        using CPU = System::CPUArchitecture;

        const auto& fs = paths.get_filesystem();

        // Note: this will contain a mix of vcvarsall.bat locations and dumpbin.exe locations.
        std::vector<fs::path> paths_examined;

        std::vector<Toolset> found_toolsets;
        std::vector<Toolset> excluded_toolsets;

        const SortedVector<VisualStudioInstance> sorted{get_visual_studio_instances_internal(paths),
                                                        VisualStudioInstance::preferred_first_comparator};

        const bool v140_is_available = Util::find_if(sorted, [&](const VisualStudioInstance& vs_instance) {
                                           return vs_instance.major_version() == "14";
                                       }) != sorted.end();

        for (const VisualStudioInstance& vs_instance : sorted)
        {
            const std::string major_version = vs_instance.major_version();
            if (major_version >= "15")
            {
                const fs::path vc_dir = vs_instance.root_path / "VC";

                // Skip any instances that do not have vcvarsall.
                const fs::path vcvarsall_dir = vc_dir / "Auxiliary" / "Build";
                const fs::path vcvarsall_bat = vcvarsall_dir / "vcvarsall.bat";
                paths_examined.push_back(vcvarsall_bat);
                if (!fs.exists(vcvarsall_bat)) continue;

                // Get all supported architectures
                std::vector<ToolsetArchOption> supported_architectures;
                if (fs.exists(vcvarsall_dir / "vcvars32.bat"))
                    supported_architectures.push_back({"x86", CPU::X86, CPU::X86});
                if (fs.exists(vcvarsall_dir / "vcvars64.bat"))
                    supported_architectures.push_back({"amd64", CPU::X64, CPU::X64});
                if (fs.exists(vcvarsall_dir / "vcvarsx86_amd64.bat"))
                    supported_architectures.push_back({"x86_amd64", CPU::X86, CPU::X64});
                if (fs.exists(vcvarsall_dir / "vcvarsx86_arm.bat"))
                    supported_architectures.push_back({"x86_arm", CPU::X86, CPU::ARM});
                if (fs.exists(vcvarsall_dir / "vcvarsx86_arm64.bat"))
                    supported_architectures.push_back({"x86_arm64", CPU::X86, CPU::ARM64});
                if (fs.exists(vcvarsall_dir / "vcvarsamd64_x86.bat"))
                    supported_architectures.push_back({"amd64_x86", CPU::X64, CPU::X86});
                if (fs.exists(vcvarsall_dir / "vcvarsamd64_arm.bat"))
                    supported_architectures.push_back({"amd64_arm", CPU::X64, CPU::ARM});
                if (fs.exists(vcvarsall_dir / "vcvarsamd64_arm64.bat"))
                    supported_architectures.push_back({"amd64_arm64", CPU::X64, CPU::ARM64});

                // Locate the "best" MSVC toolchain version
                const fs::path msvc_path = vc_dir / "Tools" / "MSVC";
                std::vector<fs::path> msvc_subdirectories = fs.get_files_non_recursive(msvc_path);
                Util::erase_remove_if(msvc_subdirectories,
                                      [&fs](const fs::path& path) { return !fs.is_directory(path); });

                // Sort them so that latest comes first
                std::sort(
                    msvc_subdirectories.begin(),
                    msvc_subdirectories.end(),
                    [](const fs::path& left, const fs::path& right) { return left.filename() > right.filename(); });

                for (const fs::path& subdir : msvc_subdirectories)
                {
                    const fs::path dumpbin_path = subdir / "bin" / "HostX86" / "x86" / "dumpbin.exe";
                    paths_examined.push_back(dumpbin_path);
                    if (fs.exists(dumpbin_path))
                    {
                        const Toolset v141_toolset{
                            vs_instance.root_path, dumpbin_path, vcvarsall_bat, {}, V_141, supported_architectures};

                        const auto english_language_pack = dumpbin_path.parent_path() / "1033";

                        if (!fs.exists(english_language_pack))
                        {
                            excluded_toolsets.push_back(v141_toolset);
                            break;
                        }

                        found_toolsets.push_back(v141_toolset);

                        if (v140_is_available)
                        {
                            const Toolset v140_toolset{vs_instance.root_path,
                                                       dumpbin_path,
                                                       vcvarsall_bat,
                                                       {"-vcvars_ver=14.0"},
                                                       V_140,
                                                       supported_architectures};
                            found_toolsets.push_back(v140_toolset);
                        }

                        break;
                    }
                }

                continue;
            }

            if (major_version == "14" || major_version == "12")
            {
                const fs::path vcvarsall_bat = vs_instance.root_path / "VC" / "vcvarsall.bat";

                paths_examined.push_back(vcvarsall_bat);
                if (fs.exists(vcvarsall_bat))
                {
                    const fs::path vs_dumpbin_exe = vs_instance.root_path / "VC" / "bin" / "dumpbin.exe";
                    paths_examined.push_back(vs_dumpbin_exe);

                    const fs::path vs_bin_dir = vcvarsall_bat.parent_path() / "bin";
                    std::vector<ToolsetArchOption> supported_architectures;
                    if (fs.exists(vs_bin_dir / "vcvars32.bat"))
                        supported_architectures.push_back({"x86", CPU::X86, CPU::X86});
                    if (fs.exists(vs_bin_dir / "amd64\\vcvars64.bat"))
                        supported_architectures.push_back({"x64", CPU::X64, CPU::X64});
                    if (fs.exists(vs_bin_dir / "x86_amd64\\vcvarsx86_amd64.bat"))
                        supported_architectures.push_back({"x86_amd64", CPU::X86, CPU::X64});
                    if (fs.exists(vs_bin_dir / "x86_arm\\vcvarsx86_arm.bat"))
                        supported_architectures.push_back({"x86_arm", CPU::X86, CPU::ARM});
                    if (fs.exists(vs_bin_dir / "amd64_x86\\vcvarsamd64_x86.bat"))
                        supported_architectures.push_back({"amd64_x86", CPU::X64, CPU::X86});
                    if (fs.exists(vs_bin_dir / "amd64_arm\\vcvarsamd64_arm.bat"))
                        supported_architectures.push_back({"amd64_arm", CPU::X64, CPU::ARM});

                    if (fs.exists(vs_dumpbin_exe))
                    {
                        const Toolset toolset = {vs_instance.root_path,
                                                 vs_dumpbin_exe,
                                                 vcvarsall_bat,
                                                 {},
                                                 major_version == "14" ? V_140 : V_120,
                                                 supported_architectures};

                        const auto english_language_pack = vs_dumpbin_exe.parent_path() / "1033";

                        if (!fs.exists(english_language_pack))
                        {
                            excluded_toolsets.push_back(toolset);
                            break;
                        }

                        found_toolsets.push_back(toolset);
                    }
                }
            }
        }

        if (!excluded_toolsets.empty())
        {
            System::println(
                System::Color::warning,
                "Warning: The following VS instances are excluded because the English language pack is unavailable.");
            for (const Toolset& toolset : excluded_toolsets)
            {
                System::println("    %s", toolset.visual_studio_root_path.u8string());
            }
            System::println(System::Color::warning, "Please install the English language pack.");
        }

        if (found_toolsets.empty())
        {
            System::println(System::Color::error, "Could not locate a complete toolset.");
            System::println("The following paths were examined:");
            for (const fs::path& path : paths_examined)
            {
                System::println("    %s", path.u8string());
            }
            Checks::exit_fail(VCPKG_LINE_INFO);
        }

        return found_toolsets;
    }