diff options
author | Kandrashin Denis <mail@lintest.ru> | 2011-03-12 02:04:45 +0300 |
---|---|---|
committer | Kandrashin Denis <mail@lintest.ru> | 2011-03-12 02:04:45 +0300 |
commit | c5020ed38f5af7638000a0385056ad537e2dd242 (patch) | |
tree | 8c66d80f7bf5a9f6294245c12f25d0c5d7b57c3e | |
parent | 25b76d4ec34682b0b86ed72be6feb970368b338b (diff) |
Try to use wxCurlHTTP object for downloadingcurl
-rw-r--r-- | sources/MyRuLib/FbInternetBook.cpp | 26 | ||||
-rw-r--r-- | sources/MyRuLib/FbUpdateThread.cpp | 48 | ||||
-rw-r--r-- | sources/MyRuLib/FbUpdateThread.h | 3 | ||||
-rw-r--r-- | sources/MyRuLib/MyRuLib.cbp | 2 | ||||
-rw-r--r-- | sources/MyRuLib/MyRuLibApp.cpp | 2 | ||||
-rw-r--r-- | sources/wxCURL/WxCURL.cbp | 4 | ||||
-rw-r--r-- | sources/wxXML2/WxXML2.cbp | 4 |
7 files changed, 27 insertions, 62 deletions
diff --git a/sources/MyRuLib/FbInternetBook.cpp b/sources/MyRuLib/FbInternetBook.cpp index eadf7143..0a50b54d 100644 --- a/sources/MyRuLib/FbInternetBook.cpp +++ b/sources/MyRuLib/FbInternetBook.cpp @@ -10,6 +10,7 @@ #include <wx/filename.h>
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
+#include <wx/curl/http.h>
#include "FbDataPath.h"
#include "FbDateTime.h"
#include "controls/FbURL.h"
@@ -95,25 +96,19 @@ bool FbInternetBook::DownloadUrl(const wxString &cookie) {
if (m_owner->IsClosed()) return false;
- FbURL url(m_url);
- if (url.GetError() != wxURL_NOERR) {
- FbLogError(_("URL error"), m_url);
- return false;
- }
- wxHTTP & http = (wxHTTP&)url.GetProtocol();
- if ( !cookie.IsEmpty() ) http.SetHeader(wxT("Cookie"), cookie);
+ m_filename = wxFileName::CreateTempFileName(wxT("~"));
- wxInputStream * in = url.GetInputStream();
- if (url.GetError() != wxURL_NOERR) {
+ wxCurlHTTP url(m_url);
+ url.SetOpt(CURLOPT_TIMEOUT, FbParams::GetInt(FB_WEB_TIMEOUT));
+ url.SetOpt(CURLOPT_CONNECTTIMEOUT, FbParams::GetInt(FB_WEB_TIMEOUT));
+ bool ok = url.Get(m_filename);
+
+ if (!ok) {
FbLogError(_("Connect error"), m_url);
return false;
}
- if (http.GetResponse() == 302) {
- m_url = http.GetHeader(wxT("Location"));
- FbLogMessage(_("Redirect"), m_url);
- return DownloadUrl(cookie);
- }
- return ReadFile(in);
+
+ return ok;
}
bool FbInternetBook::ReadFile(wxInputStream * in)
@@ -236,4 +231,3 @@ void FbInternetBook::SaveFile(const bool success) FbMasterEvent(ID_UPDATE_MASTER, info, m_id, true).Post();
}
}
-
diff --git a/sources/MyRuLib/FbUpdateThread.cpp b/sources/MyRuLib/FbUpdateThread.cpp index 1e46234a..14da44e3 100644 --- a/sources/MyRuLib/FbUpdateThread.cpp +++ b/sources/MyRuLib/FbUpdateThread.cpp @@ -7,6 +7,7 @@ #include "MyRuLibApp.h"
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
+#include <wx/curl/http.h>
//-----------------------------------------------------------------------------
// FbUpdateItem
@@ -70,7 +71,6 @@ FbUpdateItem::~FbUpdateItem() int FbUpdateItem::Execute()
{
bool ok = OpenURL();
- if (ok) ok = ReadURL();
if (ok) ok = OpenZip();
if (ok) return DoUpdate();
return 0;
@@ -78,49 +78,13 @@ int FbUpdateItem::Execute() bool FbUpdateItem::OpenURL()
{
- m_input = m_url.GetInputStream();
-
- wxHTTP & http = (wxHTTP&)m_url.GetProtocol();
- if (http.GetResponse() == 404) {
- FbLogError(_("The update file is missing"), m_url.GetURL());
- return false;
- }
-
- FbLogWarning(_("Update collection"), m_url.GetURL());
-
- if (m_url.GetError() != wxURL_NOERR) {
- FbLogError(_("Download error"), m_url.GetURL());
- return false;
- }
+ m_filename = wxFileName::CreateTempFileName(wxT("~"));
+ wxCurlHTTP url(m_url);
+ bool ok = url.Get(m_filename);
- return true;
-}
+ if (!ok) FbLogError(_("Download error"), m_url);
-bool FbUpdateItem::ReadURL()
-{
- m_filename = wxFileName::CreateTempFileName(wxT("~"));
- wxFileOutputStream out(m_filename);
-
- const size_t BUFSIZE = 1024;
- unsigned char buf[BUFSIZE];
- size_t size = m_input->GetSize();
- if (!size) size = 0xFFFFFFFF;
- size_t count = 0;
- size_t pos = 0;
-
- int step = 1;
- do {
- FbProgressEvent(ID_PROGRESS_UPDATE, m_url.GetURL(), pos * 1000 / size, _("File download")).Post();
- count = m_input->Read(buf, BUFSIZE).LastRead();
- if ( count ) {
- out.Write(buf, count);
- pos += count;
- } else step++;
- } while (pos < size && step < 5);
-
- FbProgressEvent(ID_PROGRESS_UPDATE).Post();
-
- return true;
+ return ok;
}
bool FbUpdateItem::OpenZip()
diff --git a/sources/MyRuLib/FbUpdateThread.h b/sources/MyRuLib/FbUpdateThread.h index 92321829..959e6a59 100644 --- a/sources/MyRuLib/FbUpdateThread.h +++ b/sources/MyRuLib/FbUpdateThread.h @@ -23,7 +23,6 @@ class FbUpdateItem: public wxObject int Execute();
private:
bool OpenURL();
- bool ReadURL();
bool OpenZip();
int DoUpdate();
void ExecInsert();
@@ -33,7 +32,7 @@ class FbUpdateItem: public wxObject wxSQLite3Database & m_database;
int m_code;
wxString m_type;
- FbURL m_url;
+ wxString m_url;
wxString m_filename;
wxString m_dataname;
wxInputStream * m_input;
diff --git a/sources/MyRuLib/MyRuLib.cbp b/sources/MyRuLib/MyRuLib.cbp index 857bc8d5..00dbd553 100644 --- a/sources/MyRuLib/MyRuLib.cbp +++ b/sources/MyRuLib/MyRuLib.cbp @@ -166,7 +166,9 @@ <Add directory="../SQLite3" /> <Add directory="../Expat" /> <Add directory="../wxBZipStream" /> + <Add directory="../wxCURL" /> <Add directory="../wxSQLite3" /> + <Add directory="../wxXML2" /> <Add directory="../build" /> </Compiler> <Linker> diff --git a/sources/MyRuLib/MyRuLibApp.cpp b/sources/MyRuLib/MyRuLibApp.cpp index 4b03dd12..d63b56a4 100644 --- a/sources/MyRuLib/MyRuLibApp.cpp +++ b/sources/MyRuLib/MyRuLibApp.cpp @@ -2,6 +2,7 @@ #include <wx/app.h>
#include <wx/fs_inet.h>
#include <wx/fs_mem.h>
+#include <wx/curl/http.h>
#include "FbDataPath.h"
#include "FbMainFrame.h"
#include "FbLogStream.h"
@@ -85,6 +86,7 @@ bool MyRuLibApp::OnInit() ::wxInitAllImageHandlers();
wxFileSystem::AddHandler(new wxMemoryFSHandler);
wxFileSystem::AddHandler(new wxInternetFSHandler);
+ wxCurlHTTP::Init();
LoadBlankImage();
diff --git a/sources/wxCURL/WxCURL.cbp b/sources/wxCURL/WxCURL.cbp index afceb21a..c7d3f828 100644 --- a/sources/wxCURL/WxCURL.cbp +++ b/sources/wxCURL/WxCURL.cbp @@ -17,6 +17,7 @@ <Compiler> <Add option="-Wall" /> <Add option="-g" /> + <Add option="`curl-config --cflags`" /> <Add option="`wx-config --cflags`" /> </Compiler> <Linker> @@ -32,8 +33,9 @@ <Option compiler="gcc" /> <Option createDefFile="1" /> <Compiler> - <Add option="-Wall" /> <Add option="-O2" /> + <Add option="-Wall" /> + <Add option="`curl-config --cflags`" /> <Add option="`wx-config --cflags`" /> </Compiler> <Linker> diff --git a/sources/wxXML2/WxXML2.cbp b/sources/wxXML2/WxXML2.cbp index 94bbdaca..34db2179 100644 --- a/sources/wxXML2/WxXML2.cbp +++ b/sources/wxXML2/WxXML2.cbp @@ -17,6 +17,7 @@ <Compiler> <Add option="-Wall" /> <Add option="-g" /> + <Add option="`xml2-config --cflags`" /> <Add option="`wx-config --cflags`" /> </Compiler> <Linker> @@ -32,8 +33,9 @@ <Option compiler="gcc" /> <Option createDefFile="1" /> <Compiler> - <Add option="-Wall" /> <Add option="-O2" /> + <Add option="-Wall" /> + <Add option="`xml2-config --cflags`" /> <Add option="`wx-config --cflags`" /> </Compiler> <Linker> |