Ejemplo n.º 1
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()));
        }
    }
}
Ejemplo n.º 2
0
    bool is_picture( const fs::path& file_path )
    {
        std::ifstream is( file_path.wstring().c_str(), std::ios::in | std::ios::binary );

        if ( !is )
        {
            return false;
        }

        unsigned char ch[2] = { 0 };

        is.unsetf( std::ios::skipws );
        is.read( (char*)ch, 2 );

        if ( ch[0] == 0xFF && ch[1] == 0xD8 ) // JPEG
        {
            return true;
        }
        else if ( ch[0] == 0x4D && ch[1] == 0x42 ) // BMP
        {
            return true;
        }

        return false;
    }
Ejemplo n.º 3
0
::Movie openMovieFromPath( const fs::path &path )
{
	::Movie result;
	QTNewMoviePropertyElement movieProps[10];
	ItemCount moviePropCount = 0;

	moviePropCount = openMovieBaseProperties( movieProps );

#if defined( CINDER_MSW )
	std::string pathUtf8 = msw::toUtf8String( path.wstring() );
	::CFStringRef basePathCF = ::CFStringCreateWithCString( kCFAllocatorDefault, pathUtf8.c_str(), kCFStringEncodingUTF8 );
#else
	::CFStringRef basePathCF = ::CFStringCreateWithCString( kCFAllocatorDefault, path.string().c_str(), kCFStringEncodingUTF8 );
#endif
	shared_ptr<const __CFString> pathCF = shared_ptr<const __CFString>( basePathCF, ::CFRelease );
	// Store the movie properties in the array
	movieProps[moviePropCount].propClass = kQTPropertyClass_DataLocation;
	movieProps[moviePropCount].propID = kQTDataLocationPropertyID_CFStringNativePath;
	movieProps[moviePropCount].propValueSize = sizeof(CFStringRef);
	movieProps[moviePropCount].propValueAddress = (void*)&basePathCF;
	movieProps[moviePropCount].propStatus = 0;
	moviePropCount++;

	OSStatus err;
	if( (err = ::NewMovieFromProperties( moviePropCount, movieProps, 0, NULL, &result ) ) != noErr ) {
		throw QuickTimePathInvalidExc();
	}
		
	return result;
}
Ejemplo n.º 4
0
bool remove_empty_directories_recur(const fs::path& p, std::vector<fs::path>& dirs)
{
	if (!fs::exists(p)) return false;

	bool ret = true;

	for (fs::directory_iterator i = fs::directory_iterator(p), e = fs::directory_iterator(); i != e; ++i)
	{
		if (!fs::is_directory(*i))
			ret = false;
		else
		{
			if (!remove_empty_directories(*i))
				ret = false;
		}
	}	

	if (ret)
	{
		HAL_DEV_MSG(wform(L"Removing directory: %1%") % p.wstring());
		dirs.push_back(p);
	}

	return ret;
}
Ejemplo n.º 5
0
FileLock::FileLock(const fs::path& file)
{
    hFile = CreateFileW(file.wstring().c_str(),  GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
        nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
    if (hFile == INVALID_HANDLE_VALUE) {
        reason = GetErrorReason();
    }
}
Ejemplo n.º 6
0
    Version::Version(const fs::path& file) {
#if _WIN32 || _WIN64
        DWORD dummy = 0;
        DWORD size = GetFileVersionInfoSize(file.wstring().c_str(), &dummy);

        if (size > 0) {
            LPBYTE point = new BYTE[size];
            UINT uLen;
            VS_FIXEDFILEINFO *info;
            string ver;

            GetFileVersionInfo(file.wstring().c_str(),0,size,point);

            VerQueryValue(point,L"\\",(LPVOID *)&info,&uLen);

            DWORD dwLeftMost     = HIWORD(info->dwFileVersionMS);
            DWORD dwSecondLeft   = LOWORD(info->dwFileVersionMS);
            DWORD dwSecondRight  = HIWORD(info->dwFileVersionLS);
            DWORD dwRightMost    = LOWORD(info->dwFileVersionLS);

            delete [] point;

            verString = to_string(dwLeftMost) + '.' + to_string(dwSecondLeft) + '.' + to_string(dwSecondRight) + '.' + to_string(dwRightMost);
        }
#else
        // ensure filename has no quote characters in it to avoid command injection attacks
        if (string::npos != file.string().find('"')) {
             // command mostly borrowed from the gnome-exe-thumbnailer.sh script
            // wrestool is part of the icoutils package
            string cmd = "wrestool --extract --raw --type=version \"" + file.string() + "\" | tr '\\0, ' '\\t.\\0' | sed 's/\\t\\t/_/g' | tr -c -d '[:print:]' | sed -r 's/.*Version[^0-9]*([0-9]+(\\.[0-9]+)+).*/\\1/'";

            FILE *fp = popen(cmd.c_str(), "r");

            // read out the version string
            static const uint32_t BUFSIZE = 32;
            char buf[BUFSIZE];
            if (nullptr != fgets(buf, BUFSIZE, fp)) {
                verString = string(buf);
            }
            pclose(fp);
        }
#endif
    }
Ejemplo n.º 7
0
	bool reader::Open(const fs::path& zip_file_path) 
	{
		// Use of "Unsafe" function does not look good, but there is no way to do
		// this safely on Linux. See file_util.h for details.
		zip_file_ = internal::OpenForUnzipping(bee::w2u(zip_file_path.wstring()));
		if (!zip_file_)
		{
			return false;
		}

		return true;
	}
Ejemplo n.º 8
0
IStreamFileRef loadFileStream( const fs::path &path )
{
#if defined( CINDER_MSW )
	FILE *f = _wfopen( path.wstring().c_str(), L"rb" );
#else
	FILE *f = fopen( path.string().c_str(), "rb" );
#endif
	if( f ) {
		IStreamFileRef s = IStreamFile::create( f, true );
		s->setFileName( path );
		return s;
	}
	else
		return IStreamFileRef();
}
Ejemplo n.º 9
0
ProcessWithThread Process::launch(const fs::path& app, const wstring& args,
	optional<const vector<string>&> env,
	optional<const wstring&> cwd,
	bool inheritHandles, DWORD creationFlags,
	SECURITY_ATTRIBUTES* processAttributes, SECURITY_ATTRIBUTES* threadAttributes,
	STARTUPINFOW startupInfo)
{
	startupInfo.cb = sizeof(STARTUPINFOW); // needed
	PROCESS_INFORMATION pi = {};
	wstring commandLine = app.wstring() + L" " + args;

	if (!CreateProcessW(app.c_str(), &commandLine[0], processAttributes, threadAttributes, inheritHandles,
			creationFlags, nullptr, nullptr, &startupInfo, &pi))
	{
		DWORD errcode = GetLastError();
		BOOST_THROW_EXCEPTION(ex_injection() << e_api_function("CreateProcess") << e_last_error(errcode) << e_file(app));
	}
	else
		return ProcessWithThread(Process(pi.dwProcessId, pi.hProcess), Thread(pi.dwThreadId, pi.hThread));
}
Ejemplo n.º 10
0
IStreamFileRef loadFileStream( const fs::path &path )
{
#if defined( CINDER_MSW )
	FILE *f = _wfopen( path.wstring().c_str(), L"rb" );
#else
	FILE *f = fopen( path.string().c_str(), "rb" );
#endif

#if defined( CINDER_ANDROID )
	if( nullptr == f ) {
		throw StreamExc( "(loadFileStream) couldn't open: " + path.string() );
	}
#endif	

	if( f ) {
		IStreamFileRef s = IStreamFile::create( f, true );
		s->setFileName( path );
		return s;
	}
	else
		return IStreamFileRef();
}
Ejemplo n.º 11
0
 void set_system_wallpaper( const fs::path& picture )
 {
     SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, const_cast<wchar_t*>( picture.wstring().c_str() ), SPIF_UPDATEINIFILE);
 }