From 22e95aab8bb5471593702e23aa173a4aacab29ab Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 14 Jul 2017 13:34:42 +0200 Subject: [PATCH] WIZARD_3DSHAPE_LIBS_DOWNLOADER: make it compatible with last url packages3D changes in kicad github repo --- .../wizard_3DShape_Libs_downloader.cpp | 23 +++++++++++++++---- .../dialogs/wizard_3DShape_Libs_downloader.h | 5 ++++ .../wizard_3DShape_Libs_downloader_base.cpp | 4 ++-- .../wizard_3DShape_Libs_downloader_base.fbp | 2 +- .../wizard_3DShape_Libs_downloader_base.h | 2 +- pcbnew/github/github_getliblist.cpp | 5 ++-- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/pcbnew/dialogs/wizard_3DShape_Libs_downloader.cpp b/pcbnew/dialogs/wizard_3DShape_Libs_downloader.cpp index 69ed72cb36..021282bff3 100644 --- a/pcbnew/dialogs/wizard_3DShape_Libs_downloader.cpp +++ b/pcbnew/dialogs/wizard_3DShape_Libs_downloader.cpp @@ -158,7 +158,7 @@ void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnSourceCheck( wxCommandEvent& aEvent ) void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnGridLibReviewSize( wxSizeEvent& event ) { - // Adjust the width of the column 1 afo m_gridLibReview (library names) to the + // Adjust the width of the column 1 of m_gridLibReview (library names) to the // max available width. int gridwidth = m_gridLibReview->GetClientSize().x; gridwidth -= m_gridLibReview->GetColSize( 0 ) + m_gridLibReview->GetColLabelSize(); @@ -262,7 +262,7 @@ void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnChangeSearch( wxCommandEvent& aEvent ) bool wasChecked = ( checkedStrings.Index( lib ) != wxNOT_FOUND ); int insertedIdx = -1; - if( !searchPhrase.IsEmpty() && lib.Lower().Contains( searchPhrase ) ) + if( !searchPhrase.IsEmpty() && lib.Lower().BeforeLast( '.' ).Contains( searchPhrase ) ) { insertedIdx = m_checkList3Dlibnames->Insert( lib, matching++ ); m_checkList3Dlibnames->SetSelection( insertedIdx ); @@ -359,15 +359,28 @@ bool WIZARD_3DSHAPE_LIBS_DOWNLOADER::downloadGithubLibsFromList( wxArrayString& aUrlList.GetCount(), GetParent(), wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_AUTO_HIDE ); - wxString url_base = GetGithubURL(); + // Built the full server name string: + wxURI repo( GetGithubURL() ); + wxString server = repo.GetScheme() + "://" + repo.GetServer(); // Download libs: for( unsigned ii = 0; ii < aUrlList.GetCount(); ii++ ) { wxString& libsrc_name = aUrlList[ii]; - // Extract the lib name from the full URL: - wxString url = GetGithubURL() + wxT( "/" ) + libsrc_name; + // Recover the full URL lib from short name: + // (note: m_githubLibs stores the URL relative to the server name) + wxString url; + + for( unsigned jj = 0; jj < m_githubLibs.GetCount(); jj++ ) + { + if( m_githubLibs[jj].EndsWith( libsrc_name ) ) + { + url = server + m_githubLibs[jj]; + break; + } + } + wxFileName fn( libsrc_name ); // Set our local path fn.SetPath( getDownloadDir() ); diff --git a/pcbnew/dialogs/wizard_3DShape_Libs_downloader.h b/pcbnew/dialogs/wizard_3DShape_Libs_downloader.h index 4913ad3fb5..5bb6723bcc 100644 --- a/pcbnew/dialogs/wizard_3DShape_Libs_downloader.h +++ b/pcbnew/dialogs/wizard_3DShape_Libs_downloader.h @@ -68,7 +68,12 @@ public: void OnPageChanged( wxWizardEvent& aEvent ) override; void OnSelectAll3Dlibs( wxCommandEvent& aEvent ) override; void OnUnselectAll3Dlibs( wxCommandEvent& aEvent ) override; + + /** Called when the content of m_searchCtrl3Dlibs has changed. + * Rebuild the list of libraries, lib cacdidate first + */ void OnChangeSearch( wxCommandEvent& aEvent ) override; + void OnWizardFinished( wxWizardEvent& aEvent ) override; void OnBrowseButtonClick( wxCommandEvent& aEvent ) override; void OnCheckSaveCopy( wxCommandEvent& aEvent ); diff --git a/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.cpp b/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.cpp index 8cde4a3986..3c9cbff5f3 100644 --- a/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.cpp +++ b/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jun 17 2015) +// C++ code generated with wxFormBuilder (version Jul 2 2017) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -36,7 +36,7 @@ WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE( wxWind m_staticText8->Wrap( -1 ); bSizer19->Add( m_staticText8, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - m_textCtrlGithubURL = new wxTextCtrl( m_wizPage1, wxID_ANY, _("http://github.com/KiCad"), wxDefaultPosition, wxDefaultSize, 0 ); + m_textCtrlGithubURL = new wxTextCtrl( m_wizPage1, wxID_ANY, _("https://github.com/KiCad/packages3d"), wxDefaultPosition, wxDefaultSize, 0 ); m_textCtrlGithubURL->SetMinSize( wxSize( 300,-1 ) ); bSizer19->Add( m_textCtrlGithubURL, 0, wxALL|wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.fbp b/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.fbp index 83cedb813f..e0727dac16 100644 --- a/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.fbp +++ b/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.fbp @@ -378,7 +378,7 @@ wxFILTER_NONE wxDefaultValidator - http://github.com/KiCad + https://github.com/KiCad/packages3d diff --git a/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.h b/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.h index 1e14d9db64..b04d32c3ec 100644 --- a/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.h +++ b/pcbnew/dialogs/wizard_3DShape_Libs_downloader_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jun 17 2015) +// C++ code generated with wxFormBuilder (version Jul 2 2017) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! diff --git a/pcbnew/github/github_getliblist.cpp b/pcbnew/github/github_getliblist.cpp index eec1a87138..9893aba5cf 100644 --- a/pcbnew/github/github_getliblist.cpp +++ b/pcbnew/github/github_getliblist.cpp @@ -65,10 +65,9 @@ bool GITHUB_GETLIBLIST::Get3DshapesLibsList( wxArrayString* aList, strcpy( m_option_string, "text/html" ); - wxString repoURL = m_repoURL; - wxString errorMsg; + wxString repoURL = m_repoURL; fullURLCommand = repoURL.utf8_str(); bool success = remoteGetJSON( fullURLCommand, &errorMsg ); @@ -95,7 +94,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 + int itemCountMax = 99; // Do not use a value >= 100, it does not work strcpy( m_option_string, "application/json" );