コード例 #1
0
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  -----
コード例 #2
0
/*
 * Deal the stacks into separated files and append them.
 */
void dealStack(const fs::path &outdir, const std::string &prefix,
               const fs::path &imgPath,
               const uint16_t nLayer) {
	TIFF *in, *out;
    static uint16_t iLayer = 0;

    // Suppress the warnings.
	TIFFErrorHandler oldhandler = TIFFSetWarningHandler(NULL);

	// Open the file.
	in = TIFFOpen(imgPath.string().c_str(), "r");
	if (in == NULL) {
		std::cerr << "Unable to read " << imgPath.filename() << std::endl;
		return;
	}

    // Identify the read mode.
	static char mode[3] = { 'x', 'b', 0 };
    // Overwrite on the first run, and append for rest of the page.
    mode[0] = (mode[0] == 'x') ? 'w' : 'a';
    mode[1] = (TIFFIsBigEndian(in)) ? 'b' : 'l';

	// Iterate through the directories.
	int iFile = 0;
	do {
        std::string s = genPath(outdir, prefix, iFile);
		out = TIFFOpen(s.c_str(), mode);
        try {
    		if (out == NULL) {
                throw -1;
    		} else if (!cpTiff(in, out, iLayer, nLayer)) {
                throw -2;
    		}
        } catch (int e) {
            if (e == -1) {
                std::cerr << "Unable to create output file" << std::endl;
            } else if (e == -2) {
                std::cerr << "Unable to copy the layer" << std::endl;
            } else {
                std::cerr << "Unknown error" << std::endl;
            }
            TIFFClose(in);
            TIFFClose(out);
            return;
        }
		TIFFClose(out);
		iFile++;
	} while (TIFFReadDirectory(in));

    // Increment the layer variable for next write.
    iLayer++;

	TIFFClose(in);

    // Restore the warning.
	TIFFSetWarningHandler(oldhandler);
}
コード例 #3
0
ファイル: quickbook.cpp プロジェクト: cpascal/af-cpp
    static int
    parse_document(
        fs::path const& filein_
      , fs::path const& fileout_
      , fs::path const& deps_out_
      , fs::path const& locations_out_
      , fs::path const& xinclude_base_
      , int indent
      , int linewidth
      , bool pretty_print)
    {
        string_stream buffer;
        id_manager ids;

        int result = 0;

        try {
            quickbook::state state(filein_, xinclude_base_, buffer, ids);
            set_macros(state);

            if (state.error_count == 0) {
                state.add_dependency(filein_);
                state.current_file = load(filein_); // Throws load_error

                parse_file(state);

                if(state.error_count) {
                    detail::outerr()
                        << "Error count: " << state.error_count << ".\n";
                }
            }

            result = state.error_count ? 1 : 0;

            if (!deps_out_.empty())
            {
                fs::ofstream out(deps_out_);
                BOOST_FOREACH(quickbook::state::dependency_list::value_type
                        const& d, state.dependencies)
                {
                    if (d.second) {
                        out << detail::path_to_generic(d.first) << std::endl;
                    }
                }
            }

            if (!locations_out_.empty())
            {
                fs::ofstream out(locations_out_);
                BOOST_FOREACH(quickbook::state::dependency_list::value_type
                        const& d, state.dependencies)
                {
                    out << (d.second ? "+ " : "- ")
                        << detail::path_to_generic(d.first) << std::endl;
                }
            }
コード例 #4
0
// Functor operator, gets invoked on directory traversal
void ModuleLoader::processModuleFile(const fs::path& file)
{
	// Check for the correct extension of the visited file
	if (string::to_lower_copy(file.extension().string()) != MODULE_FILE_EXTENSION) return;

	std::string fullName = file.string();
	rConsole() << "ModuleLoader: Loading module '" << fullName << "'" << std::endl;

	// Create the encapsulator class
	DynamicLibraryPtr library = std::make_shared<DynamicLibrary>(fullName);

	// greebo: Try to find our entry point and invoke it and add the library to the list
	// on success. If the load fails, the shared pointer won't be added and
	// self-destructs at the end of this scope.
	if (library->failed())
	{
		rError() << "WARNING: Failed to load module " << library->getName() << ":" << std::endl;

#ifdef __linux__
		rConsoleError() << dlerror() << std::endl;
#endif
		return;
	}

	// Library was successfully loaded, lookup the symbol
	DynamicLibrary::FunctionPointer funcPtr(
		library->findSymbol(SYMBOL_REGISTER_MODULE)
	);

	if (funcPtr == nullptr)
	{
		// Symbol lookup error
		rError() << "WARNING: Could not find symbol " << SYMBOL_REGISTER_MODULE
			<< " in module " << library->getName() << ":" << std::endl;
		return;
	}

	// Brute-force conversion of the pointer to the desired type
	RegisterModulesFunc regFunc = reinterpret_cast<RegisterModulesFunc>(funcPtr);

	try
	{
		// Call the symbol and pass a reference to the ModuleRegistry
		// This method might throw a ModuleCompatibilityException in its
		// module::performDefaultInitialisation() routine.
		regFunc(ModuleRegistry::Instance());

		// Add the library to the static list (for later reference)
		_dynamicLibraryList.push_back(library);
	}
	catch (module::ModuleCompatibilityException&)
	{
		// Report this error and don't add the module to the _dynamicLibraryList
		rError() << "Compatibility mismatch loading library " << library->getName() << std::endl;
	}
}
コード例 #5
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;
}
コード例 #6
0
ファイル: util.cpp プロジェクト: hungud/bitcoin
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 */
}
コード例 #7
0
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);
        
    }
}
コード例 #8
0
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();
    
}
コード例 #9
0
ファイル: file_pool.cpp プロジェクト: codeboost/libertv
	boost::shared_ptr<file> file_pool::open_file(void* st, fs::path const& p, file::open_mode m)
	{
		assert(st != 0);
		assert(p.is_complete());
		assert(m == file::in || m == (file::in | file::out));
		boost::mutex::scoped_lock l(m_mutex);
		typedef nth_index<file_set, 0>::type path_view;
		path_view& pt = get<0>(m_files);
		path_view::iterator i = pt.find(p);
		if (i != pt.end())
		{
			lru_file_entry e = *i;
			e.last_use = time_now();

			if (e.key != st)
			{
				// this means that another instance of the storage
				// is using the exact same file.
				throw file_error("torrent uses the same file as another torrent "
					"(" + p.string() + ")");
			}

			e.key = st;
			if ((e.mode & m) != m)
			{
				// close the file before we open it with
				// the new read/write privilages
				i->file_ptr.reset();
				assert(e.file_ptr.unique());
				e.file_ptr.reset();
				e.file_ptr.reset(new file(p, m));
				e.mode = m;
			}
			pt.replace(i, e);
			return e.file_ptr;
		}
		// the file is not in our cache
		if ((int)m_files.size() >= m_size)
		{
			// the file cache is at its maximum size, close
			// the least recently used (lru) file from it
			typedef nth_index<file_set, 1>::type lru_view;
			lru_view& lt = get<1>(m_files);
			lru_view::iterator i = lt.begin();
			// the first entry in this view is the least recently used
			assert(lt.size() == 1 || (i->last_use <= boost::next(i)->last_use));
			lt.erase(i);
		}
		lru_file_entry e(boost::shared_ptr<file>(new file(p, m)));
		e.mode = m;
		e.key = st;
		e.file_path = p;
		pt.insert(e);
		return e.file_ptr;
	}
コード例 #10
0
ファイル: MFile.cpp プロジェクト: BackupTheBerlios/japi-svn
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;
}
コード例 #11
0
ファイル: path.cpp プロジェクト: Aegisub/Aegisub
fs::path Path::MakeAbsolute(fs::path path, std::string const& token) const {
	if (path.empty()) return path;
	int idx = find_token(token.c_str(), token.size());
	if (idx == -1) throw agi::InternalError("Bad token: " + token);

	path.make_preferred();
	const auto str = path.string();
	if (boost::starts_with(str, "?dummy") || boost::starts_with(str, "dummy-audio:"))
		return path;
	return (paths[idx].empty() || path.is_absolute()) ? path : paths[idx]/path;
}
コード例 #12
0
ファイル: StarsApp.cpp プロジェクト: rmnzr/Cinder-Samples
shared_ptr<ISound> StarsApp::createSound( const fs::path &path )
{
	shared_ptr<ISound>	sound;

	if(mSoundEngine && !path.empty()) {
		// create sound in a very safe way
		sound = shared_ptr<ISound>( mSoundEngine->play3D( path.string().c_str(), vec3df(0,0,0), false, true ), std::mem_fun(&ISound::drop) );
	}

	return sound;
}
コード例 #13
0
/*******************************************************************
 * Function Name: GetFullImagePath
 * Return Type 	: const fs::path
 * Created On	: Mar 8, 2014
 * Created By 	: hrushi
 * Comments		: Returns the corresponding full image path for the given track image
 * Arguments	:
 *******************************************************************/
const fs::path TrackXML::GetFullImagePath( UINT FrameNum ) const
{
	const fs::path Parentfldr = GetFilePath().parent_path();
	const string FldrName = Parentfldr.stem().string();

	string ImgStemName = StringOp<UINT>::GetString(FrameNum, '0', 5);

	fs::path FullImgPath = Parentfldr.string() + "/full/" +  FldrName + "." + ImgStemName + ".jpeg";

	return FullImgPath;
}
コード例 #14
0
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;
}
コード例 #15
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());
	
}
コード例 #16
0
ファイル: ArgHandler.cpp プロジェクト: haved/DafCompiler
bool tryMakeFilePathReal(FileForParsing& ffp, vector<fs::path> searchDirs) {
    const fs::path dafExt(".daf");
    const fs::path oExt(".o");

    bool done = false;
    std::string attempt(ffp.m_inputName.string());
    bool tryWithDaf = ffp.m_inputName.extension()!=dafExt;
    while(!done) {
        for(unsigned int i = 0; i < searchDirs.size(); i++) {
            fs::path fullAttempt = searchDirs[i]/fs::path(attempt);
            if(isInputFile(fullAttempt)) {
                ffp.m_inputFile = fullAttempt;
                if(!ffp.m_outputFileSet)
                    ffp.m_outputFile = ffp.m_outputFile/attempt;
                done = true;
                break;
            }
            if(tryWithDaf) {
                fullAttempt = fullAttempt.concat(dafExt.string());
                if(isInputFile(fullAttempt)) {
                    ffp.m_inputFile = fullAttempt;
                    if(!ffp.m_outputFileSet)
                        ffp.m_outputFile = ffp.m_outputFile/attempt;
                    done = true;
                    break;
                }
            }
        }
        if(!done) {
            size_t dotPos = attempt.find('.');
            if(dotPos == std::string::npos) { //We never found the file :'(
                break;
            }
            attempt[dotPos] = '/';
        }
    }

    if(!done) {
        return false;
    }

    //Set output file properly
    if(!ffp.m_outputFileSet) {
        ffp.m_outputFileSet = true;
        if(ffp.m_outputFile.extension()==dafExt) {
            ffp.m_outputFile.replace_extension(oExt);
        } else {
            ffp.m_outputFile+=oExt;
        }
    }
    return true;
}
コード例 #17
0
ファイル: fileservice.cpp プロジェクト: patrikha/qdiff
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;
  }
}
コード例 #18
0
ファイル: io.cpp プロジェクト: Aegisub/Aegisub
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);
	}
}
コード例 #19
0
/*******************************************************************
 * 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;
}
コード例 #20
0
void AudioObjApp::loadObject( fs::path filepath )
{
    try {
		ObjLoader loader( DataSourcePath::create( filepath.string() ) );
		TriMesh mesh;
		loader.load( &mesh );
		mVbo = gl::VboMesh( mesh );
	}    
	catch( ... ) {
		console() << "cannot load file: " << filepath.generic_string() << endl;
		return;
	}
}
コード例 #21
0
ファイル: Shader.cpp プロジェクト: Gazoo101/Cinder-Samples
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();
}
コード例 #22
0
ファイル: MFile.cpp プロジェクト: BackupTheBerlios/japi-svn
fs::path relative_path(const fs::path& inFromDir, const fs::path& inFile)
{
//	assert(false);

	fs::path::iterator d = inFromDir.begin();
	fs::path::iterator f = inFile.begin();
	
	while (d != inFromDir.end() and f != inFile.end() and *d == *f)
	{
		++d;
		++f;
	}
	
	fs::path result;
	
	if (d == inFromDir.end() and f == inFile.end())
		result = ".";
	else
	{
		while (d != inFromDir.end())
		{
			result /= "..";
			++d;
		}
		
		while (f != inFile.end())
		{
			result /= *f;
			++f;
		}
	}

	return result;
}
コード例 #23
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"));
}
コード例 #24
0
void
FileCollectionTest::setUp()
{
    fs::remove_all(testFolder);

    fs::create_directory(folderTest);
    fs::create_directory(folderTest/testDirectory);
    {
        ofstream test0(fileTest0.file_string().c_str());
        ofstream test1(fileTest1.file_string().c_str());
        ofstream test2(fileTest2.file_string().c_str());
        ofstream test3(fileTest3.file_string().c_str());
    }

    struct ::utimbuf times;

    times.actime = time(NULL);
    times.modtime = times.actime - 8;
    utime( fileTest0.file_string().c_str(), &times );

    times.actime -= 1;
    times.modtime += 1;
    utime( fileTest1.file_string().c_str(), &times );

    times.actime -= 1;
    times.modtime += 1;
    utime( fileTest2.file_string().c_str(), &times );

    times.actime -= 1;
    times.modtime += 1;
    utime( fileTest3.file_string().c_str(), &times );
}
コード例 #25
0
std::vector<std::string> filestorage::get_file_list(const boost::filesystem::path &path) {
	std::vector<std::string> file_list;
	if (!path.empty()) {
		fs::path apk_path(path);
		fs::recursive_directory_iterator end;

		for (fs::recursive_directory_iterator i(apk_path); i != end; ++i) {
			const fs::path cp = (*i);
			std::string filename = extract_filename(cp.native());
			file_list.push_back(filename);
		}
	}
	return file_list;
}
コード例 #26
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());
}
コード例 #27
0
ファイル: templates.cpp プロジェクト: racktopsystems/kyua
/// Applies a set of templates to an input file and writes an output file.
///
/// \param templates The templates to use.
/// \param input_file The path to the input to process.
/// \param output_file The path to the file into which to write the output.
///
/// \throw text::error If the input or output files cannot be opened.
/// \throw text::syntax_error If there is any problem processing the input.
void
text::instantiate(const templates_def& templates,
                  const fs::path& input_file, const fs::path& output_file)
{
    std::ifstream input(input_file.c_str());
    if (!input)
        throw text::error(F("Failed to open %s for read") % input_file);

    std::ofstream output(output_file.c_str());
    if (!output)
        throw text::error(F("Failed to open %s for write") % output_file);

    instantiate(templates, input, output);
}
コード例 #28
0
ファイル: access.cpp プロジェクト: KagamiChan/Aegisub
/*
This function is still a proof of concept, it's probably rife with bugs, below
is a short (and incomplete) todo
 * "Basic" checks (Read/Write/File/Dir) checks for FAT32 filesystems which
   requires detecting the filesystem being used.
*/
void Check(fs::path const& file, acs::Type type) {
	DWORD file_attr = GetFileAttributes(file.c_str());
	if ((file_attr & INVALID_FILE_ATTRIBUTES) == INVALID_FILE_ATTRIBUTES) {
		switch (GetLastError()) {
			case ERROR_FILE_NOT_FOUND:
			case ERROR_PATH_NOT_FOUND:
				throw fs::FileNotFound(file);
			case ERROR_ACCESS_DENIED:
				throw fs::ReadDenied(file);
			default:
				throw fs::FileSystemUnknownError(str(boost::format("Unexpected error when getting attributes for \"%s\": %s") % file % util::ErrorString(GetLastError())));
		}
	}

	switch (type) {
		case FileRead:
		case FileWrite:
			if ((file_attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
				throw fs::NotAFile(file);
			break;
		case DirRead:
		case DirWrite:
			if ((file_attr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
				throw fs::NotADirectory(file);
			break;
	}

	SECURITY_INFORMATION info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
	DWORD len = 0;
	GetFileSecurity(file.c_str(), info, nullptr, 0, &len);
	if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
		LOG_W("acs/check") << "GetFileSecurity: fatal: " << util::ErrorString(GetLastError());

	std::vector<uint8_t> sd_buff(len);
	SECURITY_DESCRIPTOR *sd = (SECURITY_DESCRIPTOR *)&sd_buff[0];

	if (!GetFileSecurity(file.c_str(), info, sd, len, &len))
		LOG_W("acs/check") << "GetFileSecurity failed: " << util::ErrorString(GetLastError());

	ImpersonateSelf(SecurityImpersonation);
	HANDLE client_token;
	if (!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &client_token))
		LOG_W("acs/check") << "OpenThreadToken failed: " << util::ErrorString(GetLastError());

	if (!check_permission(true, sd, client_token))
		throw fs::ReadDenied(file);
	if ((type == DirWrite || type == FileWrite) && !check_permission(false, sd, client_token))
		throw fs::WriteDenied(file);
}
コード例 #29
0
ファイル: filesystem.cpp プロジェクト: Fuitad/mapcrafter
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;
}
コード例 #30
0
ファイル: Output.cpp プロジェクト: Baron59/boss
	void BossLog::Save(const fs::path file, const bool overwrite) {
		if (fs::exists(file))
			recognisedHasChanged = HasRecognisedListChanged(file);

		ofstream outFile;
		if (overwrite)
			outFile.open(file.c_str());
		else
			outFile.open(file.c_str(), ios_base::out|ios_base::app);
		if (outFile.fail())
			throw boss_error(BOSS_ERROR_FILE_WRITE_FAIL, file.string());

		outFile << PrintLog();
		outFile.close();
	}