Try to replace avhttp by Curl
This commit is contained in:
@@ -41,35 +41,7 @@
|
||||
* JP Charras.
|
||||
*/
|
||||
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* FIX ME
|
||||
* I do not include avhttp.hpp here, because it is already included in
|
||||
* github_plugin.cpp
|
||||
* and if it is also included in this file, the link fails (double definiton of modules)
|
||||
* therefore, the GITHUB_GETLIBLIST method which uses avhttp to download dats from gitub
|
||||
* is in github_plugin.cpp
|
||||
*/
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
// when WIN32_LEAN_AND_MEAN is defined, some useless includes in <window.h>
|
||||
// are skipped, and this avoid some compil issues
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
// defines needed by avhttp
|
||||
// Minimal Windows version is XP: Google for _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define WINVER 0x0501
|
||||
#endif
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <avhttp.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#include <kicad_curl/kicad_curl_easy.h> // Include before any wx file
|
||||
#include <wx/uri.h>
|
||||
|
||||
#include <github_getliblist.h>
|
||||
@@ -90,6 +62,7 @@ bool GITHUB_GETLIBLIST::Get3DshapesLibsList( wxArrayString* aList,
|
||||
bool (*aFilter)( const wxString& aData ) )
|
||||
{
|
||||
std::string fullURLCommand;
|
||||
|
||||
strcpy( m_option_string, "text/html" );
|
||||
|
||||
wxString repoURL = m_repoURL;
|
||||
@@ -97,7 +70,7 @@ bool GITHUB_GETLIBLIST::Get3DshapesLibsList( wxArrayString* aList,
|
||||
wxString errorMsg;
|
||||
|
||||
fullURLCommand = repoURL.utf8_str();
|
||||
bool success = remote_get_json( &fullURLCommand, &errorMsg );
|
||||
bool success = remoteGetJSON( fullURLCommand, &errorMsg );
|
||||
|
||||
if( !success )
|
||||
{
|
||||
@@ -123,6 +96,7 @@ bool GITHUB_GETLIBLIST::GetFootprintLibraryList( wxArrayString& aList )
|
||||
std::string fullURLCommand;
|
||||
int page = 1;
|
||||
int itemCountMax = 99; // Do not use a valu > 100, it does not work
|
||||
|
||||
strcpy( m_option_string, "application/json" );
|
||||
|
||||
// Github max items returned is 100 per page
|
||||
@@ -147,7 +121,7 @@ bool GITHUB_GETLIBLIST::GetFootprintLibraryList( wxArrayString& aList )
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
bool success = remote_get_json( &fullURLCommand, &errorMsg );
|
||||
bool success = remoteGetJSON( fullURLCommand, &errorMsg );
|
||||
|
||||
if( !success )
|
||||
{
|
||||
@@ -235,3 +209,37 @@ bool GITHUB_GETLIBLIST::repoURL2listURL( const wxString& aRepoURL,
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool GITHUB_GETLIBLIST::remoteGetJSON( const std::string& aFullURLCommand, wxString* aMsgError )
|
||||
{
|
||||
KICAD_CURL_EASY kcurl;
|
||||
|
||||
wxLogDebug( wxT( "Attempting to download: " ) + aFullURLCommand );
|
||||
|
||||
kcurl.SetURL( aFullURLCommand );
|
||||
kcurl.SetUserAgent( "http://kicad-pcb.org" );
|
||||
kcurl.SetHeader( "Accept", m_option_string );
|
||||
kcurl.SetFollowRedirects( true );
|
||||
|
||||
try
|
||||
{
|
||||
kcurl.Perform();
|
||||
m_image = kcurl.GetBuffer();
|
||||
return true;
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
if( aMsgError )
|
||||
{
|
||||
UTF8 fmt( _( "Error fetching JSON data from URL '%s'.\nReason: '%s'" ) );
|
||||
|
||||
std::string msg = StrPrintf( fmt.c_str(),
|
||||
aFullURLCommand.c_str(),
|
||||
TO_UTF8( ioe.errorText ) );
|
||||
|
||||
*aMsgError = FROM_UTF8( msg.c_str() );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user