void file_system_watcher::unsubscribe( path path )
{ path_watchers.erase(path.make_preferred()); }
示例#2
0
long ExtractCurrentFile ( path parent, unzFile zip_file )
{
    long error = UNZ_OK;
	
    char filename_inzip[PATH_MAX];
    unz_file_info64 file_info;
	
    error = unzGetCurrentFileInfo64 ( zip_file, &file_info, filename_inzip, sizeof ( filename_inzip ), NULL, 0, NULL, 0 );
	
	path file = filename_inzip;
	
	file.make_preferred();
	parent.make_preferred();
	
	if ( error == UNZ_OK ) {
		
		std::string macos = "__MACOSX";
		if ( file.string().compare ( 0, macos.length(), macos ) == 0 ) {
			return kNoError;
		}
		
		path to_write = parent / file;
		create_directories ( to_write.parent_path() );
		
		if ( file.filename().string() == "." ) {
			
			create_directory ( to_write );
			
		} else {
			
			error = unzOpenCurrentFilePassword ( zip_file, NULL );
			
			if ( error == UNZ_OK ) {
				
				char * buffer = new char [ WRITEBUFFERSIZE ];
				
				boost::filesystem::ofstream output_file ( to_write, std::ios_base::binary );
				output_file.exceptions ( boost::filesystem::ofstream::badbit | boost::filesystem::ofstream::failbit );
				
				long bytes_read = 0;
				do {
					bytes_read = unzReadCurrentFile ( zip_file, (void *)buffer, WRITEBUFFERSIZE );
					
					if ( bytes_read > 0 ) {
						output_file.write ( buffer, bytes_read );
					} else if ( bytes_read < 0 ) {
						error = bytes_read;
					}
				} while ( bytes_read > 0 );
				
				output_file.close();
                ChangeFileDate ( to_write, file_info.tmu_date );
				delete [] buffer;
				
			}
			
			// don't lose the error
			int close_error = unzCloseCurrentFile ( zip_file );
			if ( error == UNZ_OK ) {
				error = close_error;
			}
		}
	}
	
	return error;
	
} // ExtractCurrentFile
////////////////////////////////////////////////////////////////////////////////
/// File System Watcher
////////////////////////////////////////////////////////////////////////////////
void file_system_watcher::subscribe( path path, const filter filter_ )
{
	path_watchers.insert({
		path.make_preferred(), 
		std::make_shared<path_watcher>(this, path, filter_)});
}