示例#1
0
bool RLogMill::findRepository(boost::filesystem::path& dir, std::string& log_format) {

    dir = absolute(dir);

    //fprintf(stderr, "find repository from initial path: %s\n", dir.string().c_str());

    while(is_directory(dir)) {

             if(is_directory(dir / ".git")) log_format = "git";
        else if(is_directory(dir / ".hg"))  log_format = "hg";
        else if(is_directory(dir / ".bzr")) log_format = "bzr";
        else if(is_directory(dir / ".svn")) log_format = "svn";

        if(!log_format.empty()) {
            //fprintf(stderr, "found '%s' repository at: %s\n", log_format.c_str(), dir.string().c_str());
            return true;
        }

        if(!dir.has_parent_path()) return false;

        dir = dir.parent_path();
    }

    return false;
}
示例#2
0
boost::optional<fs::path> HeaderTagger::toUserLibHeader(const fs::path& path) const {
	static const boost::optional<fs::path> fail;

	if(userIncludeDirs.empty()) { return fail; }

	if(contains(userIncludeDirs, fs::canonical(path))) { return fs::path(); }

	if(!path.has_parent_path()) { return fail; }

	// if it is within the user-added-include directory, build relative path
	auto res = toUserLibHeader(path.parent_path());
	return (res) ? (*res / path.filename()) : fail;
}
示例#3
0
/**
 * A utility function cutting down std-lib header files.
 */
boost::optional<fs::path> HeaderTagger::toStdLibHeader(const fs::path& path) const {
	static const boost::optional<fs::path> fail;

	if(stdLibDirs.empty()) { return fail; }

	if(contains(stdLibDirs, fs::canonical(path))) { // very expensive, keep low use
		return fs::path();
	}

	if(!path.has_parent_path()) { return fail; }

	// if it is within the std-lib directory, build relative path
	auto res = toStdLibHeader(path.parent_path());
	return (res) ? (*res / path.filename()) : fail;
}
示例#4
0
文件: path.cpp 项目: xxwpc/gitbk
void path_init( const std::string &repo )
{
   path_repo = repo;

   while ( true )
   {
      if ( boost::filesystem::exists( path_repo / path_bak ) )
         break;

      if ( path_repo.has_parent_path( ) )
         path_repo = path_repo.parent_path( );
      else
         break;
   }
}
bool IsInside(const fs::path& path, const fs::path& directory) {
    const fs::path target = fs::canonical(directory);

    if (!path.has_parent_path()) {
        return false;
    }

    fs::path cur = path.parent_path();
    while (cur.has_parent_path()) {
        if (cur == target) {
            return true;
        } else {
            cur = cur.parent_path();
        }
    }
    return false;
}
示例#6
0
文件: Path.cpp 项目: othnos/PutkaRTS
static bool Path::mkdir(const boost::filesystem::path& path, bool recurse)
try {
	if (recurse) {
		if (path.has_parent_path()) {
			boost::filesystem::path parent = path.parent_path();
			if (!boost::filesystem::exists(parent)) {
				mkdir(parent, recurse);
			}
		}
		if (boost::filesystem::is_directory(path)) {
			return true;
		}
	}
	return boost::filesystem::create_directory(path);
} catch (boost::filesystem::basic_filesystem_error<boost::filesystem::path>& e) {
	return false;
}
示例#7
0
    /** Find local sub directories of \p path. */
    std::vector<std::string> FindLocalRelativeDirs(const fs::path& path) {
        std::vector<std::string> dirs;
        if (path.has_parent_path() && path.parent_path() != path) {
                dirs.push_back("..");
        }

        fs::directory_iterator end_it;
        for (fs::directory_iterator it(path); it != end_it; ++it) {
            if (fs::is_directory(it->path())) {
                fs::path last_bit_of_path = it->path().filename();
                std::string utf8_dir_name = PathToString(last_bit_of_path);
                DebugLogger() << "SaveFileDialog::FindLocalRelativeDirs name: " << utf8_dir_name
                              << " valid UTF-8: " << IsValidUTF8(utf8_dir_name);
                dirs.push_back(utf8_dir_name);
            }
        }

        return dirs;
    }
示例#8
0
  static boost::filesystem::path system_absolute(
      const boost::filesystem::path path)
  {
    if (path.empty())
      return path;

    if (path.is_absolute())
      return path;

    if (path.has_parent_path())
      return bfs::system_complete(path);

    if (!bfs::exists(path) || bfs::is_directory(path))
    {
      std::string envPath = qi::os::getenv("PATH");
      size_t begin = 0;
#ifndef _WIN32
      static const char SEPARATOR = ':';
#else
      static const char SEPARATOR = ';';
#endif
      for (size_t end = envPath.find(SEPARATOR, begin);
          end != std::string::npos;
          begin = end + 1, end = envPath.find(SEPARATOR, begin))
      {
        std::string realPath = envPath.substr(begin, end - begin);
        bfs::path p(realPath);

        p /= path;
        p = boost::filesystem::system_complete(p);

        if (boost::filesystem::exists(p) &&
            !boost::filesystem::is_directory(p))
          return p.string(qi::unicodeFacet());
      }
    }

    // fallback to something
    return bfs::system_complete(path);
  }
示例#9
0
文件: main.cpp 项目: HavenDV/Detector
auto	detect_file_or_url( const fs::path & file, const fs::path & saveTo, double k ) {
	auto isExists = fs::exists( file );
	auto isUrl = is_url( file );
	if ( !isExists && !isUrl ) {
		std::cout << "File or directory " << file << " not is exists" << std::endl;
		return -1;
	}

	auto outDir = saveTo.empty() ? ( file.has_parent_path() ? file.parent_path() : "./" ) : saveTo;
	if ( !isUrl ) {
		outDir /= file.stem();
	}

	if ( !fs::exists( outDir ) && !fs::create_directories( outDir ) ) {
		std::cout << "Unable to create directory " << outDir << std::endl;
		return -1;
	}

	std::cout << "Begin. k = " << k << "." << std::endl;
	std::cout << "Input " << ( isUrl ? "url" : "file" ) << " is " << file << std::endl;
	std::cout << "Files save to " << outDir << std::endl;
	
	return detect( file.string(), outDir.string(), k );
}
示例#10
0
      // Read parameter from spec file.
      // Return true if read succeeded.
      bool XMLSpecReaderImpl::read(const std::string& filePath)
      {
        // Read XML file.
        boost::property_tree::ptree root;
        boost::property_tree::read_xml(filePath, root);

        // Set current directory.
        const boost::filesystem::path oldPath = boost::filesystem::current_path();
        const boost::filesystem::path currentPath = boost::filesystem::path(filePath);
        if(currentPath.has_parent_path())
          boost::filesystem::current_path(currentPath.parent_path());

        // Read fields.
        // name
        if( boost::optional<std::string> value = root.get_optional<std::string>("animation.<xmlattr>.name") )
        {
          _name = value.get();
        }

        // loops
        if( boost::optional<unsigned int> value = root.get_optional<unsigned int>("animation.<xmlattr>.loops") )
        {
          _loops = value.get();
        }

        // skip_first
        if( boost::optional<bool> value = root.get_optional<bool>("animation.<xmlattr>.skip_first") )
        {
          _skipFirst = value.get();
        }

        // delay
        Delay defaultDelay = { DEFAULT_FRAME_NUMERATOR, DEFAULT_FRAME_DENOMINATOR };
        if( boost::optional<std::string> value = root.get_optional<std::string>("animation.<xmlattr>.default_delay") )
        {
          if( !str2delay(value.get(), &defaultDelay) )
          {
            defaultDelay.num = DEFAULT_FRAME_NUMERATOR;
            defaultDelay.den = DEFAULT_FRAME_DENOMINATOR;
          }
        }

        // frames
        if( boost::optional<boost::property_tree::ptree&> child = root.get_child_optional("animation") )
        {
          BOOST_FOREACH(const boost::property_tree::ptree::value_type& current, child.get())
          {
            std::string file;
            Delay delay;
            const boost::property_tree::ptree& frame = current.second;

            // filepath
            if( boost::optional<std::string> value = frame.get_optional<std::string>("<xmlattr>.src") )
            {
              file = value.get();
            }
            if(file.empty())
              continue;

            // delay
            if( boost::optional<std::string> value = frame.get_optional<std::string>("<xmlattr>.delay") )
            {
              if( !str2delay(value.get(), &delay) )
                delay = defaultDelay;
            }
            else
            {
              delay = defaultDelay;
            }

            // Add frame informations.
            const FrameInfo frameInfo = { boost::filesystem::absolute(file).string(), delay };
            _frameInfos.push_back(frameInfo);
          }
        }