Mercurial > mercurial > hgweb_rsearcher.cgi
view src/net.cpp @ 9:ae89ce4793d8
add satellite-view.
author | pyon@macmini |
---|---|
date | Wed, 31 Oct 2018 20:10:29 +0900 |
parents | 82f9af6aa7e4 |
children | 36811fd22bd2 |
line wrap: on
line source
// Filename : net.cpp // Last Change: 2018-10-31 水 10:42:06. // #include <wx/datetime.h> #include <wx/stream.h> #include <wx/zstream.h> #include <wx/tarstrm.h> #include <wx/mstream.h> #include "net.h" RsHttp::RsHttp() { } RsHttp::~RsHttp() { } bool RsHttp::Get( wxString url, wxString file ) { bool ret = false; wxHTTP get; get.SetFlags( wxSOCKET_WAITALL|wxSOCKET_BLOCK ); while ( !get.Connect( m_server, m_port ) ) wxSleep( 1 ); wxInputStream *httpStream = get.GetInputStream( url ); if ( get.GetError() == wxPROTO_NOERR ) { wxFileOutputStream out_stream( file ); httpStream->Read( out_stream ); ret = true; } else { wxMessageBox( wxT( "Re:Searcher Error: cannot get data." ) ); } wxDELETE( httpStream ); get.Close(); return ret; } bool RsHttp::GetDB( void ) { bool ret = false; ret = Get( wxT( "/db/auth.db"), wxT( "auth.db") ); ret = Get( wxT( "/db/hhs.db"), wxT( "hhs.db") ); wxDateTime now = wxDateTime::Now(); if ( now.GetDay() % 14 == 0 ) Get( wxT( "/db/index.db"), wxT( "index.db" ) ); return ret; } int RsHttp::GetImagesSize( wxString hhs, wxString date ) { wxHTTP get; while ( !get.Connect( m_server, m_port ) ) wxSleep( 1 ); wxString url = wxT( "/images/" ) + date + wxT( "/" ) + hhs + wxT( ".tgz" ); int size = -1; wxInputStream *http_istream = get.GetInputStream( url ); if ( get.GetError() == wxPROTO_NOERR ) { size = http_istream->GetSize(); } else { wxMessageBox( wxT( "Re:Searcher Error: Cannot get file size." ) ); } wxDELETE( http_istream ); get.Close(); return size; } void RsHttp::GetImages( wxString hhs, wxString date ) { wxHTTP get; get.SetTimeout( 30 ); get.SetFlags( wxSOCKET_WAITALL|wxSOCKET_BLOCK ); while ( !get.Connect( m_server, m_port ) ) wxSleep( 1 ); wxString url = wxT( "/images/" ) + date + wxT( "/" ) + hhs + wxT( ".tgz" ); wxInputStream *http_istream = get.GetInputStream( url ); if ( get.GetError() == wxPROTO_NOERR ) { //int size = http_istream->GetSize(); wxZlibInputStream zlib_istream( http_istream ); // 0: no cache : bad wxTarEntry* entry; wxTarInputStream tar_istream( zlib_istream ); int i = 1; while ( ( entry = tar_istream.GetNextEntry() ) != NULL ) { //wxString name = entry->GetName(); wxFileOutputStream file_ostream( wxString::Format( wxT( ".cache/%s_%d" ), date, i++ ) ); file_ostream.Write( tar_istream ); file_ostream.Close(); } } else { wxMessageBox( wxT( "Re:Searcher Error: get err" ) ); } //wxDELETE( http_istream ); get.Close(); }