示例#1
0
void FBReader::tryShowFootnoteView(const std::string &id, const std::string &type) {
    if (type == "external") {
        openLinkInBrowser(id);
    } else if (type == "internal") {
        if (myMode == BOOK_TEXT_MODE && !myModel.isNull()) {
            BookModel::Label label = myModel->label(id);
            if (!label.Model.isNull()) {
                if (label.Model == myModel->bookTextModel()) {
                    bookTextView().gotoParagraph(label.ParagraphNumber);
                } else {
                    FootnoteView &view = ((FootnoteView&)*myFootnoteView);
                    view.setModel(label.Model);
                    setMode(FOOTNOTE_MODE);
                    view.gotoParagraph(label.ParagraphNumber);
                }
                setHyperlinkCursor(false);
                refreshWindow();
            }
        }
    } else if (type == "book") {
        DownloadBookRunnable downloader(id);
        downloader.executeWithUI();
        if (downloader.hasErrors()) {
            downloader.showErrorMessage();
        } else {
            shared_ptr<Book> book;
            createBook(downloader.fileName(), book);
            if (!book.isNull()) {
                Library::Instance().addBook(book);
                openBook(book);
                refreshWindow();
            }
        }
    }
}
示例#2
0
/*----------------------------------------------------------------------
|   Test1
+---------------------------------------------------------------------*/
static bool
Test1(PLT_TaskManager* task_manager, const char* url, NPT_Size& size)
{
    NPT_LOG_INFO("########### TEST 1 ######################");

    NPT_MemoryStreamReference memory_stream(new NPT_MemoryStream());
    NPT_OutputStreamReference output_stream(memory_stream);
    PLT_Downloader downloader(task_manager, url, output_stream);
    downloader.Start();

    while (1) {
        switch(downloader.GetState()) {
            case PLT_DOWNLOADER_SUCCESS: {
                size = memory_stream->GetDataSize();
                return true;
            }

            case PLT_DOWNLOADER_ERROR:
                return false;

            default:
                NPT_System::Sleep(NPT_TimeInterval(0, 10000));
                break;
        }
    };

    return false;
}
示例#3
0
/*----------------------------------------------------------------------
|   Test3
+---------------------------------------------------------------------*/
static bool
Test3(PLT_TaskManager* task_manager, NPT_HttpUrl url, PLT_RingBufferStreamReference& ringbuffer_stream, NPT_Size& size)
{
    NPT_LOG_INFO("########### TEST 3 ######################");

    /* reset output param first */
    size = 0;

    NPT_MemoryStreamReference memory_stream(new NPT_MemoryStream());
    NPT_OutputStreamReference output_stream(memory_stream);
    PLT_Downloader downloader(task_manager, url, output_stream);
    downloader.Start();

    /* asynchronously write onto ring buffer stream */
    task_manager->StartTask(new RingBufferWriterTask(ringbuffer_stream));

    /* start pulling data */
    while (1) {
        switch(downloader.GetState()) {
            case PLT_DOWNLOADER_SUCCESS:
                size = memory_stream->GetDataSize();
                return true;

            case PLT_DOWNLOADER_ERROR:
                return false;

            default:
                NPT_System::Sleep(NPT_TimeInterval(.1f));
                break;
        }
    };

    return false;
}
示例#4
0
void FBReader::tryShowFootnoteView(const std::string &id, const std::string &type) {
	if (type == "external") {
		shared_ptr<ProgramCollection> collection = webBrowserCollection();
		if (!collection.isNull()) {
			shared_ptr<Program> program = collection->currentProgram();
			if (!program.isNull()) {
				program->run("openLink", id);
			}
		}
	} else if (type == "internal") {
		if (((myMode == BOOK_TEXT_MODE) || (myMode == FOOTNOTE_MODE) || (myMode == HYPERLINK_NAV_MODE)) && (myModel != 0)) {
			BookModel::Label label = myModel->label(id);
			if (!label.Model.isNull()) {
				if ((myMode != FOOTNOTE_MODE) && (label.Model == myModel->bookTextModel())) {
					bookTextView().gotoParagraph(label.ParagraphNumber);
				} else {
					FootnoteView &view = ((FootnoteView&)*myFootnoteView);
					view.setModel(label.Model, myModel->description()->language());
					setMode(FOOTNOTE_MODE);
					view.gotoParagraph(label.ParagraphNumber);
				}
				setHyperlinkCursor(false);
				refreshWindow();
			}
		}
	} else if (type == "book") {
		DownloadBookRunnable downloader(id);
		downloader.executeWithUI();
		if (downloader.hasErrors()) {
			downloader.showErrorMessage();
		} else {
			openFile(downloader.fileName());
		}
	}
}
示例#5
0
STDMETHODIMP CCxEvol3DViewer::OpenURL(BSTR _url)
{
    // TODO: Add your implementation code here
    xURLDownloader downloader(this);
    downloader.Download( (wchar_t*) _url );
    return S_OK;
}
示例#6
0
void Crawler::downloader()
{
	for (auto i : InitList)
	{
		wstring ws(i->url.begin(), i->url.end());
		downloader(ws);
	}
}
示例#7
0
QgsWFSProvider::QgsWFSProvider( const QString& uri )
    : QgsVectorDataProvider( uri )
    , mShared( new QgsWFSSharedData( uri ) )
    , mWKBType( QGis::WKBUnknown )
    , mValid( true )
    , mCapabilities( 0 )
{
  if ( uri.isEmpty() )
  {
    mValid = false;
    return;
  }

  //create mSourceCRS from url if possible [WBC 111221] refactored from GetFeatureGET()
  QString srsname = mShared->mURI.SRSName();
  if ( !srsname.isEmpty() )
  {
    if ( srsname == "EPSG:900913" )
      mShared->mSourceCRS.createFromOgcWmsCrs( "EPSG:3857" );
    else
      mShared->mSourceCRS.createFromOgcWmsCrs( srsname );
  }

  // Must be called first to establish the version, in case we are in auto-detection
  if ( !getCapabilities() )
  {
    mValid = false;
    return;
  }

  mSubsetString = mShared->mURI.filter();
  mShared->computeFilter();

  //fetch attributes of layer and type of its geometry attribute
  //WBC 111221: extracting geometry type here instead of getFeature allows successful
  //layer creation even when no features are retrieved (due to, e.g., BBOX or FILTER)
  if ( !describeFeatureType( mShared->mGeometryAttribute, mShared->mFields, mWKBType ) )
  {
    mValid = false;
    return;
  }

  //Failed to detect feature type from describeFeatureType -> get first feature from layer to detect type
  if ( mWKBType == QGis::WKBUnknown )
  {
    QgsWFSFeatureDownloader downloader( mShared.data() );
    connect( &downloader, SIGNAL( featureReceived( QVector<QgsWFSFeatureGmlIdPair> ) ),
             this, SLOT( featureReceivedAnalyzeOneFeature( QVector<QgsWFSFeatureGmlIdPair> ) ) );
    downloader.run( false, /* serialize features */
                    1 /* maxfeatures */ );
  }

  qRegisterMetaType<QgsRectangle>( "QgsRectangle" );
}
示例#8
0
HRESULT CPatchDlg::DownloadFile(CString srvPath,CString savePath,BOOL checkCrc,DWORD crc)
{
	CBkUpdDownloader downloader(TRUE);
	HRESULT hr;
	CBkUpdWebFile file;
	CString sSaveDir=savePath;
	DWORD dwCliCrc=0;
	int i=0;
	CString sFileName;

	PathRemoveFileSpec(sSaveDir.GetBuffer());
	if(!PathIsDirectory(sSaveDir))
		hr=CAppPath::Instance().CreateFullPath(sSaveDir);
	//先比较下载文件是否存在
	if(PathFileExists(savePath))
	{
		dwCliCrc=CalcCrc(savePath);
		if(dwCliCrc!=crc) //校验不通过,重新下载
		{
			goto Download;
		}
		else
		{
			hr=S_OK;
			goto Done;
		}
	}

	Download:
	file.SetFileName(savePath);
	sFileName=PathFindFileName(savePath);
	GetDlgItem(IDC_STC_DOWNLOAD_FILE)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_PGS_DOWNLOAD_FILE)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STC_DOWNLOAD_FILE)->SetWindowText(sFileName);
	do{
		hr = downloader.Download(srvPath, (IBkUpdWebFile*)&file, this);
		dwCliCrc=CalcCrc(savePath);
		i++;
	}
	while(hr==S_OK && checkCrc && i<=nCrc32Retry && dwCliCrc!=crc);
	if(dwCliCrc!=crc && checkCrc)
	{
		if(bCrcChecekUp) bCrcChecekUp=FALSE;
		sCrcHint.AppendFormat(_T("%-38s校验不通过,客户端:%08x,服务端:%08x.\r\n"),
			sFileName,dwCliCrc,crc);
	}

	Done:
	GetDlgItem(IDC_STC_DOWNLOAD_FILE)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_PGS_DOWNLOAD_FILE)->ShowWindow(SW_HIDE);
	return hr;
}
示例#9
0
文件: il.c 项目: johnjohnsp1/c-utils
int main(int argc, char* argv[]) {

if (argc != 2) {
	printf("Must provide username\n");
	exit(0);
}

if (argc == 2) {
	// remove potential slash at end of line

	size_t ln = strlen(argv[1]) - 1;

	if (argv[1][ln] == '/') {
        	argv[1][ln] = '\0';
	}
	
	downloader(argc, argv);
}

}
示例#10
0
/*----------------------------------------------------------------------
|   Test2
+---------------------------------------------------------------------*/
static bool
Test2(PLT_TaskManager* task_manager, const char* url, NPT_Size& size)
{
    NPT_LOG_INFO("########### TEST 2 ######################");

    /* reset output param first */
    size = 0;

    PLT_RingBufferStreamReference ringbuffer_stream(new PLT_RingBufferStream());
    NPT_OutputStreamReference output_stream(ringbuffer_stream);
    NPT_InputStreamReference  input_stream(ringbuffer_stream);
    PLT_Downloader downloader(task_manager, url, output_stream);
    downloader.Start();

    while (1) {
        switch(downloader.GetState()) {
            case PLT_DOWNLOADER_SUCCESS:
                ringbuffer_stream->SetEos();
                /* fallthrough */

            case PLT_DOWNLOADER_DOWNLOADING: {
                    NPT_Size bytes_read;
                    NPT_Result res = ReadBody(downloader, input_stream, bytes_read);
                    if (NPT_FAILED(res)) {
                        return (res==NPT_ERROR_EOS)?true:false;
                    }
                    size += bytes_read;
                }
                break;

            case PLT_DOWNLOADER_ERROR:
                return false;

            default:
                NPT_System::Sleep(NPT_TimeInterval(0, 10000));
                break;
        }
    };

    return false;
}
示例#11
0
int main(int argc, char* argv[])
{
	if (argc < 2)
	{
		std::cout << "Usage: " << argv[0] << " <url> [optional]"<<std::endl;
		std::cout << "<url>: link to PhotoSynth (http://photosynth.net/view.aspx?cid=GUID)"<<std::endl;
		std::cout << "[optional] : thumb (will download thumbs)" <<std::endl;
		std::cout <<std::endl;
		std::cout << "Example: "<<argv[0]<< " http://photosynth.net/view.aspx?cid=1471c7c7-da12-4859-9289-a2e6d2129319 thumb"<<std::endl;
		std::cout << "will download json, thumbs and bin files and put everything in a GUID folder"<<std::endl;

		return -1;
	}

	std::string url = argv[1];
	bool downloadThumb  = false;

	for (int i=1; i<argc; ++i)
	{
		std::string current(argv[i]);
		if (current == "thumb")
			downloadThumb = true;
	}

	boost::asio::io_service* service;
	try
	{
		service = new boost::asio::io_service;
		service->run();

		PhotoSynth::Downloader downloader(service);
		downloader.download(url, downloadThumb);
	}
	catch(std::exception& e)
	{
		std::cerr << e.what() << std::endl;
	}

	return 0;
}
示例#12
0
int main(int argc, char* argv[])
{
	// expect two arguments
	if (argc != 3)
	{
		std::cerr << "usage: " << argv[0] << " url file" << std::endl;
		return 1;
	}

	// this example program downloads argv[1] to argv[2]
	char* url = argv[1];
	char* file_name = argv[2];
	
	// start by creating an io_service object
	asio::io_service io_service;
	
	// construct an instance of curl::easy
	curl::easy downloader(io_service);
	
	// set the object's properties
	downloader.set_url(url);
	downloader.set_sink(std::make_shared<std::ofstream>(file_name, std::ios::binary));
	
	// download the file
	std::error_code ec;
	downloader.perform(ec);

	// error handling
	if (!ec)
	{
		std::cerr << "Download succeeded" << std::endl;
	}
	else
	{
		std::cerr << "Download failed: " << ec.message() << std::endl;
	}
	
	return 0;
}
示例#13
0
/*----------------------------------------------------------------------
|   Test3
+---------------------------------------------------------------------*/
static bool
Test3(PLT_TaskManager* task_manager, const char* url, PLT_RingBufferStreamReference& ringbuffer_stream, NPT_Size& size)
{
    NPT_LOG_INFO("########### TEST 3 ######################");

    /* reset output param first */
    size = 0;

    NPT_MemoryStreamReference memory_stream(new NPT_MemoryStream());
    NPT_OutputStreamReference output_stream(memory_stream);
    PLT_Downloader downloader(task_manager, url, output_stream);
    downloader.Start();

    /* asynchronously write onto ring buffer stream */
    char buffer[32768];
    ringbuffer_stream->WriteFully(buffer, 32768);

    /* mark as done */
    ringbuffer_stream->SetEos();

    while (1) {
        switch(downloader.GetState()) {
            case PLT_DOWNLOADER_SUCCESS:
                size = memory_stream->GetDataSize();
                return true;

            case PLT_DOWNLOADER_ERROR:
                return false;

            default:
                NPT_System::Sleep(NPT_TimeInterval(0, 10000));
                break;
        }
    };

    return false;
}
示例#14
0
/**
 * @brief HTTP::get_headers
 * @return int
 */
int HTTP::get_headers()
{

    char buffer[1];
    int count;
    std::string endHeaderSequence = "\r\n\r\n"; // end headers string
    std::string endLine = "\r\n";
    std::string firstLine = "";
    bool doOnce = true; // for first line check
    int resCheck = 0;
    while (errno == EINTR || (errno = 0, (count = receive(buffer, 1)) > 0))

    {
        if (count > 0)
        {
            m_headers.append(buffer, count); // append to headers
            if (doOnce)
            {
                firstLine.append(buffer, count);
                if (Gadgets::contains_substring(firstLine, endLine))
                {
                    resCheck = httpResponseCheck(firstLine); // check if we have 200 or 301, or error
                    doOnce = false;
                }
            }

            if (Gadgets::contains_substring(m_headers, endHeaderSequence))
            {
                int res = Gadgets::find_chunked(m_headers); // determine if chunked
                if (res == -1) m_chunked = true;
                else m_contentLength = res; // or to use content-length

                if (resCheck == 301) // if we found 301 state
                {
                    std::string redirectUrl = Gadgets::find_location_on_redirect(m_headers); // we find location which to redirect to
                    UrlDetail urldet(redirectUrl);

                    if (m_maxRedir > 0) // check if we still can redirect
                    {
                        if (urldet.port() == 80)
                        {
                            HTTP downloader(urldet.server(), urldet.file(), m_maxRedir - 1); // http
                            downloader.download();
                            throw ISAException(Gadgets::redirc);
                        }
                        else
                        {
                            HTTPS downloader(urldet.server(), urldet.file(), m_args, m_maxRedir - 1); // ssl
                            downloader.download();
                            throw ISAException(Gadgets::redirc);
                        }
                    }
                    else
                    {
                        throw ISAException("Error - Maximal redirection limit 10 reached");
                    }


                }
                break;
            }
        }
    }
    if (count < 0)
    {
        throw ISAException("Error - Recv bytes");
    }
    return 0;
}
   // PD_TRACE_DECLARE_FUNCTION ( COORD_EVAL_EXE, "_coordCMDEval::execute" )
   INT32 _coordCMDEval::execute( MsgHeader *pMsg,
                                 pmdEDUCB *cb,
                                 INT64 &contextID,
                                 rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( COORD_EVAL_EXE ) ;
      spdSession *session = NULL ;
      contextID           = -1 ;

      CHAR *pQuery = NULL ;
      BSONObj procedures ;
      spdCoordDownloader downloader( this, cb ) ;
      BSONObj runInfo ;

      rc = msgExtractQuery( (CHAR*)pMsg, NULL, NULL,
                            NULL, NULL, &pQuery, NULL,
                            NULL, NULL );
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to extract eval msg:%d", rc) ;
         goto error ;
      }

      try
      {
         procedures = BSONObj( pQuery ) ;
         PD_LOG( PDDEBUG, "eval:%s", procedures.toString().c_str() ) ;
      }
      catch ( std::exception &e )
      {
         PD_LOG( PDERROR, "unexpected err happened:%s", e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

      session = SDB_OSS_NEW _spdSession() ;
      if ( NULL == session )
      {
         PD_LOG( PDERROR, "failed to allocate mem." ) ;
         rc = SDB_OOM ;
         goto error ;
      }

      rc = session->eval( procedures, &downloader, cb ) ;
      if ( SDB_OK != rc )
      {
         const BSONObj &errmsg = session->getErrMsg() ;
         if ( !errmsg.isEmpty() )
         {
            *buf = rtnContextBuf( errmsg.getOwned() ) ;
         }
         PD_LOG( PDERROR, "failed to eval store procedure:%d", rc ) ;
         goto error ;
      }

      if ( FMP_RES_TYPE_VOID != session->resType() )
      {
         rc = _buildContext( session, cb, contextID ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "failed to prepare reply msg:%d", rc ) ;
            goto error ;
         }
      }

      runInfo = BSON( FIELD_NAME_RTYPE << session->resType() ) ;
      *buf = rtnContextBuf( runInfo ) ;

   done:
      if ( -1 == contextID )
      {
         SAFE_OSS_DELETE( session ) ;
      }
      PD_TRACE_EXITRC( COORD_EVAL_EXE, rc ) ;
      return rc ;
   error:
      if ( contextID >= 0 )
      {
         pmdGetKRCB()->getRTNCB()->contextDelete( contextID, cb ) ;
         contextID = -1 ;
      }
      goto done ;
   }
示例#16
0
bool NetLibraryView::_onStylusPress(int x, int y) {
	fbreader().setHyperlinkCursor(false);

	if (model().isNull()) {
		return false;
	}

	const ZLTextElementArea *imageArea = elementByCoordinates(x, y);
	if ((imageArea == 0) || (imageArea->Kind != ZLTextElement::IMAGE_ELEMENT)) {
		return false;
	}

	ZLTextWordCursor cursor = startCursor();
	cursor.moveToParagraph(imageArea->ParagraphIndex);
	cursor.moveTo(imageArea->ElementIndex, 0);
	const ZLTextElement &element = cursor.element();
	if (element.kind() != ZLTextElement::IMAGE_ELEMENT) {
		return false;
	}
	const ZLTextImageElement &imageElement = (ZLTextImageElement&)element;

	const std::string &id = imageElement.id();

	shared_ptr<NetworkBookInfo> book = myParagraphToBookMap[imageArea->ParagraphIndex];
	if (book.isNull()) {
		return false;
	}

	if ((id == DownloadEpub) || (id == DownloadMobi)) {
		if (!ZLNetworkManager::instance().connect()) {
			NetworkOperationRunnable::showErrorMessage(
				ZLResource::resource("dialog")
					["networkError"]
					["couldntConnectToNetworkMessage"].value()
			);
			return false;
		}

		NetworkBookInfo::URLType format = (id == DownloadEpub) ? NetworkBookInfo::BOOK_EPUB : NetworkBookInfo::BOOK_MOBIPOCKET;
		DownloadBookRunnable downloader(*book, format);
		downloader.executeWithUI();
		if (downloader.hasErrors()) {
			downloader.showErrorMessage();
		} else {
			BookDescriptionPtr description = BookDescription::getDescription(downloader.fileName());
			WritableBookDescription wDescription(*description);
			wDescription.clearAuthor();
			wDescription.addAuthor(book->Author.DisplayName, book->Author.SortKey);
			wDescription.title() = book->Title;
			wDescription.language() = book->Language;
			for (std::vector<std::string>::const_iterator it = book->Tags.begin(); it != book->Tags.end(); ++it) {
				wDescription.addTag(*it);
			}
			wDescription.saveInfo();

			fbreader().openBook(description);
			fbreader().setMode(FBReader::BOOK_TEXT_MODE);
			rebuildModel();
		}
		return true;
	} else if ((id == ReadLocalEpub) || (id == ReadLocalMobi)) {
		NetworkBookInfo::URLType format = (id == DownloadEpub) ? NetworkBookInfo::BOOK_EPUB : NetworkBookInfo::BOOK_MOBIPOCKET;
		fbreader().openFile(NetworkLinkCollection::instance().bookFileName(book->URLByType[format]));
		fbreader().setMode(FBReader::BOOK_TEXT_MODE);
		return true;
	} else if (id == OpenInBrowser) {
		std::string url = book->URLByType[NetworkBookInfo::LINK_HTTP];
		shared_ptr<ProgramCollection> collection = fbreader().webBrowserCollection();
		if (!url.empty() && !collection.isNull()) {
			shared_ptr<Program> program = collection->currentProgram();
			if (!program.isNull()) {
				program->run("openLink", url);
			}
		}
		return true;
	}
	return false;
}
示例#17
0
文件: cmaevent.cpp 项目: 173210/qcma
void CmaEvent::vitaEventSendHttpObjectFromURL(vita_event_t *event, int eventId)
{
    qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);

    char *url;
    if(VitaMTP_GetUrl(device, eventId, &url) != PTP_RC_OK) {
        qWarning("Failed to recieve URL");
        return;
    }

    QString urlpath = QSettings().value("urlPath").toString();
    QString basename = QFileInfo(QUrl(url).path()).fileName();
    QFile file(QDir(urlpath).absoluteFilePath(basename));

    QByteArray data;
    QSettings settings;

    bool offlineMode = settings.value("offlineMode", true).toBool();

    if(!file.open(QIODevice::ReadOnly)) {
        if(offlineMode && basename == "psp2-updatelist.xml") {
            qDebug("Found request for update list. Sending cached data");
            QFile res(":/main/resources/xml/psp2-updatelist.xml");
            res.open(QIODevice::ReadOnly);
            data = res.readAll();

        } else if(!offlineMode) {
            qDebug("URL: %s", url);
            HTTPDownloader downloader(url);
            QThread *http_thread = new QThread();
            http_thread->setObjectName("http_thread");
            connect(http_thread, SIGNAL(started()), &downloader, SLOT(downloadFile()));
            connect(&downloader, SIGNAL(messageSent(QString)), SIGNAL(messageSent(QString)), Qt::DirectConnection);
            downloader.moveToThread(http_thread);
            http_thread->start();

            int remote_size = (int)downloader.getFileSize();

            if(remote_size != -1) {
                // add the size of the file length to the total filesize
                remote_size += 8;
                qDebug("Sending %i bytes of data for HTTP request %s", remote_size, url);

                if(VitaMTP_SendData_Callback(device, eventId, PTP_OC_VITA_SendHttpObjectFromURL, remote_size, HTTPDownloader::readCallback) != PTP_RC_OK) {
                    qWarning("Failed to send HTTP object");
                } else {
                    VitaMTP_ReportResult(device, eventId, PTP_RC_OK);
                }

            } else {
                qWarning("No valid content-length in header, aborting");
                VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Failed_Download);
            }

            free(url);
            http_thread->quit();
            http_thread->deleteLater();
            return;
        }
    } else {
        qDebug("Reading from local file");
        data = file.readAll();
    }

    qDebug("Sending %i bytes of data for HTTP request %s", data.size(), url);

    if(VitaMTP_SendHttpObjectFromURL(device, eventId, data.data(), data.size()) != PTP_RC_OK) {
        qWarning("Failed to send HTTP object");
    } else {
        VitaMTP_ReportResult(device, eventId, PTP_RC_OK);
    }

    free(url);
}