Mercurial > mercurial > hgweb_rsearcher.cgi
comparison src/net.cpp @ 15:c262e17de9b1
db download skip-mode.
| author | pyon@macmini |
|---|---|
| date | Sat, 08 Jun 2019 15:50:59 +0900 |
| parents | f5ffc34f045a |
| children |
comparison
equal
deleted
inserted
replaced
| 14:c1dc1fcee7fe | 15:c262e17de9b1 |
|---|---|
| 1 // Filename : net.cpp | 1 // Filename : net.cpp |
| 2 // Last Change: 2018-11-14 水 10:46:24. | 2 // Last Change: 2019-05-24 金 16:02:39. |
| 3 // | 3 // |
| 4 | 4 |
| 5 #include <wx/datetime.h> | 5 #include <wx/datetime.h> |
| 6 #include <wx/stream.h> | 6 #include <wx/stream.h> |
| 7 #include <wx/zstream.h> | 7 #include <wx/zstream.h> |
| 37 wxDELETE( httpStream ); | 37 wxDELETE( httpStream ); |
| 38 get.Close(); | 38 get.Close(); |
| 39 return ret; | 39 return ret; |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool RsHttp::GetDB( int a, int h, int i ) | 42 bool RsHttp::GetDB( bool a, bool h, bool i ) |
| 43 { | 43 { |
| 44 bool ret = false; | 44 bool ret = false; |
| 45 if ( a == 1 ) ret = Get( wxT( "/db/auth.db"), wxT( "auth.db") ); | 45 if ( a ) ret = Get( wxT( "/db/auth.db"), wxT( "auth.db") ); |
| 46 if ( h == 1 ) ret = Get( wxT( "/db/hhs.db"), wxT( "hhs.db") ); | 46 if ( h ) ret = Get( wxT( "/db/hhs.db"), wxT( "hhs.db") ); |
| 47 wxDateTime now = wxDateTime::Now(); | 47 wxDateTime now = wxDateTime::Now(); |
| 48 if ( i == 2 || now.GetDay() % 13 == 0 || now.GetDay() % 28 == 0 ) | 48 if ( i || now.GetDay() % 13 == 0 || now.GetDay() % 28 == 0 ) |
| 49 Get( wxT( "/db/index.db"), wxT( "index.db" ) ); | 49 Get( wxT( "/db/index.db"), wxT( "index.db" ) ); |
| 50 return ret; | 50 return ret; |
| 51 } | 51 } |
| 52 | 52 |
| 53 int RsHttp::GetImagesSize( wxString hhs, wxString date ) | 53 int RsHttp::GetImagesSize( wxString hhs, wxString date ) |
| 69 wxDELETE( http_istream ); | 69 wxDELETE( http_istream ); |
| 70 get.Close(); | 70 get.Close(); |
| 71 return size; | 71 return size; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void RsHttp::GetImages( wxString hhs, wxString date ) | 74 void RsHttp::GetImages( wxString hhs, wxString date, wxString flag ) |
| 75 { | 75 { |
| 76 wxHTTP get; | 76 wxHTTP get; |
| 77 get.SetTimeout( 30 ); | 77 get.SetTimeout( 30 ); |
| 78 get.SetFlags( wxSOCKET_WAITALL|wxSOCKET_BLOCK ); | 78 get.SetFlags( wxSOCKET_WAITALL|wxSOCKET_BLOCK ); |
| 79 while ( !get.Connect( m_server, m_port ) ) | 79 while ( !get.Connect( m_server, m_port ) ) |
| 80 wxSleep( 1 ); | 80 wxSleep( 1 ); |
| 81 | 81 |
| 82 wxString url = wxT( "/images/" ) + date + wxT( "/" ) + hhs + wxT( ".tgz" ); | 82 wxString url = wxT( "/images/" ) + date + wxT( "/" ) + hhs + wxT( ".tgz" ); |
| 83 url += wxT( "?q=" ) + flag; | |
| 83 | 84 |
| 84 wxInputStream *http_istream = get.GetInputStream( url ); | 85 wxInputStream *http_istream = get.GetInputStream( url ); |
| 85 if ( get.GetError() == wxPROTO_NOERR ) { | 86 if ( get.GetError() == wxPROTO_NOERR ) { |
| 86 //int size = http_istream->GetSize(); | 87 //int size = http_istream->GetSize(); |
| 87 wxZlibInputStream zlib_istream( http_istream ); // 0: no cache : bad | 88 wxZlibInputStream zlib_istream( http_istream ); // 0: no cache : bad |
| 101 | 102 |
| 102 //wxDELETE( http_istream ); | 103 //wxDELETE( http_istream ); |
| 103 get.Close(); | 104 get.Close(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void RsHttp::GetImages2Memory( wxString hhs, wxString date ) | |
| 107 { | |
| 108 wxHTTP get; | |
| 109 get.SetTimeout( 30 ); | |
| 110 get.SetFlags( wxSOCKET_WAITALL|wxSOCKET_BLOCK ); | |
| 111 while ( !get.Connect( m_server, m_port ) ) | |
| 112 wxSleep( 1 ); | |
| 113 | |
| 114 wxString url = wxT( "/images/" ) + date + wxT( "/" ) + hhs + wxT( ".tgz" ); | |
| 115 | |
| 116 wxInputStream *http_istream = get.GetInputStream( url ); | |
| 117 if ( get.GetError() == wxPROTO_NOERR ) { | |
| 118 //int size = http_istream->GetSize(); | |
| 119 wxZlibInputStream zlib_istream( http_istream ); // 0: no cache : bad | |
| 120 | |
| 121 wxTarEntry* entry; | |
| 122 wxTarInputStream tar_istream( zlib_istream ); | |
| 123 int i = 1; | |
| 124 while ( ( entry = tar_istream.GetNextEntry() ) != NULL ) { | |
| 125 //wxString name = entry->GetName(); | |
| 126 wxFileOutputStream file_ostream( wxString::Format( wxT( ".cache/%s_%d" ), date, i++ ) ); | |
| 127 file_ostream.Write( tar_istream ); | |
| 128 file_ostream.Close(); | |
| 129 } | |
| 130 } else { | |
| 131 wxMessageBox( wxT( "Re:Searcher Error: get err" ) ); | |
| 132 } | |
| 133 | |
| 134 //wxDELETE( http_istream ); | |
| 135 get.Close(); | |
| 136 } | |
| 137 |
