/// \brief TODOCUMENT
bool options_block::is_acceptable_executable(const path &arg_output_file ///< TODOCUMENT
                                             ) {
	if (arg_output_file.filename() == ".." || arg_output_file.filename() == ".") {
//		cerr << "Here0" << endl;
		return false;
	}
	if (arg_output_file.has_root_directory() || arg_output_file.has_root_name()) {
//		cerr << "Here1" << endl;
		if (!exists(arg_output_file) && !is_regular_file(arg_output_file)) {
//			cerr << "Here2" << endl;
			return false;
		}
	}
	return true;
}
LandmarkCollection DefaultNamedLandmarkSource::get(const path& imagePath) {
	// Todo: .at throws an out_of_range exception when the element is not found.
	//       [] inserts a new, empty element if not found. Think about what we want.
	//       there is also find, which returns an iterator
	//       and we may want to use an unordered_map because of O(1) access
	Logger logger = Loggers->getLogger("imageio");

	LandmarkCollection landmarks;
	try { // Todo: We should probably change this unreadable try-catch code to find()
		landmarks = landmarkCollections.at(imagePath);
	} catch (std::out_of_range& e) {
		try {
			landmarks = landmarkCollections.at(imagePath.filename());
		} catch (std::out_of_range& e) {
			try {
				landmarks = landmarkCollections.at(imagePath.stem());
			}
			catch (std::out_of_range& e) {
				logger.warn("Landmarks for the given image could not be found, returning an empty LandmarkCollection. Is this expected?");
			}
		}
		// we succeeded using the basename
	}
	return landmarks; // empty if element not found
}
/// \brief TODOCUMENT
///
/// \relates score_classn_value_results_set
void cath::score::write_to_svm_light_data_files(const score_classn_value_results_set &arg_results_set,      ///< TODOCUMENT
                                                const path                           &arg_output_file_stem, ///< TODOCUMENT
                                                const size_t                         &arg_num_repeats,      ///< TODOCUMENT
                                                mt19937                              &arg_rng,              ///< TODOCUMENT
                                                const double                         &arg_fraction_train    ///< TODOCUMENT
                                                ) {
	const auto num_instances   = get_num_instances      ( arg_results_set );
	const auto names           = get_names              ( arg_results_set );
	const auto instance_labels = get_instance_labels    ( arg_results_set );
	const auto scalings        = get_value_list_scalings( arg_results_set );

	// Get a data structure in which all lists are sorted in the same way
	const auto results = transform_build<score_classn_value_vec_vec>(
		names,
		[&] (const string &x) {
			const auto &results_list = arg_results_set.get_score_classn_value_list_of_name( x );
			return get_score_classn_values_of_instance_labels( results_list, instance_labels );
		}
	);

	for (const size_t &repeat_ctr : irange( 1_z, arg_num_repeats + 1 ) ) {
		const auto repeat_ctr_str = lexical_cast<string>( repeat_ctr );

		const path train_file  = arg_output_file_stem.parent_path() / ( path( arg_output_file_stem.filename() ).string() + "." + repeat_ctr_str + ".train" );
		const path test_file   = arg_output_file_stem.parent_path() / ( path( arg_output_file_stem.filename() ).string() + "." + repeat_ctr_str + ".test"  );

		const size_vec_size_vec_pair split_indices = random_split( arg_rng, num_instances, arg_fraction_train );

		write_to_svm_light_data_files_impl( results, scalings, train_file, split_indices.first  );
		write_to_svm_light_data_files_impl( results, scalings, test_file,  split_indices.second );
	}
}
示例#4
0
node_tuple readFile(path currentFile)
{
	regex rx("(^|\\s)#include\\s[\"<](.*?)[\">]");

	string fileName = currentFile.filename();
	transform(fileName.begin(), fileName.end(), fileName.begin(), tolower);
	string fileFolder = currentFile.parent_path();
	transform(fileFolder.begin(), fileFolder.end(), fileFolder.begin(), tolower);

	vector<string> includes;
	ifstream sourceFile(currentFile);
	stringstream buffer;
	buffer << sourceFile.rdbuf();
	sourceFile.close();
	string sourceFileContent(buffer.str());

	sregex_iterator rit(sourceFileContent.begin(), sourceFileContent.end(), rx);
	sregex_iterator riend;

	smatch res;
	string res2;

	while (rit != riend) {
		res = *rit;
		res2 = res[2];
		transform(res2.begin(), res2.end(), res2.begin(), tolower);
		includes.push_back(res2);
		++rit;
	}

	return make_tuple(fileName, fileFolder, includes);
}
示例#5
0
void file_manager::safe_add_file(path & file, suffix_array_builder & sa_builder)
{
    boost::lock_guard<boost::mutex> locker(lock_);
    size_t file_number = files_.size();
    std::string file_name = file.filename().string();
    files_.push_back(file.string());
    sa_builder.add_suffixes(file_name, file_number);
}
示例#6
0
文件: huefile.cpp 项目: caomw/sgps
HUEFile::HUEFile(const path p)
{
    //TODO: name  = p.filename().string(); for Boost >1.46
    name  = p.filename().string();
    ppath = p.string();
    size  = file_size(p);
    column = 4;
    sslimit = 10;
}
示例#7
0
static void add_resource_dir(const char* a_class, const path& p)
{
   const path xml_file = p / (p.filename().replace_extension(".xml"));

   if (!exists(xml_file))
      warn() << "Missing resource XML file: " << xml_file;
   else
      add_resource(a_class, IResourcePtr(new FilesystemResource(p)));
}
示例#8
0
filetype analyse_file(path file){
	if(!is_regular_file(file)){
		return OTHER;
	}
	string filename=file.filename().string();
	string filename_extension=cut(filename,".").back();
	if(in(filename_extension,settings::header_endings)){
		return HEADER;
	}
	else if(in(filename_extension,settings::implementation_endings)){
		return IMPL;
	}
	else return OTHER;
}
	InquiryProcessor (ThreadPool & _threadPool, std::string _saver): threadPool(_threadPool), saverPath(_saver) {
		std::ifstream ifs(saverPath);
		std::string textsPath;
		getline(ifs, textsPath);
		curPath = path(textsPath);
		std::string text;
		int words = 0;
		std::string str; 
		int counter = 0;
		std::vector<double> newText;
		while (getline(ifs, str)) {
			while(str.find(" ") != std::string::npos) {	
				text = str.substr(0, str.find(" "));
				str = str.substr(str.find(" ") + 1);
				newText.push_back(atof(text.c_str()));
			}
			matrix.push_back(newText);
			CPoint kdTreePoint(newText, counter);
			counter++;
			KDTreeBase.push_back(kdTreePoint);
			newText.clear();
		}
		ifs.close();

		directory_iterator end_iter;
		try {
			if (exists(curPath)) {
				if (is_regular_file(curPath)) {
					docs = 1;
					docNames.push_back(curPath.filename().generic_string());
				}
				docs = 0;
				if (is_directory(curPath)) {
					for (directory_iterator p(curPath); p != end_iter; ++p) {
						docNames.push_back(p->path().filename().generic_string());
						docs++;
					}
				}				
			}
		} catch (const filesystem_error& ex) {
			std::cout << ex.what() << std::endl;
		} 
		for (int i = 0; i < docs; ++i) {
			docID.push_back(i);
		}
		// build для одного, потом выкидываем точку из кдтри бэйз и снова строим вектор рутов
		root = BuildKDTree(KDTreeBase);
	}	
示例#10
0
int SortIt::isCorrectFile(path file) {
    string fileName = file.filename().string();

    // EXISTS = -1
    if (!exists(file)) {
        return -1;
    }

    // DUPLICATE = 1
    if (boost::starts_with(fileName, DUPLICATE_FILE_TAG)) {
        return 1;
    }

    // FILE OK = 0
    return 0;
}
示例#11
0
uint32_t wallet::import_electrum_wallet(
        const path& wallet_dat,
        const string& wallet_dat_passphrase,
        const string& account_name
        )
{ try {
   if( NOT is_open()     ) FC_CAPTURE_AND_THROW( wallet_closed );
   if( NOT is_unlocked() ) FC_CAPTURE_AND_THROW( wallet_locked );

   uint32_t count = 0;
   auto keys = bitcoin::import_electrum_wallet( wallet_dat, wallet_dat_passphrase );
   for( const auto& key : keys )
      count += friendly_import_private_key( key, account_name );

   start_scan( 0, 1 );
   ulog( "Successfully imported ${x} keys from ${file}", ("x",keys.size())("file",wallet_dat.filename()) );
   return count;
} FC_CAPTURE_AND_RETHROW( (wallet_dat)(account_name) ) }
示例#12
0
void KeyManager::prefixKeyFile(const path& pKeyFileFName, const std::string& pPrefix) const {
	BOOST_LOG_NAMED_SCOPE("KeyManager::renameMallformedKeyFile");
	path myNewFName;
	try {
		if (exists(pKeyFileFName)) {
			path myPath = pKeyFileFName.parent_path();
			path myFName = pKeyFileFName.filename();
			myNewFName = myPath / (path(pPrefix+"-") += myFName);
			BOOST_LOG_TRIVIAL(debug)<<"Going to rename "<< pKeyFileFName << " into " << myNewFName << ".";
			rename(pKeyFileFName, myNewFName);
		} else {
			BOOST_LOG_TRIVIAL(debug)<<"File "<< pKeyFileFName << " does not exist.";
		}
	} catch (const std::exception& myExc) {
		BOOST_LOG_TRIVIAL(error)<<"Failed to rename "<< pKeyFileFName << " into " << myNewFName << "because - " << myExc.what();
	} catch(...) {
		BOOST_LOG_TRIVIAL(error)<<"Failed to rename "<< pKeyFileFName << " into " << myNewFName << ".";
	}
}
void GenerateStdAfxMaker::set_include( const path& include )
{
    for ( size_t i = 0; i < m_includes.size(); ++i )
    {
        const path& p = m_includes[i].first;

        if ( p == include )
        {
            m_includes[i].second = true;
            break;
        }
        else if ( p.has_parent_path() )
        {
            if ( p.filename() == include.filename() )
            {
                m_includes[i].second = true;
                break;
            }
        }
    }
}
示例#14
0
size_t inline Epub::compute_epub_hash(const path & _absolute_path)
{

	unsigned int size = file_size(_absolute_path);
	time_t lmtime = last_write_time(_absolute_path);
	string timestring = lexical_cast<std::string>(lmtime);

	#ifdef DEBUG
	cout << "File Exists" << endl;
	cout << "\t Name: " << _absolute_path.filename().string() << endl;
	cout << "\t Absolute path: " << _absolute_path.string() << endl;
	cout << "\t Size: " << size << endl;
	cout << "\t Last Modified: " << timestring << endl;
	#endif

	//Calculate the hash.
	size_t filehash = 0;
	hash_combine<string>(filehash, _absolute_path.string());
	hash_combine<unsigned int>(filehash, size);
	hash_combine<string>(filehash, timestring);

	return filehash;
}
示例#15
0
int main(int argc, char* argv[])
{
	using std::cout;
	using std::cerr;
	using boost::filesystem::directory_iterator;
	using boost::filesystem::ifstream;
	using boost::iostreams::filtering_istream;
	using boost::iostreams::gzip_decompressor;

	const directory_iterator dir_iter;
	ptr_vector<genome> genomes(20);
	string line;
	for (directory_iterator di0(argv[1]); di0 != dir_iter; ++di0)
	{
		const path genome_path = di0->path();
		if (!is_directory(genome_path)) continue;
		cout << "Reading " << genome_path.filename() << '\n';

		// Parse README
		ifstream readme(genome_path / "README");
		for (auto i = 0; i < 21; ++i) getline(readme, line);
		size_t idx;
		while (getline(readme, line) && ((idx = line.find("taxid=", 51)) == string::npos));
		const auto taxid = line.substr(idx + 6, line.size() - idx - 7);
		readme.close();

		// Parse README_CURRENT_BUILD
		ifstream build(genome_path / "README_CURRENT_BUILD");
		getline(build, line); // ======================================================================
		getline(build, line); // Organism: Apis mellifera (honey bee) 
		const auto organism = line.substr(10, line.size() - 11);
		getline(build, line); // NCBI Build Number: 5 
		const auto ncbiBuild = line.substr(19, line.size() - 20);
		getline(build, line); // Version: 1 
		const auto version = line.substr(9, line.size() - 10);
		getline(build, line); // Release date: 29 April 2011 
		const auto releaseDate = line.substr(14, line.size() - 15);
		build.close();

		// Construct a genome.
		genomes.push_back(new genome(taxid, organism, ncbiBuild, version, releaseDate));
		auto& g = genomes.back();

		// Sort *.fa.gz
		ptr_vector<string> files(20);
		for (directory_iterator di(genome_path); di != dir_iter; ++di)
		{
			const auto p = di->path();
			if (p.extension().string() != ".gz") continue;
			files.push_back(new string(p.filename().string()));
		}
		files.sort();

		// Parse *.fa.gz in the previously sorted order
		g.files.reserve(files.size());
		for (const auto& f : files)
		{
			ifstream in(genome_path / f);
			filtering_istream fis;
			fis.push(gzip_decompressor());
			fis.push(in);
			getline(fis, line); // Header line
			const auto header = line;
			size_t nucleotides = 0;
			while (getline(fis, line))
			{
				if (line.front() == '>')
				{
					cerr << "Multiple header lines in " << f << '\n';
				}
				if (line.size() > 70)
				{
					cerr << "Line longer than 70 characters in " << f << '\n';
				}
				nucleotides += line.size();
			}
			g.files.push_back(file_t(f, header, nucleotides));
		}

		// Compute the overall nucleotides
		for (const auto& f : g.files) g.nucleotides += f.nucleotides;
	}

	// Sort genomes in the descending order of nucleotides
	genomes.sort();

	// Output genome construction code in javascript
	cout << "  var genomes = [";
	for (auto i = 0; i < genomes.size(); ++i)
	{
		const auto& g = genomes[i];
		if (i) cout << ", ";
		cout << "{\n"
		     << "    taxid: " << g.taxid << ",\n"
		     << "    name: '" << g.organism << "',\n"
		     << "    ncbiBuild: " << g.ncbiBuild << ",\n"
		     << "    version: " << g.version << ",\n"
		     << "    releaseDate: '" << g.releaseDate << "',\n"
		     << "    nucleotides: " << g.nucleotides << ",\n"
		     << "    files: [";
		for (auto j = 0; j < g.files.size(); ++j)
		{
			const auto& f = g.files[j];
			if (j) cout << ", ";
			cout << "{\n"
			     << "      file: '" << f.file << "',\n"
			     << "      header: '" << f.header << "',\n"
			     << "      nucleotides: " << f.nucleotides << "\n"
			     << "    }";
		}
		cout << "]\n"
		     << "  }";
	}
	cout << "];\n";
}
示例#16
0
文件: fs.cpp 项目: Aegisub/Aegisub
	bool HasExtension(path const& p, std::string const& ext) {
		auto filename = p.filename().string();
		if (filename.size() < ext.size() + 1) return false;
		if (filename[filename.size() - ext.size() - 1] != '.') return false;
		return boost::iends_with(filename, ext);
	}
示例#17
0
	void decrypt(path &filePlace, path &keyPlace) {
		
		std::ifstream fileToDecode(filePlace.string(), std::ios::binary);
		std::ifstream fileWithKey(keyPlace.string(), std::ios::binary);

		if (!fileToDecode.is_open()) {
			std::cout << "Cannot open file to decode: " << filePlace.filename().string();
			exit(0);
		}
		if (!fileWithKey.is_open()) {
			std::cout << "Cannot open file with key: " << keyPlace.filename().string();
			exit(0);
		}

		DES_cblock key;
		fileWithKey.read((char *)key, file_size(keyPlace));

		DES_key_schedule key_schedule;
		DES_set_key_checked(&key, &key_schedule);

		DES_cblock ivec;
		memset((char*)&ivec, 0, sizeof(ivec));

		char *inputData = new char[file_size(filePlace)];
		char *outputData = new char[file_size(filePlace)];
		memset(inputData, 0, file_size(filePlace));
		memset(outputData, 0, file_size(filePlace));
		fileToDecode.read(inputData, file_size(filePlace));

		DES_ncbc_encrypt((unsigned char *)inputData, (unsigned char *)outputData, 
			             file_size(filePlace), &key_schedule, &ivec, DES_DECRYPT);

		std::stringstream outputDataStream(outputData);
		std::string newFileName;
		std::string size;


		//Loop for file data
		while (std::getline(outputDataStream, newFileName)) {

			std::getline(outputDataStream, size);
			int fileSize = std::stoi(size);

			std::string newData;
			newData.resize(fileSize + 1);
			outputDataStream.read(&newData[0], fileSize);


			std::ofstream outputFile;

			//if on Linux
			if (filePlace.parent_path().string()[0] == '/') {
				outputFile.open(filePlace.parent_path().string() + "/" + newFileName,
				    			std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
			}
			else {
				outputFile.open(filePlace.parent_path().string() + "\\" + newFileName,
				             	std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
			}

			if (!outputFile.is_open()) {
				std::cout << "Cannot create new file: " << newFileName;
				exit(0);
			}


			//If it`s an image then decode back
			path p(newFileName);
			if (p.extension() != ".txt") {

				char *decoded_image = new char[fileSize + 1];
				bn::decode_b16(newData.begin(), newData.end(), decoded_image);

				outputFile.write(decoded_image, fileSize);
			}
			else {

				outputFile.write(&newData[0], fileSize);
			}

			outputFile.close();
		}


		fileToDecode.close();
		fileWithKey.close();

		delete[] inputData;
		delete[] outputData;
	}
示例#18
0
void __copy(const path& from, const path& to, copy_options options,
            std::error_code *ec)
{
    const bool sym_status = bool(options &
        (copy_options::create_symlinks | copy_options::skip_symlinks));

    const bool sym_status2 = bool(options &
        copy_options::copy_symlinks);

    std::error_code m_ec;
    struct ::stat f_st = {};
    const file_status f = sym_status || sym_status2
                                     ? detail::posix_lstat(from, f_st, &m_ec)
                                     : detail::posix_stat(from,  f_st, &m_ec);
    if (m_ec)
        return set_or_throw(m_ec, ec, "copy", from, to);

    struct ::stat t_st = {};
    const file_status t = sym_status ? detail::posix_lstat(to, t_st, &m_ec)
                                     : detail::posix_stat(to, t_st, &m_ec);

    if (not status_known(t))
        return set_or_throw(m_ec, ec, "copy", from, to);

    if (!exists(f) || is_other(f) || is_other(t)
        || (is_directory(f) && is_regular_file(t))
        || detail::stat_equivalent(f_st, t_st))
    {
        return set_or_throw(make_error_code(errc::function_not_supported),
                            ec, "copy", from, to);
    }

    if (ec) ec->clear();

    if (is_symlink(f)) {
        if (bool(copy_options::skip_symlinks & options)) {
            // do nothing
        } else if (not exists(t)) {
            __copy_symlink(from, to, ec);
        } else {
            set_or_throw(make_error_code(errc::file_exists),
                         ec, "copy", from, to);
        }
        return;
    }
    else if (is_regular_file(f)) {
        if (bool(copy_options::directories_only & options)) {
            // do nothing
        }
        else if (bool(copy_options::create_symlinks & options)) {
            __create_symlink(from, to, ec);
        }
        else if (bool(copy_options::create_hard_links & options)) {
            __create_hard_link(from, to, ec);
        }
        else if (is_directory(t)) {
            __copy_file(from, to / from.filename(), options, ec);
        } else {
            __copy_file(from, to, options, ec);
        }
        return;
    }
    else if (is_directory(f) && bool(copy_options::create_symlinks & options)) {
        return set_or_throw(make_error_code(errc::is_a_directory), ec, "copy");
    }
    else if (is_directory(f) && (bool(copy_options::recursive & options) ||
             copy_options::none == options)) {

        if (!exists(t)) {
            // create directory to with attributes from 'from'.
            __create_directory(to, from, ec);
            if (ec && *ec) { return; }
        }
        directory_iterator it = ec ? directory_iterator(from, *ec)
                                   : directory_iterator(from);
        if (ec && *ec) { return; }
        std::error_code m_ec;
        for (; it != directory_iterator(); it.increment(m_ec)) {
            if (m_ec) return set_or_throw(m_ec, ec, "copy", from, to);
            __copy(it->path(), to / it->path().filename(),
                   options | copy_options::__in_recursive_copy, ec);
            if (ec && *ec) { return; }
        }
    }
}
示例#19
0
文件: adbr.cpp 项目: arucard21/AniDB
void process_file(const options *adbr_opt, path &fpath)
{
  long fdate = last_write_time(fpath);
  ulong fsize = file_size(fpath);
  uint fid = 0;
  char ed2k[33];
  adbr_attr attrib;

  bool hash_req = false,
       ident_req = true;

  if(adbr_opt->use_repository)
  {
    printf("\tSearching repository...\t\t");

    adbr_entry e;
    if((adbr_opt->use_dates && repos->search_hash(fsize, fdate, &e)) ||
       (repos->search_hash(fsize, &e)))
    {
      strcpy(ed2k, e.ed2k);
      fid = e.fileid;

      printf("Found (%s|%lu)\n", ed2k, fsize);
    }
    else
    {
      hash_req = true;
      printf("Failed\n");
    }
  }

  if((!adbr_opt->use_repository && !adbr_opt->rename &&
      !adbr_opt->add_mylist && !adbr_opt->move) ||
     (fid && !adbr_opt->rename && !adbr_opt->move))
  {
    ident_req = false;
  }

  if(hash_req)
  {
    printf("\tHashing...\t\t\t");
    ed2k_hash(fpath.string().c_str(), ed2k);
    printf("Done (%s)\n", ed2k);

    if(adbr_opt->use_repository)
    {
      repos->insert_hash(fsize, ed2k, fdate);
    }
  }

  if(ident_req)
  {
    printf("\tIdentifying file...\t\t");

    if((fid && adbc->file(attrib, fid)) ||
      (!fid && adbc->file(attrib, ed2k, fsize)))
    {
      if(adbr_opt->romaji)
        attrib["PREFERRED_NAME"] = attrib["ANIME_ROMAJI"];
      else
        attrib["PREFERRED_NAME"] = attrib["ANIME_ENGLISH"];

      sscanf(attrib["FID"].c_str(), "%u", &fid);

      if(adbr_opt->use_repository)
        repos->update_hash(fsize, fdate, fid);

      printf("Done (%u)\n", fid);
    }
    else
    {
      printf("Failed\n");
      return;
    }
  }

  if(adbr_opt->rename || adbr_opt->move)
  {
    printf("\tRenaming file...\t\t");

    string str;

    if(adbr_opt->rename)
    {
      str = adbr_opt->format;

      if(!attrib["ANIME_TYPE"].compare("Film"))
      {
        if(attrib["EPISODE_NAME"].find("0123456789") == string::npos)
        {
          str = adbr_opt->format_yn;
        }
        else
        {
          str = adbr_opt->format_y;
        }
      }
      else if(!attrib["ANIME_TYPE"].compare("OVA") ||
              !attrib["ANIME_TYPE"].compare("TV Special"))
      {
        if(!attrib["EPISODE_TOTAL"].compare("1"))
        {
          if(attrib["EPISODE_NAME"].find("OVA") == string::npos)
          {
            str = adbr_opt->format_ye;
          }
          else
          {
            str = adbr_opt->format_y;
          }
        }
      }

      for(size_t i = 0; i < str.length(); i++)
      {
        size_t st;
        if(str.at(i) == '%')
        {
          st = i;
          while(++i < str.length())
          {
            if(str.at(i) != '%')
            {
              continue;
            }
            else
            {
              string at = str.substr(st+1, i-st-1);
              if(attrib.count(at.c_str()))
              {
                string r = attrib[at.c_str()];
                str.replace(st, i-st+1, r);
                i = st+r.length();
//              printf("after:  %s (<- %s)\n", str->c_str(), at.c_str());
              }
              else
              {
                printf("|%s| is not a valid token\n", at.c_str());
              }
            }
            break;
          }
        }
      }

      boost::algorithm::trim(str);
    }
    else
    {
      str = fpath.filename();
    }

    path fnew = fpath.parent_path();

    if(adbr_opt->move)
    {
      fnew = adbr_opt->animeroot;

      if(adbr_opt->wstatus)
      {
        size_t viewdate = 0;

        adbr_attr file_att;

        if(adbc->myfile(file_att, fid))
        {
          sscanf(file_att["VIEWDATE"].c_str(), "%u", &viewdate);
        }

        if(viewdate)
        {
          fnew /= "watched";
        }
        else
        {
          fnew /= "unwatched";
        }
      }

      fnew /= attrib["PREFERRED_NAME"];
      if(!exists(fnew))
      {
        if(!create_directories(fnew))
        {
          printf("Failed to create parent (%s) | ", fnew.file_string().c_str());
        }
      }

      fnew /= str;
    }
    else
    {
      fnew = fpath.parent_path() / str;
    }

    if(exists(fnew))
    {
      printf("Already exists (%s)\n", fnew.file_string().c_str());
    }
    else
    {
      rename(fpath, fnew);
      if(exists(fnew))
      {
        printf("Done (%s)\n", fnew.filename().c_str());
      }
      else
      {
        printf("Failed (%s)\n", fnew.file_string().c_str());
      }
    }
  }

  if(adbr_opt->add_mylist)
  {
    printf("\tAdding to mylist...\t\t");

    if((fid && adbc->mylistadd(fid, adbr_opt)) ||
      (!fid && adbc->mylistadd(ed2k, fsize, adbr_opt)))
    {
      printf("Done\n");
    }
    else
    {
      printf("Failed\n");
    }
  }
}
示例#20
0
文件: FsUtil.cpp 项目: JacobMao/folly
path canonical_parent(const path& pth, const path& base) {
  return canonical(pth.parent_path(), base) / pth.filename();
}
示例#21
0
void get_files_in_dir(const std::string &dir,
                      std::vector<std::string>* files,
                      std::vector<std::string>* dirs,
                      file_name_option mode,
                      file_filter_option filter,
                      file_reorder_option reorder,
                      file_tree_checksum* checksum) {
	if(path(dir).is_relative() && !game_config::path.empty()) {
		path absolute_dir(game_config::path);
		absolute_dir /= dir;
		if(is_directory_internal(absolute_dir)) {
			get_files_in_dir(absolute_dir.string(), files, dirs, mode, filter, reorder, checksum);
			return;
		}
	}

	const path dirpath(dir);

	if (reorder == DO_REORDER) {
		LOG_FS << "searching for _main.cfg in directory " << dir << '\n';
		const path maincfg = dirpath / maincfg_filename;

		if (file_exists(maincfg)) {
			LOG_FS << "_main.cfg found : " << maincfg << '\n';
			push_if_exists(files, maincfg, mode == ENTIRE_FILE_PATH);
			return;
		}
	}

	error_code ec;
	bfs::directory_iterator di(dirpath, ec);
	bfs::directory_iterator end;
	if (ec) {
		// Probably not a directory, let the caller deal with it.
		return;
	}
	for(; di != end; ++di) {
		bfs::file_status st = di->status(ec);
		if (ec) {
			LOG_FS << "Failed to get file status of " << di->path().string() << ": " << ec.message() << '\n';
			continue;
		}
		if (st.type() == bfs::regular_file) {
			{
				std::string basename = di->path().filename().string();
				if (filter == SKIP_PBL_FILES && looks_like_pbl(basename))
					continue;
				if(!basename.empty() && basename[0] == '.' )
					continue;
			}
			push_if_exists(files, di->path(), mode == ENTIRE_FILE_PATH);

			if (checksum != NULL) {
				std::time_t mtime = bfs::last_write_time(di->path(), ec);
				if (ec) {
					LOG_FS << "Failed to read modification time of " << di->path().string() << ": " << ec.message() << '\n';
				} else if (mtime > checksum->modified) {
					checksum->modified = mtime;
				}

				uintmax_t size = bfs::file_size(di->path(), ec);
				if (ec) {
					LOG_FS << "Failed to read filesize of " << di->path().string() << ": " << ec.message() << '\n';
				} else {
					checksum->sum_size += size;
				}
				checksum->nfiles++;
			}
		} else if (st.type() == bfs::directory_file) {
			std::string basename = di->path().filename().string();
			
			if(!basename.empty() && basename[0] == '.' )
				continue;
			if (filter == SKIP_MEDIA_DIR
				&& (basename == "images" || basename == "sounds"))
				continue;

			const path inner_main(di->path() / maincfg_filename);
			bfs::file_status main_st = bfs::status(inner_main, ec);
			if (error_except_not_found(ec)) {
				LOG_FS << "Failed to get file status of " << inner_main.string() << ": " << ec.message() << '\n';
			} else if (reorder == DO_REORDER && main_st.type() == bfs::regular_file) {
				LOG_FS << "_main.cfg found : " << (mode == ENTIRE_FILE_PATH ? inner_main.string() : inner_main.filename().string()) << '\n';
				push_if_exists(files, inner_main, mode == ENTIRE_FILE_PATH);
			} else {
				push_if_exists(dirs, di->path(), mode == ENTIRE_FILE_PATH);
			}
		}
	}

	if (files != NULL)
		std::sort(files->begin(),files->end());

	if (dirs != NULL)
		std::sort(dirs->begin(),dirs->end());

	if (files != NULL && reorder == DO_REORDER) {
		// move finalcfg_filename, if present, to the end of the vector
		for (unsigned int i = 0; i < files->size(); i++) {
			if (ends_with((*files)[i], "/" + finalcfg_filename)) {
				files->push_back((*files)[i]);
				files->erase(files->begin()+i);
				break;
			}
		}
		// move initialcfg_filename, if present, to the beginning of the vector
		int foundit = -1;
		for (unsigned int i = 0; i < files->size(); i++)
			if (ends_with((*files)[i], "/" + initialcfg_filename)) {
				foundit = i;
				break;
			}
		if (foundit > 0) {
			std::string initialcfg = (*files)[foundit];
			for (unsigned int i = foundit; i > 0; i--)
				(*files)[i] = (*files)[i-1];
			(*files)[0] = initialcfg;
		}
	}
}
示例#22
0
int main(int argc, char* argv[])
{
	if (argc != 5)
	{
		std::cout << "combinelog slices_folder prefix 16_prop_350.xls out.csv\n";
		return 1;
	}

	const path slices = argv[1];
	const string prefix = argv[2];
	const path prop = argv[3];
	const path output_csv = argv[4];

	string line;
	line.reserve(600);

	std::cout << "Reading log.csv's." << std::endl;
	vector<record> records;
	records.reserve(80000);
	const directory_iterator end_dir_iter;
	for (directory_iterator dir_iter(slices); dir_iter != end_dir_iter; ++dir_iter)
	{
		if (!is_directory(dir_iter->status())) continue; // Find example directories.
		const path slice_path = dir_iter->path();
		const string fullslice = slice_path.filename().string();
		if (!starts_with(fullslice, prefix)) continue;
		std::cout << fullslice << '\n';
		const string slice = fullslice.substr(6);
		ifstream log(slice_path / "log.csv");
		getline(log, line); // Filter out header line.
		while (getline(log, line))
		{
			records.push_back(record(static_cast<string&&>(line), slice));
		}
	}

	const size_t num_records = records.size();
	std::cout << "Sorting " << num_records << " records." << std::endl;
	std::sort(records.begin(), records.end());

	std::cout << "Reading property xls file " << prop << '.' << std::endl;
	vector<property> properties;
	properties.reserve(7220928); // Number of molecules in 16_prop_350.xls
	ifstream xls(prop);
	getline(xls, line); // Filter out header line.
	while (getline(xls, line))
	{
		properties.push_back(property(static_cast<string&&>(line)));
	}
	xls.close();
	std::cout << properties.size() << " records in prop xls file." << std::endl;

	std::cout << "Writing combined csv to " << output_csv << std::endl;
	ofstream csv(output_csv);
	csv << "Slice,Ligand,Conf,FE1,HB1,FE2,HB2,FE3,HB3,FE4,HB4,FE5,HB5,FE6,HB6,FE7,HB7,FE8,HB8,FE9,HB9,HA,MWT,LogP,Desolv_apolar,Desolv_polar,HBD,HBA,tPSA,Charge,NRB,SMILES\n";
	size_t s, e, num_not_found = 0;
	for (size_t i = 0; i < num_records; ++i)
	{
		const record& r = records[i];
		const string id = r.line.substr(4, 8);
		csv << r.slice << ',' << id << ',' << r.line.substr(r.comma + 1);
		const property& p = properties[binary(properties, id)];
		if (id != p.id)
		{
			//std::cerr << id << ' '  << p.id;
			++num_not_found;
			csv << ",,,,,,,,,,,,,,,,,,,\n";
			continue;
		}
		s = 13;
		for (size_t j = 0; j < 10; ++j) // 9 properties, i.e. HA,MWT,LogP,Desolv_apolar,Desolv_polar,HBD,HBA,tPSA,Charge,NRB
		{
			e = p.line.find_first_of('\t', s + 1);
			csv << ',' << p.line.substr(s, e - s);
			s = e + 1;
		}
		csv << ',' << p.line.substr(s) << '\n'; // SMILES
	}
	csv.close();
	std::cout << num_not_found << " records in log.csv's but not in prop xls file." << std::endl;

	return 0;
}