예제 #1
0
string HTMLEditor::CreateImage(const IImageCPtr & image, const path & imgPath)
{
    auto imgDirPath = path(IMAGES);
    auto relativePath = imgDirPath / path(image->GetPath()).filename();
    create_directories(imgPath.parent_path() / imgDirPath);
    copy_file(image->GetPath(), imgPath.parent_path() / relativePath, copy_option::overwrite_if_exists);
    return "\t<img src='" + EncodeHtmlStr(relativePath.generic_string()) + "' height=" + to_string(image->GetHeight())+ " width=" + to_string(image->GetWidth()) + ">\n";
}
예제 #2
0
const long Zip ( const BEValueList<std::string> * filenames, const StringAutoPtr archive )
{
    long error = 0;
	
	const path file = filenames->first();
	const path archive_path = *archive;
	
	if ( archive->empty() || exists ( archive_path.parent_path() ) ) {
		
		if ( archive->empty() ) {
			*archive = file.string() + ".zip";
		}
		
		zipFile zip_file;
		const bool dont_overwrite = APPEND_STATUS_CREATE;
		
		zip_file = zipOpen64 ( archive->c_str(), dont_overwrite );
		
		if ( zip_file == NULL ) {
			error = ZIP_ERRNO;
		} else {
			
			for ( size_t i = 0 ; i < filenames->size() ; i++ ) {

				path file_to_archive = filenames->at ( i );
				
				if ( exists ( file_to_archive ) ) {
					error = AddToArchive ( file_to_archive, zip_file, file.parent_path() );
				} else {
					error = kNoSuchFileOrDirectoryError;
					break;
				}
			
			}
		}
		
		// only worry about an error closing the file if there hasn't already been one
		int close_error = zipClose ( zip_file, NULL );
		if ( error == kNoError ) {
			error = close_error;
		}
		
	} else {
		error = kNoSuchFileOrDirectoryError;
	}
	
    return error;
	
} // Zip
/// \brief TODOCUMENT
pair<alignment, superpose_orderer> ssap_scores_file_alignment_acquirer::do_get_alignment_and_orderer(const pdb_list &arg_pdbs ///< TODOCUMENT
                                                                                                     ) const {
	// Parse the SSAP scores file
	const path                     ssap_scores_file = get_ssap_scores_file();
	const pair<str_vec, size_size_pair_doub_map> ssap_scores_data = ssap_scores_file::parse_ssap_scores_file( ssap_scores_file );
	const str_vec                 &names            = ssap_scores_data.first;
	const size_size_pair_doub_map &scores           = ssap_scores_data.second;

	if ( names.size() != arg_pdbs.size() ) {
		BOOST_THROW_EXCEPTION(runtime_error_exception(
			"The number of PDBs is "
			+ ::std::to_string( arg_pdbs.size()         )
			+ ", which doesn't match the "
			+ ::std::to_string( names.size() )
			+ " structures required for combining with the SSAP scores file \""
			+ ssap_scores_file.string()
			+ "\""
		));
	}

	// Make a superpose_orderer from the scores
	const superpose_orderer my_orderer = make_superpose_orderer( scores );

	// Use the superpose_orderer code to get a spanning tree, ordered in descending order of score
	const size_size_pair_vec spanning_tree = get_spanning_tree_ordered_by_desc_score( scores );

//	// TODOCUMENT
	ostringstream stderr;
	const size_size_alignment_tuple_vec spanning_alignments = get_spanning_alignments(
		ssap_scores_file.parent_path(),
		names,
		arg_pdbs,
		spanning_tree,
		stderr
	);

	// TODOCUMENT
	const bool      single_pdb    = ( arg_pdbs.size() == 1 );
	const alignment new_alignment = single_pdb ? make_single_alignment( front( arg_pdbs ).get_num_residues() )
	                                           : build_alignment_from_parts( spanning_alignments, build_protein_list_of_pdb_list( arg_pdbs ) );

	if ( names.size() == 0 ) {
		// Return the results
		return make_pair( new_alignment, my_orderer );
	}

//	BOOST_LOG_TRIVIAL( warning )<< "About to attempt to build protein list using data that's been read from ssap_scores_file (with " << arg_pdbs.size() << " pdbs and " << names.size() << " names)";

	const protein_list proteins_of_pdbs     = build_protein_list_of_pdb_list_and_names( arg_pdbs, names );
	const alignment    scored_new_alignment = score_alignment_copy( residue_scorer(), new_alignment, proteins_of_pdbs );


//	cerr << "Did generate alignment : \n";
//	cerr << horiz_align_outputter( scored_new_alignment ) << endl;
//	write_alignment_as_fasta_alignment( cerr, scored_new_alignment, build_protein_list_of_pdb_list( arg_pdbs ) );
//	cerr << endl;

	// Return the results
	return make_pair( scored_new_alignment, my_orderer );
}
예제 #4
0
CTLProcessParams<CTLPlugin::Scalar> CTLPlugin::getProcessParams( const OfxPointD& renderScale ) const
{
	using namespace boost::filesystem;
	CTLProcessParams<Scalar> params;
	params._inputType = static_cast<EParamChooseInput>( _paramInput->getValue() );
	switch( params._inputType )
	{
		case eParamChooseInputCode:
		{
			params._module = "inputCode";
			params._code = _paramCode->getValue();
			break;
		}
		case eParamChooseInputFile:
		{
//			std::ifstream f( _paramFile->getValue().c_str(), std::ios::in );
//			std::getline( f, params._code, '\0' );
//			split( params._paths, paths, is_any_of(":;"), token_compress_on );
			const path filename = path( _paramFile->getValue() );
			params._module = filename.stem().string();
			params._paths.push_back( filename.parent_path().string() );
			break;
		}
	}
	return params;
}
예제 #5
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);
}
/// \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 );
	}
}
예제 #7
0
bool __create_directories(const path& p, std::error_code *ec)
{
    std::error_code m_ec;
    auto const st = detail::posix_stat(p, &m_ec);
    if (!status_known(st)) {
        set_or_throw(m_ec, ec, "create_directories", p);
        return false;
    }
    else if (is_directory(st)) {
        if (ec) ec->clear();
        return false;
    }
    else if (exists(st)) {
        set_or_throw(make_error_code(errc::file_exists),
                     ec, "create_directories", p);
        return false;
    }

    const path parent = p.parent_path();
    if (!parent.empty()) {
        const file_status parent_st = status(parent, m_ec);
        if (not status_known(parent_st)) {
            set_or_throw(m_ec, ec, "create_directories", p);
            return false;
        }
        if (not exists(parent_st)) {
            __create_directories(parent, ec);
            if (ec && *ec) { return false; }
        }
    }
    return __create_directory(p, ec);
}
예제 #8
0
/// \brief TODOCUMENT
bool options_block::is_acceptable_output_file(const path &arg_output_file ///< TODOCUMENT
                                              ) {
	if (exists(arg_output_file) && !is_regular_file(arg_output_file)) {
		return false;
	}
	if (arg_output_file.has_parent_path() && !is_directory(arg_output_file.parent_path())) {
		return false;
	}
	return true;
}
예제 #9
0
vector<path> get_includes(path file, set<path>& touched_files){
	debug(3,"reading dependencies for „"+file.string()+"“");
	if( touched_files.count(file) ){
		debug(4, "\tfile is already known");
		return vector<path>();
	}
	else{
		touched_files.insert(file);
	}
	vector<path> includes;
	string line;
	ifstream filestream(file.c_str());
	path file_dir=file.parent_path();
	while(getline(filestream,line)){
		line = strip(line);
		if(!line.empty() && line[0]=='#' && strip(line.substr(1)).find("include")==0){
			line.erase(0,sizeof("#include"));
			line = strip(line);
			if(line[0]!='"') continue;
			line.erase(0,1);
			size_t pos;
			if((pos=line.find('"'))==string::npos) continue;
			line.erase(pos);
			
			path include=clean_path(file_dir/path(line));
			if(std::find(settings::header_files.begin(),
			             settings::header_files.end(),include)
			   == settings::header_files.end()
			){
				if(std::find(
					settings::implementation_files.begin(),
					settings::implementation_files.end(),
					include)
				   == settings::implementation_files.end()
				){
					continue;
				}
			}
			includes.push_back(include);
		}
	}
	vector<path> secondary_includes, tmp;
	for(auto i:includes){
		tmp=get_includes(i, touched_files);
		secondary_includes.insert(secondary_includes.end(),
		                          tmp.begin(),tmp.end());
	}
	includes.insert(includes.end(),secondary_includes.begin(),
	                secondary_includes.end());
	return includes;
}
예제 #10
0
inline bool create_directories(const path & p) {
	
	if(p.empty()) {
		return true;
	}
	
	path parent = p.parent_path();
	if(!exists(parent)) {
		if(!create_directories(parent)) {
			return false;
		}
	}
	
	return create_directory(p);
}
예제 #11
0
파일: fs.cpp 프로젝트: rcombs/Aegisub
void Touch(path const& file) {
    CreateDirectory(file.parent_path());

    SYSTEMTIME st;
    FILETIME ft;
    GetSystemTime(&st);
    if(!SystemTimeToFileTime(&st, &ft))
        throw EnvironmentError("SystemTimeToFileTime failed with error: " + util::ErrorString(GetLastError()));

    scoped_holder<HANDLE, BOOL (__stdcall *)(HANDLE)>
    h(CreateFile(file.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr), CloseHandle);
    // error handling etc.
    if (!SetFileTime(h, nullptr, nullptr, &ft))
        throw EnvironmentError("SetFileTime failed with error: " + util::ErrorString(GetLastError()));
}
예제 #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 << ".";
	}
}
예제 #13
0
int main()
{
  using namespace fs;
  for (auto const & TC : TestCases) {
    path const p_orig(TC.value);
    path p(p_orig);
    assert(p == TC.value);
    path& Ref = (p.remove_filename());
    assert(p == TC.expect);
    assert(&Ref == &p);
    {
      const path parentp = p_orig.parent_path();
      if (parentp == p_orig.root_name()) {

        assert(p.empty());
      } else {
        assert(p == parentp);
      }
    }
  }
}
예제 #14
0
파일: filepath.cpp 프로젝트: berenm/xoreos
static UString findSubDirectory_internal(const UString &directory, const UString &subDirectory,
		bool caseInsensitive) {

	try {
		// Special case: . is the same, current directory
		if (subDirectory == UString("."))
			return directory;

		const path dirPath(directory.c_str());

		// Special case: .. is the parent directory
		if (subDirectory == UString("..")) {
			path parent = dirPath.parent_path();
			if (parent == dirPath)
				return "";

			return parent.generic_string();
		}

		// Iterator over the directory's contents
		directory_iterator itEnd;
		for (directory_iterator itDir(dirPath); itDir != itEnd; ++itDir) {
			if (is_directory(itDir->status())) {
				// It's a directory. Check if it's the one we're looking for

				if (caseInsensitive) {
					if (iequals(itDir->path().filename().string(), subDirectory.c_str()))
						return itDir->path().generic_string();
				} else {
					if (equals(itDir->path().filename().string(), subDirectory.c_str()))
						return itDir->path().generic_string();
				}
			}
		}
	} catch (...) {
	}

	return "";
}
예제 #15
0
void HTMLEditor::Save(const path & path)
{
    if (path.empty())
    {
        throw runtime_error("Path cannot be empty!");
    }

    if (path.has_parent_path())
    {
        create_directories(path.parent_path());
    }

    std::ofstream file(path.generic_string());

    if (!file.is_open())
    {
        throw runtime_error("Invalid path specified" + path.generic_string());
    }

    file << "<!DOCTYPE html>\n<html>\n<head>\n\t<title>" << EncodeHtmlStr(m_document.GetTitle()) << "</title>\n</head>\n"
        << "<body>\n" << CreateBody(path) << "</body>\n</html>";
    file.close();
}
예제 #16
0
static bool create_directory_if_missing_recursive(const path& dirpath)
{
	DBG_FS << "creating recursive directory: " << dirpath.string() << '\n';

	if (dirpath.empty())
		return false;
	error_code ec;
	bfs::file_status fs = bfs::status(dirpath);
	if (error_except_not_found(ec)) {
		ERR_FS << "Failed to retrieve file status for " << dirpath.string() << ": " << ec.message() << '\n';
		return false;
	} else if (bfs::is_directory(fs)) {
		return true;
	} else if (bfs::exists(fs)) {
		return false;
	}

	if (!dirpath.has_parent_path() || create_directory_if_missing_recursive(dirpath.parent_path())) {
		return create_directory_if_missing(dirpath);
	} else {
		ERR_FS << "Could not create parents to " << dirpath.string() << '\n';
		return false;
	}
}
예제 #17
0
string albumFromPath(const path& p,regex& r) {
	return regex_replace(p.parent_path().filename(),r," ");
}
예제 #18
0
파일: FsUtil.cpp 프로젝트: JacobMao/folly
path canonical_parent(const path& pth, const path& base) {
  return canonical(pth.parent_path(), base) / pth.filename();
}
예제 #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
파일: kat_fs.hpp 프로젝트: emmaggie/KAT
        /**
         * 
         * @param exe Full path to the exe, probably derived from argv0.
         */
        KatFS(const char* argv) {
            
            path exe(argv);
            
            //cout << exe << endl;
            
            if(exe.is_absolute()) {
                
                //cout << "Absolute" << endl;
                
                // Easy job... nothing special to do, resolve symlink then take two levels up
                katExe = fs::canonical(exe);
                rootDir = katExe.parent_path().parent_path();
            }
            else if (exe.string().find('/') != string::npos) {
                
                //cout << "Relative" << endl;
                
                // Relative with some parent paths... get absolute path, resolving symlinks then take two levels up
                katExe = fs::canonical(fs::system_complete(exe));
                rootDir = katExe.parent_path().parent_path();
            }
            else {

                //cout << "name only" << endl;
                
                // Tricky one... just exe name, no indication of where if comes from. Now we have to resort to using which.
                string cmd = string("which ") + exe.string();
                string res = exec(cmd.c_str());
                string fullpath = res.substr(0, res.length() - 1);

                //cout << "fullpath" << fullpath << endl;
                katExe = fs::canonical(path(fullpath));
                rootDir = katExe.parent_path().parent_path();
            }
            
            binDir = path(rootDir);
            binDir /= "bin";
            
            libsDir = path(rootDir);
            libsDir /= ".libs";
            
            path srcDir = path(rootDir);
            srcDir /= "src";
            
            path testDir = path(rootDir);
            testDir /= "tests";
                            
            if (katExe.parent_path() == srcDir || katExe.parent_path() == libsDir || katExe.parent_path() == testDir) {
                scriptsDir = path(rootDir);
                scriptsDir /= "scripts";                 
            }
            else {
                scriptsDir = path(binDir);
            }
            
            if (!exists(scriptsDir)) {
                BOOST_THROW_EXCEPTION(FileSystemException() << FileSystemErrorInfo(string(
                    "Could not find suitable directory containing KAT scripts at: ") + scriptsDir.c_str()));
            }
            
        }
예제 #21
0
string Routines::GetBinDirectory()
{
	return binFilePath.parent_path().generic_string();
}
예제 #22
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;
	}