Formatting and "auto" reduction.
This commit is contained in:
parent
f6297d328c
commit
5777254cfa
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
|
* Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
|
||||||
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
@ -54,7 +54,8 @@ static std::vector<std::pair<PCM_PACKAGE_TYPE, wxString>> PACKAGE_TYPE_LIST = {
|
||||||
|
|
||||||
|
|
||||||
DIALOG_PCM::DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) :
|
DIALOG_PCM::DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) :
|
||||||
DIALOG_PCM_BASE( parent ), m_pcm( pcm )
|
DIALOG_PCM_BASE( parent ),
|
||||||
|
m_pcm( pcm )
|
||||||
{
|
{
|
||||||
m_defaultBitmap = KiBitmap( BITMAPS::icon_pcm );
|
m_defaultBitmap = KiBitmap( BITMAPS::icon_pcm );
|
||||||
|
|
||||||
|
@ -76,7 +77,9 @@ DIALOG_PCM::DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER
|
||||||
aData.current_version, aVersion ),
|
aData.current_version, aVersion ),
|
||||||
_( "Confirm update" ), wxICON_QUESTION | wxYES_NO, this )
|
_( "Confirm update" ), wxICON_QUESTION | wxYES_NO, this )
|
||||||
== wxNO )
|
== wxNO )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gridPendingActions->Freeze();
|
m_gridPendingActions->Freeze();
|
||||||
|
@ -126,11 +129,11 @@ DIALOG_PCM::DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER
|
||||||
|
|
||||||
m_pinCallback =
|
m_pinCallback =
|
||||||
[this]( const wxString& aPackageId, const PCM_PACKAGE_STATE aState, const bool aPinned )
|
[this]( const wxString& aPackageId, const PCM_PACKAGE_STATE aState, const bool aPinned )
|
||||||
{
|
{
|
||||||
m_pcm->SetPinned( aPackageId, aPinned );
|
m_pcm->SetPinned( aPackageId, aPinned );
|
||||||
|
|
||||||
updatePackageState( aPackageId, aState );
|
updatePackageState( aPackageId, aState );
|
||||||
};
|
};
|
||||||
|
|
||||||
m_installedPanel = new PANEL_PACKAGES_VIEW( m_panelInstalledHolder, m_pcm, m_actionCallback,
|
m_installedPanel = new PANEL_PACKAGES_VIEW( m_panelInstalledHolder, m_pcm, m_actionCallback,
|
||||||
m_pinCallback );
|
m_pinCallback );
|
||||||
|
@ -278,7 +281,8 @@ void DIALOG_PCM::OnRefreshClicked( wxCommandEvent& event )
|
||||||
void DIALOG_PCM::OnInstallFromFileClicked( wxCommandEvent& event )
|
void DIALOG_PCM::OnInstallFromFileClicked( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
wxFileDialog open_file_dialog( this, _( "Choose package file" ), wxEmptyString, wxEmptyString,
|
wxFileDialog open_file_dialog( this, _( "Choose package file" ), wxEmptyString, wxEmptyString,
|
||||||
"Zip files (*.zip)|*.zip", wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
wxT( "Zip files (*.zip)|*.zip" ),
|
||||||
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
||||||
|
|
||||||
if( open_file_dialog.ShowModal() == wxID_CANCEL )
|
if( open_file_dialog.ShowModal() == wxID_CANCEL )
|
||||||
return;
|
return;
|
||||||
|
@ -308,8 +312,8 @@ void DIALOG_PCM::setRepositoryData( const wxString& aRepositoryId )
|
||||||
{
|
{
|
||||||
if( m_pcm->CacheRepository( aRepositoryId ) )
|
if( m_pcm->CacheRepository( aRepositoryId ) )
|
||||||
{
|
{
|
||||||
for( const auto& entry : m_repositoryContentPanels )
|
for( const auto& [ packageType, packagesView ] : m_repositoryContentPanels )
|
||||||
entry.second->ClearData();
|
packagesView->ClearData();
|
||||||
|
|
||||||
m_packageBitmaps = m_pcm->GetRepositoryPackageBitmaps( aRepositoryId );
|
m_packageBitmaps = m_pcm->GetRepositoryPackageBitmaps( aRepositoryId );
|
||||||
|
|
||||||
|
@ -364,12 +368,12 @@ void DIALOG_PCM::setRepositoryData( const wxString& aRepositoryId )
|
||||||
PCM_PACKAGE_TYPE type = PACKAGE_TYPE_LIST[i].first;
|
PCM_PACKAGE_TYPE type = PACKAGE_TYPE_LIST[i].first;
|
||||||
const wxString& label = PACKAGE_TYPE_LIST[i].second;
|
const wxString& label = PACKAGE_TYPE_LIST[i].second;
|
||||||
m_repositoryContentPanels[type]->SetData( data[type] );
|
m_repositoryContentPanels[type]->SetData( data[type] );
|
||||||
m_contentNotebook->SetPageText(
|
m_contentNotebook->SetPageText( i, wxString::Format( wxGetTranslation( label ),
|
||||||
i, wxString::Format( wxGetTranslation( label ), (int) data[type].size() ) );
|
(int) data[type].size() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_dialogNotebook->SetPageText(
|
m_dialogNotebook->SetPageText( 0, wxString::Format( _( "Repository (%d)" ),
|
||||||
0, wxString::Format( _( "Repository (%d)" ), (int) packages.size() ) );
|
(int) packages.size() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,8 +387,8 @@ void DIALOG_PCM::OnPendingActionsCellClicked( wxGridEvent& event )
|
||||||
|
|
||||||
void DIALOG_PCM::updatePendingActionsTab()
|
void DIALOG_PCM::updatePendingActionsTab()
|
||||||
{
|
{
|
||||||
m_dialogNotebook->SetPageText(
|
m_dialogNotebook->SetPageText( 2, wxString::Format( _( "Pending (%d)" ),
|
||||||
2, wxString::Format( _( "Pending (%d)" ), (int) m_pendingActions.size() ) );
|
(int) m_pendingActions.size() ) );
|
||||||
|
|
||||||
for( int col = 0; col < m_gridPendingActions->GetNumberCols(); col++ )
|
for( int col = 0; col < m_gridPendingActions->GetNumberCols(); col++ )
|
||||||
{
|
{
|
||||||
|
@ -412,8 +416,8 @@ void DIALOG_PCM::setInstalledPackages()
|
||||||
else
|
else
|
||||||
package_data.bitmap = &m_defaultBitmap;
|
package_data.bitmap = &m_defaultBitmap;
|
||||||
|
|
||||||
package_data.state =
|
package_data.state = m_pcm->GetPackageState( entry.repository_id,
|
||||||
m_pcm->GetPackageState( entry.repository_id, entry.package.identifier );
|
entry.package.identifier );
|
||||||
|
|
||||||
if( package_data.state == PPS_UPDATE_AVAILABLE )
|
if( package_data.state == PPS_UPDATE_AVAILABLE )
|
||||||
package_data.update_version = m_pcm->GetPackageUpdateVersion( entry.package );
|
package_data.update_version = m_pcm->GetPackageUpdateVersion( entry.package );
|
||||||
|
@ -423,8 +427,8 @@ void DIALOG_PCM::setInstalledPackages()
|
||||||
|
|
||||||
m_installedPanel->SetData( package_list );
|
m_installedPanel->SetData( package_list );
|
||||||
|
|
||||||
m_dialogNotebook->SetPageText(
|
m_dialogNotebook->SetPageText( 1, wxString::Format( _( "Installed (%d)" ),
|
||||||
1, wxString::Format( _( "Installed (%d)" ), (int) package_list.size() ) );
|
(int) package_list.size() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -506,8 +510,8 @@ void DIALOG_PCM::discardAction( int aIndex )
|
||||||
|
|
||||||
PENDING_ACTION action = m_pendingActions[aIndex];
|
PENDING_ACTION action = m_pendingActions[aIndex];
|
||||||
|
|
||||||
PCM_PACKAGE_STATE state =
|
PCM_PACKAGE_STATE state = m_pcm->GetPackageState( action.repository_id,
|
||||||
m_pcm->GetPackageState( action.repository_id, action.package.identifier );
|
action.package.identifier );
|
||||||
|
|
||||||
updatePackageState( action.package.identifier, state );
|
updatePackageState( action.package.identifier, state );
|
||||||
|
|
||||||
|
@ -521,8 +525,8 @@ void DIALOG_PCM::updatePackageState( const wxString& aPackageId, const PCM_PACKA
|
||||||
|
|
||||||
m_installedPanel->SetPackageState( aPackageId, aState, pinned );
|
m_installedPanel->SetPackageState( aPackageId, aState, pinned );
|
||||||
|
|
||||||
for( const auto& entry : m_repositoryContentPanels )
|
for( const auto& [ packageType, packagesView ] : m_repositoryContentPanels )
|
||||||
entry.second->SetPackageState( aPackageId, aState, pinned );
|
packagesView->SetPackageState( aPackageId, aState, pinned );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
|
* Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
|
||||||
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
@ -26,7 +26,9 @@
|
||||||
PANEL_PACKAGE::PANEL_PACKAGE( wxWindow* parent, const ActionCallback& aCallback,
|
PANEL_PACKAGE::PANEL_PACKAGE( wxWindow* parent, const ActionCallback& aCallback,
|
||||||
const PinCallback& aPinCallback, const PACKAGE_VIEW_DATA& aData ) :
|
const PinCallback& aPinCallback, const PACKAGE_VIEW_DATA& aData ) :
|
||||||
PANEL_PACKAGE_BASE( parent ),
|
PANEL_PACKAGE_BASE( parent ),
|
||||||
m_actionCallback( aCallback ), m_pinCallback( aPinCallback ), m_data( aData )
|
m_actionCallback( aCallback ),
|
||||||
|
m_pinCallback( aPinCallback ),
|
||||||
|
m_data( aData )
|
||||||
{
|
{
|
||||||
// Propagate clicks on static elements to the panel handler.
|
// Propagate clicks on static elements to the panel handler.
|
||||||
m_name->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( PANEL_PACKAGE::OnClick ), NULL, this );
|
m_name->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( PANEL_PACKAGE::OnClick ), NULL, this );
|
||||||
|
@ -48,11 +50,11 @@ PANEL_PACKAGE::PANEL_PACKAGE( wxWindow* parent, const ActionCallback& aCallback,
|
||||||
|
|
||||||
m_minHeight = GetMinHeight();
|
m_minHeight = GetMinHeight();
|
||||||
|
|
||||||
double descLineHeight = m_desc->GetTextExtent( "X" ).GetHeight() * 1.2 /* leading */;
|
double descLineHeight = m_desc->GetTextExtent( wxT( "X" ) ).GetHeight() * 1.2 /* leading */;
|
||||||
m_desc->SetLabel( m_data.package.description );
|
m_desc->SetLabel( m_data.package.description );
|
||||||
descLineHeight = wxSplit( m_desc->GetLabel(), '\n' ).size() * descLineHeight;
|
descLineHeight = wxSplit( m_desc->GetLabel(), '\n' ).size() * descLineHeight;
|
||||||
|
|
||||||
int nameLineHeight = m_name->GetTextExtent( "X" ).GetHeight();
|
int nameLineHeight = m_name->GetTextExtent( wxT( "X" ) ).GetHeight();
|
||||||
wxSize minSize = GetMinSize();
|
wxSize minSize = GetMinSize();
|
||||||
minSize.y = std::max( nameLineHeight + KiROUND( descLineHeight ) + 15, m_minHeight );
|
minSize.y = std::max( nameLineHeight + KiROUND( descLineHeight ) + 15, m_minHeight );
|
||||||
SetMinSize( minSize );
|
SetMinSize( minSize );
|
||||||
|
@ -64,7 +66,7 @@ PANEL_PACKAGE::PANEL_PACKAGE( wxWindow* parent, const ActionCallback& aCallback,
|
||||||
m_pinVersionMenuItem =
|
m_pinVersionMenuItem =
|
||||||
splitMenu->Append( wxID_ANY, _( "Pin package" ),
|
splitMenu->Append( wxID_ANY, _( "Pin package" ),
|
||||||
_( "Pinned packages don't affect available update notification and "
|
_( "Pinned packages don't affect available update notification and "
|
||||||
"will not be updated with \"Update All\" button." ),
|
"will not be updated with 'Update All' button." ),
|
||||||
wxITEM_CHECK );
|
wxITEM_CHECK );
|
||||||
splitMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_PACKAGE::OnPinVersionClick, this,
|
splitMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_PACKAGE::OnPinVersionClick, this,
|
||||||
m_pinVersionMenuItem->GetId() );
|
m_pinVersionMenuItem->GetId() );
|
||||||
|
|
|
@ -131,11 +131,11 @@ void PANEL_PACKAGES_VIEW::SetData( const std::vector<PACKAGE_VIEW_DATA>& aPackag
|
||||||
|
|
||||||
for( const PACKAGE_VIEW_DATA& data : aPackageData )
|
for( const PACKAGE_VIEW_DATA& data : aPackageData )
|
||||||
{
|
{
|
||||||
PANEL_PACKAGE* package_panel =
|
PANEL_PACKAGE* package_panel = new PANEL_PACKAGE( m_packageListWindow, m_actionCallback,
|
||||||
new PANEL_PACKAGE( m_packageListWindow, m_actionCallback, m_pinCallback, data );
|
m_pinCallback, data );
|
||||||
|
|
||||||
package_panel->SetSelectCallback(
|
package_panel->SetSelectCallback(
|
||||||
[package_panel, this]()
|
[package_panel, this] ()
|
||||||
{
|
{
|
||||||
if( m_currentSelected && m_currentSelected != package_panel )
|
if( m_currentSelected && m_currentSelected != package_panel )
|
||||||
m_currentSelected->SetSelected( false );
|
m_currentSelected->SetSelected( false );
|
||||||
|
@ -166,57 +166,59 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
|
||||||
// Details
|
// Details
|
||||||
wxString details;
|
wxString details;
|
||||||
|
|
||||||
details << "<h5>" + package.name + "</h5>";
|
details << wxT( "<h5>" ) + package.name + wxT( "</h5>" );
|
||||||
|
|
||||||
auto format_desc = []( const wxString& text ) -> wxString
|
auto format_desc =
|
||||||
{
|
[]( const wxString& text ) -> wxString
|
||||||
wxString result;
|
|
||||||
bool inURL = false;
|
|
||||||
wxString url;
|
|
||||||
|
|
||||||
for( unsigned i = 0; i < text.length(); ++i )
|
|
||||||
{
|
|
||||||
wxUniChar c = text[i];
|
|
||||||
|
|
||||||
if( inURL )
|
|
||||||
{
|
{
|
||||||
if( c == ' ' )
|
wxString result;
|
||||||
|
bool inURL = false;
|
||||||
|
wxString url;
|
||||||
|
|
||||||
|
for( unsigned i = 0; i < text.length(); ++i )
|
||||||
{
|
{
|
||||||
result += wxString::Format( "<a href='%s'>%s</a>", url, url );
|
wxUniChar c = text[i];
|
||||||
inURL = false;
|
|
||||||
|
|
||||||
result += c;
|
if( inURL )
|
||||||
}
|
{
|
||||||
else
|
if( c == ' ' )
|
||||||
{
|
{
|
||||||
url += c;
|
result += wxString::Format( wxT( "<a href='%s'>%s</a>" ), url, url );
|
||||||
}
|
inURL = false;
|
||||||
}
|
|
||||||
else if( text.Mid( i, 5 ) == "http:" || text.Mid( i, 6 ) == "https:" )
|
|
||||||
{
|
|
||||||
url = c;
|
|
||||||
inURL = true;
|
|
||||||
}
|
|
||||||
else if( c == '\n' )
|
|
||||||
{
|
|
||||||
result += "</p><p>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
result += c;
|
||||||
};
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( text.Mid( i, 5 ) == wxT( "http:" )
|
||||||
|
|| text.Mid( i, 6 ) == wxT( "https:" ) )
|
||||||
|
{
|
||||||
|
url = c;
|
||||||
|
inURL = true;
|
||||||
|
}
|
||||||
|
else if( c == '\n' )
|
||||||
|
{
|
||||||
|
result += wxT( "</p><p>" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
wxString desc = package.description_full;
|
wxString desc = package.description_full;
|
||||||
details << "<p>" + format_desc( desc ) + "</p>";
|
details << wxT( "<p>" ) + format_desc( desc ) + wxT( "</p>" );
|
||||||
|
|
||||||
details << "<p><b>" + _( "Metadata" ) + "</b></p>";
|
details << wxT( "<p><b>" ) + _( "Metadata" ) + wxT( "</b></p>" );
|
||||||
details << "<ul>";
|
details << wxT( "<ul>" );
|
||||||
details << "<li>" + _( "Package identifier: " ) + package.identifier + "</li>";
|
details << wxT( "<li>" ) + _( "Package identifier: " ) + package.identifier + wxT( "</li>" );
|
||||||
details << "<li>" + _( "License: " ) + package.license + "</li>";
|
details << wxT( "<li>" ) + _( "License: " ) + package.license + wxT( "</li>" );
|
||||||
|
|
||||||
if( package.tags.size() > 0 )
|
if( package.tags.size() > 0 )
|
||||||
{
|
{
|
||||||
|
@ -230,31 +232,37 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
|
||||||
tags_str += tag;
|
tags_str += tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
details << "<li>" + _( "Tags: " ) + tags_str + "</li>";
|
details << wxT( "<li>" ) + _( "Tags: " ) + tags_str + wxT( "</li>" );
|
||||||
}
|
}
|
||||||
|
|
||||||
auto format_entry = []( const std::pair<const std::string, wxString>& entry ) -> wxString
|
auto format_entry =
|
||||||
{
|
[]( const std::pair<const std::string, wxString>& entry ) -> wxString
|
||||||
wxString name = entry.first;
|
{
|
||||||
wxString url = EscapeHTML( entry.second );
|
wxString name = entry.first;
|
||||||
|
wxString url = EscapeHTML( entry.second );
|
||||||
|
|
||||||
if( name == "email" )
|
if( name == wxT( "email" ) )
|
||||||
return wxString::Format( "<a href='mailto:%s'>%s</a>", url, url );
|
return wxString::Format( wxT( "<a href='mailto:%s'>%s</a>" ), url, url );
|
||||||
else if( url.StartsWith( "http:" ) || url.StartsWith( "https:" ) )
|
else if( url.StartsWith( wxT( "http:" ) ) || url.StartsWith( wxT( "https:" ) ) )
|
||||||
return wxString::Format( "<a href='%s'>%s</a>", url, url );
|
return wxString::Format( wxT( "<a href='%s'>%s</a>" ), url, url );
|
||||||
else
|
else
|
||||||
return entry.second;
|
return entry.second;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto write_contact = [&]( const wxString& type, const PCM_CONTACT& contact )
|
auto write_contact =
|
||||||
{
|
[&]( const wxString& type, const PCM_CONTACT& contact )
|
||||||
details << "<li>" + type + ": " + contact.name + "<ul>";
|
{
|
||||||
|
details << wxT( "<li>" ) + type + wxT( ": " ) + contact.name + wxT( "<ul>" );
|
||||||
|
|
||||||
for( const std::pair<const std::string, wxString>& entry : contact.contact )
|
for( const std::pair<const std::string, wxString>& entry : contact.contact )
|
||||||
details << "<li>" + entry.first + ": " + format_entry( entry ) + "</li>";
|
{
|
||||||
|
details << wxT( "<li>" );
|
||||||
|
details << entry.first + wxT( ": " ) + format_entry( entry );
|
||||||
|
details << wxT( "</li>" );
|
||||||
|
}
|
||||||
|
|
||||||
details << "</ul>";
|
details << wxT( "</ul>" );
|
||||||
};
|
};
|
||||||
|
|
||||||
write_contact( _( "Author" ), package.author );
|
write_contact( _( "Author" ), package.author );
|
||||||
|
|
||||||
|
@ -263,15 +271,19 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
|
||||||
|
|
||||||
if( package.resources.size() > 0 )
|
if( package.resources.size() > 0 )
|
||||||
{
|
{
|
||||||
details << "<li>" + _( "Resources" ) + "<ul>";
|
details << wxT( "<li>" ) + _( "Resources" ) + wxT( "<ul>" );
|
||||||
|
|
||||||
for( const std::pair<const std::string, wxString>& entry : package.resources )
|
for( const std::pair<const std::string, wxString>& entry : package.resources )
|
||||||
details << "<li>" + entry.first + wxS( ": " ) + format_entry( entry ) + "</li>";
|
{
|
||||||
|
details << wxT( "<li>" );
|
||||||
|
details << entry.first + wxT( ": " );
|
||||||
|
details << format_entry( entry ) + wxT( "</li>" );
|
||||||
|
}
|
||||||
|
|
||||||
details << "</ul>";
|
details << wxT( "</ul>" );
|
||||||
}
|
}
|
||||||
|
|
||||||
details << "</ul>";
|
details << wxT( "</ul>" );
|
||||||
|
|
||||||
m_infoText->SetPage( details );
|
m_infoText->SetPage( details );
|
||||||
|
|
||||||
|
@ -387,17 +399,17 @@ void PANEL_PACKAGES_VIEW::unsetPackageDetails()
|
||||||
wxString PANEL_PACKAGES_VIEW::toHumanReadableSize( const std::optional<uint64_t> size ) const
|
wxString PANEL_PACKAGES_VIEW::toHumanReadableSize( const std::optional<uint64_t> size ) const
|
||||||
{
|
{
|
||||||
if( !size )
|
if( !size )
|
||||||
return "-";
|
return wxT( "-" );
|
||||||
|
|
||||||
uint64_t b = *size;
|
uint64_t b = *size;
|
||||||
|
|
||||||
if( b >= 1024 * 1024 )
|
if( b >= 1024 * 1024 )
|
||||||
return wxString::Format( "%.1f MB", b / 1000.0 / 1000.0 );
|
return wxString::Format( wxT( "%.1f MB" ), b / 1000.0 / 1000.0 );
|
||||||
|
|
||||||
if( b >= 1024 )
|
if( b >= 1024 )
|
||||||
return wxString::Format( "%lld kB", b / 1000 );
|
return wxString::Format( wxT( "%lld kB" ), b / 1000 );
|
||||||
|
|
||||||
return wxString::Format( "%lld B", b );
|
return wxString::Format( wxT( "%lld B" ), b );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -504,8 +516,8 @@ void PANEL_PACKAGES_VIEW::OnDownloadVersionClicked( wxCommandEvent& event )
|
||||||
KICAD_SETTINGS* app_settings = mgr.GetAppSettings<KICAD_SETTINGS>();
|
KICAD_SETTINGS* app_settings = mgr.GetAppSettings<KICAD_SETTINGS>();
|
||||||
|
|
||||||
wxFileDialog dialog( this, _( "Save package" ), app_settings->m_PcmLastDownloadDir,
|
wxFileDialog dialog( this, _( "Save package" ), app_settings->m_PcmLastDownloadDir,
|
||||||
wxString::Format( "%s_v%s.zip", package.identifier, version ),
|
wxString::Format( wxT( "%s_v%s.zip" ), package.identifier, version ),
|
||||||
"ZIP files (*.zip)|*.zip", wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
wxT( "ZIP files (*.zip)|*.zip" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
||||||
|
|
||||||
if( dialog.ShowModal() == wxID_CANCEL )
|
if( dialog.ShowModal() == wxID_CANCEL )
|
||||||
return;
|
return;
|
||||||
|
@ -705,7 +717,7 @@ PCM_PACKAGE_ACTION PANEL_PACKAGES_VIEW::getAction() const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_gridVersions->GetNumberRows() == 1
|
wxASSERT_MSG( m_gridVersions->GetNumberRows() == 1
|
||||||
|| m_gridVersions->GetSelectedRows().size() == 1,
|
|| m_gridVersions->GetSelectedRows().size() == 1,
|
||||||
"getAction() called with ambiguous version selection" );
|
wxT( "getAction() called with ambiguous version selection" ) );
|
||||||
|
|
||||||
int selected_row = 0;
|
int selected_row = 0;
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,8 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/filefn.h>
|
#include <wx/filefn.h>
|
||||||
#include <wx/fs_zip.h>
|
|
||||||
#include <wx/image.h>
|
#include <wx/image.h>
|
||||||
#include <wx/mstream.h>
|
#include <wx/mstream.h>
|
||||||
#include <wx/sstream.h>
|
|
||||||
#include <wx/tokenzr.h>
|
#include <wx/tokenzr.h>
|
||||||
#include <wx/wfstream.h>
|
#include <wx/wfstream.h>
|
||||||
#include <wx/zipstrm.h>
|
#include <wx/zipstrm.h>
|
||||||
|
@ -77,7 +75,7 @@ public:
|
||||||
|
|
||||||
void Report( const wxString& aMessage ) override
|
void Report( const wxString& aMessage ) override
|
||||||
{
|
{
|
||||||
m_report = wxString::Format( ": %s", aMessage );
|
m_report = wxString::Format( wxT( ": %s" ), aMessage );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cancel() { m_cancelled.store( true ); }
|
void Cancel() { m_cancelled.store( true ); }
|
||||||
|
@ -85,7 +83,7 @@ public:
|
||||||
private:
|
private:
|
||||||
bool updateUI() override
|
bool updateUI() override
|
||||||
{
|
{
|
||||||
m_statusCallback( wxString::Format( "%s%s", m_title, m_report ) );
|
m_statusCallback( wxString::Format( wxT( "%s%s" ), m_title, m_report ) );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +95,11 @@ private:
|
||||||
|
|
||||||
|
|
||||||
PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER(
|
PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER(
|
||||||
std::function<void( int )> aAvailableUpdateCallback,
|
std::function<void( int )> aAvailableUpdateCallback,
|
||||||
std::function<void( const wxString )> aStatusCallback ) :
|
std::function<void( const wxString )> aStatusCallback ) :
|
||||||
m_dialog( nullptr ),
|
m_dialog( nullptr ),
|
||||||
m_availableUpdateCallback( aAvailableUpdateCallback ), m_statusCallback( aStatusCallback )
|
m_availableUpdateCallback( aAvailableUpdateCallback ),
|
||||||
|
m_statusCallback( aStatusCallback )
|
||||||
{
|
{
|
||||||
ReadEnvVar();
|
ReadEnvVar();
|
||||||
|
|
||||||
|
@ -120,14 +119,18 @@ PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER(
|
||||||
catch( std::exception& e )
|
catch( std::exception& e )
|
||||||
{
|
{
|
||||||
if( !schema_file.FileExists() )
|
if( !schema_file.FileExists() )
|
||||||
|
{
|
||||||
wxLogError( wxString::Format( _( "schema file '%s' not found" ),
|
wxLogError( wxString::Format( _( "schema file '%s' not found" ),
|
||||||
schema_file.GetFullPath() ) );
|
schema_file.GetFullPath() ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
wxLogError( wxString::Format( _( "Error loading schema: %s" ), e.what() ) );
|
wxLogError( wxString::Format( _( "Error loading schema: %s" ), e.what() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load currently installed packages
|
// Load currently installed packages
|
||||||
wxFileName f( SETTINGS_MANAGER::GetUserSettingsPath(), "installed_packages.json" );
|
wxFileName f( SETTINGS_MANAGER::GetUserSettingsPath(), wxT( "installed_packages.json" ) );
|
||||||
|
|
||||||
if( f.FileExists() )
|
if( f.FileExists() )
|
||||||
{
|
{
|
||||||
|
@ -158,7 +161,7 @@ PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER(
|
||||||
|
|
||||||
for( const wxString& dir : PCM_PACKAGE_DIRECTORIES )
|
for( const wxString& dir : PCM_PACKAGE_DIRECTORIES )
|
||||||
{
|
{
|
||||||
wxFileName d( m_3rdparty_path, "" );
|
wxFileName d( m_3rdparty_path, wxEmptyString );
|
||||||
d.AppendDir( dir );
|
d.AppendDir( dir );
|
||||||
|
|
||||||
if( d.DirExists() )
|
if( d.DirExists() )
|
||||||
|
@ -210,7 +213,7 @@ PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER(
|
||||||
|
|
||||||
// Calculate package compatibility
|
// Calculate package compatibility
|
||||||
std::for_each( m_installed.begin(), m_installed.end(),
|
std::for_each( m_installed.begin(), m_installed.end(),
|
||||||
[&]( auto& entry )
|
[&]( std::pair<const wxString, PCM_INSTALLATION_ENTRY>& entry )
|
||||||
{
|
{
|
||||||
preparePackage( entry.second.package );
|
preparePackage( entry.second.package );
|
||||||
} );
|
} );
|
||||||
|
@ -221,7 +224,7 @@ void PLUGIN_CONTENT_MANAGER::ReadEnvVar()
|
||||||
{
|
{
|
||||||
// Get 3rd party path
|
// Get 3rd party path
|
||||||
const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables();
|
const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables();
|
||||||
auto it = env.find( "KICAD6_3RD_PARTY" );
|
auto it = env.find( wxT( "KICAD6_3RD_PARTY" ) );
|
||||||
|
|
||||||
if( it != env.end() && !it->second.GetValue().IsEmpty() )
|
if( it != env.end() && !it->second.GetValue().IsEmpty() )
|
||||||
m_3rdparty_path = it->second.GetValue();
|
m_3rdparty_path = it->second.GetValue();
|
||||||
|
@ -374,8 +377,10 @@ bool PLUGIN_CONTENT_MANAGER::fetchPackages( const wxString& aUrl,
|
||||||
catch( std::exception& e )
|
catch( std::exception& e )
|
||||||
{
|
{
|
||||||
if( m_dialog )
|
if( m_dialog )
|
||||||
wxLogError(
|
{
|
||||||
wxString::Format( _( "Unable to parse packages metadata:\n\n%s" ), e.what() ) );
|
wxLogError( wxString::Format( _( "Unable to parse packages metadata:\n\n%s" ),
|
||||||
|
e.what() ) );
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -400,7 +405,7 @@ const PCM_REPOSITORY&
|
||||||
PLUGIN_CONTENT_MANAGER::getCachedRepository( const wxString& aRepositoryId ) const
|
PLUGIN_CONTENT_MANAGER::getCachedRepository( const wxString& aRepositoryId ) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_repository_cache.find( aRepositoryId ) != m_repository_cache.end(),
|
wxASSERT_MSG( m_repository_cache.find( aRepositoryId ) != m_repository_cache.end(),
|
||||||
"Repository is not cached." );
|
wxT( "Repository is not cached." ) );
|
||||||
|
|
||||||
return m_repository_cache.at( aRepositoryId );
|
return m_repository_cache.at( aRepositoryId );
|
||||||
}
|
}
|
||||||
|
@ -429,7 +434,7 @@ const bool PLUGIN_CONTENT_MANAGER::CacheRepository( const wxString& aRepositoryI
|
||||||
std::shared_ptr<PROGRESS_REPORTER> reporter;
|
std::shared_ptr<PROGRESS_REPORTER> reporter;
|
||||||
|
|
||||||
if( m_dialog )
|
if( m_dialog )
|
||||||
reporter = std::make_shared<WX_PROGRESS_REPORTER>( m_dialog, wxT( "" ), 1 );
|
reporter = std::make_shared<WX_PROGRESS_REPORTER>( m_dialog, wxEmptyString, 1 );
|
||||||
else
|
else
|
||||||
reporter = m_statusReporter;
|
reporter = m_statusReporter;
|
||||||
|
|
||||||
|
@ -439,10 +444,10 @@ const bool PLUGIN_CONTENT_MANAGER::CacheRepository( const wxString& aRepositoryI
|
||||||
bool packages_cache_exists = false;
|
bool packages_cache_exists = false;
|
||||||
|
|
||||||
// First load repository data from local filesystem if available.
|
// First load repository data from local filesystem if available.
|
||||||
wxFileName repo_cache = wxFileName( PATHS::GetUserCachePath(), "repository.json" );
|
wxFileName repo_cache = wxFileName( PATHS::GetUserCachePath(), wxT( "repository.json" ) );
|
||||||
repo_cache.AppendDir( "pcm" );
|
repo_cache.AppendDir( wxT( "pcm" ) );
|
||||||
repo_cache.AppendDir( aRepositoryId );
|
repo_cache.AppendDir( aRepositoryId );
|
||||||
wxFileName packages_cache( repo_cache.GetPath(), "packages.json" );
|
wxFileName packages_cache( repo_cache.GetPath(), wxT( "packages.json" ) );
|
||||||
|
|
||||||
if( repo_cache.FileExists() && packages_cache.FileExists() )
|
if( repo_cache.FileExists() && packages_cache.FileExists() )
|
||||||
{
|
{
|
||||||
|
@ -474,8 +479,10 @@ const bool PLUGIN_CONTENT_MANAGER::CacheRepository( const wxString& aRepositoryI
|
||||||
catch( ... )
|
catch( ... )
|
||||||
{
|
{
|
||||||
if( m_dialog )
|
if( m_dialog )
|
||||||
wxLogError( _( "Packages cache for current repository is "
|
{
|
||||||
"corrupted, it will be redownloaded." ) );
|
wxLogError( _( "Packages cache for current repository is corrupted, it will "
|
||||||
|
"be redownloaded." ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,7 +520,7 @@ const bool PLUGIN_CONTENT_MANAGER::CacheRepository( const wxString& aRepositoryI
|
||||||
// Check resources file date, redownload if needed
|
// Check resources file date, redownload if needed
|
||||||
PCM_RESOURCE_REFERENCE& resources = *current_repo.resources;
|
PCM_RESOURCE_REFERENCE& resources = *current_repo.resources;
|
||||||
|
|
||||||
wxFileName resource_file( repo_cache.GetPath(), "resources.zip" );
|
wxFileName resource_file( repo_cache.GetPath(), wxT( "resources.zip" ) );
|
||||||
|
|
||||||
time_t mtime = 0;
|
time_t mtime = 0;
|
||||||
|
|
||||||
|
@ -544,8 +551,10 @@ const bool PLUGIN_CONTENT_MANAGER::CacheRepository( const wxString& aRepositoryI
|
||||||
read_stream.close();
|
read_stream.close();
|
||||||
|
|
||||||
if( m_dialog )
|
if( m_dialog )
|
||||||
|
{
|
||||||
wxLogError( _( "Resources file hash doesn't match and will not be used. "
|
wxLogError( _( "Resources file hash doesn't match and will not be used. "
|
||||||
"Repository may be corrupted." ) );
|
"Repository may be corrupted." ) );
|
||||||
|
}
|
||||||
|
|
||||||
wxRemoveFile( resource_file.GetFullPath() );
|
wxRemoveFile( resource_file.GetFullPath() );
|
||||||
}
|
}
|
||||||
|
@ -578,51 +587,47 @@ void PLUGIN_CONTENT_MANAGER::updateInstalledPackagesMetadata( const wxString& aR
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( auto& entry : m_installed )
|
for( std::pair<const wxString, PCM_INSTALLATION_ENTRY>& pair : m_installed )
|
||||||
{
|
{
|
||||||
PCM_INSTALLATION_ENTRY& installation_entry = entry.second;
|
PCM_INSTALLATION_ENTRY& entry = pair.second;
|
||||||
|
|
||||||
// If current package is not from this repository, skip it
|
// If current package is not from this repository, skip it
|
||||||
if( installation_entry.repository_id != aRepositoryId )
|
if( entry.repository_id != aRepositoryId )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If current package is no longer in this repository, keep it as is
|
// If current package is no longer in this repository, keep it as is
|
||||||
if( repository->package_map.count( installation_entry.package.identifier ) == 0 )
|
if( repository->package_map.count( entry.package.identifier ) == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::optional<PACKAGE_VERSION> current_version;
|
std::optional<PACKAGE_VERSION> current_version;
|
||||||
|
|
||||||
auto current_version_it =
|
auto current_version_it =
|
||||||
std::find_if( installation_entry.package.versions.begin(),
|
std::find_if( entry.package.versions.begin(), entry.package.versions.end(),
|
||||||
installation_entry.package.versions.end(),
|
|
||||||
[&]( const PACKAGE_VERSION& version )
|
[&]( const PACKAGE_VERSION& version )
|
||||||
{
|
{
|
||||||
return version.version == installation_entry.current_version;
|
return version.version == entry.current_version;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if( current_version_it != installation_entry.package.versions.end() )
|
if( current_version_it != entry.package.versions.end() )
|
||||||
current_version = *current_version_it; // copy
|
current_version = *current_version_it; // copy
|
||||||
|
|
||||||
// Copy repository metadata into installation entry
|
// Copy repository metadata into installation entry
|
||||||
installation_entry.package = repository->package_list[repository->package_map.at(
|
entry.package = repository->package_list[repository->package_map.at( entry.package.identifier )];
|
||||||
installation_entry.package.identifier )];
|
|
||||||
|
|
||||||
// Insert current version if it's missing from repository metadata
|
// Insert current version if it's missing from repository metadata
|
||||||
current_version_it =
|
current_version_it =
|
||||||
std::find_if( installation_entry.package.versions.begin(),
|
std::find_if( entry.package.versions.begin(), entry.package.versions.end(),
|
||||||
installation_entry.package.versions.end(),
|
|
||||||
[&]( const PACKAGE_VERSION& version )
|
[&]( const PACKAGE_VERSION& version )
|
||||||
{
|
{
|
||||||
return version.version == installation_entry.current_version;
|
return version.version == entry.current_version;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if( current_version_it == installation_entry.package.versions.end() )
|
if( current_version_it == entry.package.versions.end() )
|
||||||
{
|
{
|
||||||
installation_entry.package.versions.emplace_back( *current_version );
|
entry.package.versions.emplace_back( *current_version );
|
||||||
|
|
||||||
// Re-sort the versions by descending version
|
// Re-sort the versions by descending version
|
||||||
std::sort( installation_entry.package.versions.begin(),
|
std::sort( entry.package.versions.begin(), entry.package.versions.end(),
|
||||||
installation_entry.package.versions.end(),
|
|
||||||
[]( const PACKAGE_VERSION& a, const PACKAGE_VERSION& b )
|
[]( const PACKAGE_VERSION& a, const PACKAGE_VERSION& b )
|
||||||
{
|
{
|
||||||
return a.parsed_version > b.parsed_version;
|
return a.parsed_version > b.parsed_version;
|
||||||
|
@ -642,7 +647,7 @@ void PLUGIN_CONTENT_MANAGER::preparePackage( PCM_PACKAGE& aPackage )
|
||||||
if( ver.version_epoch )
|
if( ver.version_epoch )
|
||||||
epoch = *ver.version_epoch;
|
epoch = *ver.version_epoch;
|
||||||
|
|
||||||
wxStringTokenizer version_tokenizer( ver.version, "." );
|
wxStringTokenizer version_tokenizer( ver.version, wxT( "." ) );
|
||||||
|
|
||||||
major = wxAtoi( version_tokenizer.GetNextToken() );
|
major = wxAtoi( version_tokenizer.GetNextToken() );
|
||||||
|
|
||||||
|
@ -657,24 +662,25 @@ void PLUGIN_CONTENT_MANAGER::preparePackage( PCM_PACKAGE& aPackage )
|
||||||
// Determine compatibility
|
// Determine compatibility
|
||||||
ver.compatible = true;
|
ver.compatible = true;
|
||||||
|
|
||||||
auto parse_version_tuple = []( const wxString& version, int deflt )
|
auto parse_version_tuple =
|
||||||
{
|
[]( const wxString& version, int deflt )
|
||||||
int ver_major = deflt;
|
{
|
||||||
int ver_minor = deflt;
|
int ver_major = deflt;
|
||||||
int ver_patch = deflt;
|
int ver_minor = deflt;
|
||||||
|
int ver_patch = deflt;
|
||||||
|
|
||||||
wxStringTokenizer tokenizer( version, "." );
|
wxStringTokenizer tokenizer( version, wxT( "." ) );
|
||||||
|
|
||||||
ver_major = wxAtoi( tokenizer.GetNextToken() );
|
ver_major = wxAtoi( tokenizer.GetNextToken() );
|
||||||
|
|
||||||
if( tokenizer.HasMoreTokens() )
|
if( tokenizer.HasMoreTokens() )
|
||||||
ver_minor = wxAtoi( tokenizer.GetNextToken() );
|
ver_minor = wxAtoi( tokenizer.GetNextToken() );
|
||||||
|
|
||||||
if( tokenizer.HasMoreTokens() )
|
if( tokenizer.HasMoreTokens() )
|
||||||
ver_patch = wxAtoi( tokenizer.GetNextToken() );
|
ver_patch = wxAtoi( tokenizer.GetNextToken() );
|
||||||
|
|
||||||
return std::tuple<int, int, int>( ver_major, ver_minor, ver_patch );
|
return std::tuple<int, int, int>( ver_major, ver_minor, ver_patch );
|
||||||
};
|
};
|
||||||
|
|
||||||
if( parse_version_tuple( ver.kicad_version, 0 ) > m_kicad_version )
|
if( parse_version_tuple( ver.kicad_version, 0 ) > m_kicad_version )
|
||||||
ver.compatible = false;
|
ver.compatible = false;
|
||||||
|
@ -729,7 +735,7 @@ PLUGIN_CONTENT_MANAGER::GetRepositoryPackages( const wxString& aRepositoryId ) c
|
||||||
void PLUGIN_CONTENT_MANAGER::SetRepositoryList( const STRING_PAIR_LIST& aRepositories )
|
void PLUGIN_CONTENT_MANAGER::SetRepositoryList( const STRING_PAIR_LIST& aRepositories )
|
||||||
{
|
{
|
||||||
// Clean up cache folder if repository is not in new list
|
// Clean up cache folder if repository is not in new list
|
||||||
for( const auto& entry : m_repository_list )
|
for( const std::tuple<wxString, wxString, wxString>& entry : m_repository_list )
|
||||||
{
|
{
|
||||||
auto it = std::find_if( aRepositories.begin(), aRepositories.end(),
|
auto it = std::find_if( aRepositories.begin(), aRepositories.end(),
|
||||||
[&]( const auto& new_entry )
|
[&]( const auto& new_entry )
|
||||||
|
@ -746,11 +752,11 @@ void PLUGIN_CONTENT_MANAGER::SetRepositoryList( const STRING_PAIR_LIST& aReposit
|
||||||
m_repository_list.clear();
|
m_repository_list.clear();
|
||||||
m_repository_cache.clear();
|
m_repository_cache.clear();
|
||||||
|
|
||||||
for( const auto& repo : aRepositories )
|
for( const std::pair<wxString, wxString>& repo : aRepositories )
|
||||||
{
|
{
|
||||||
std::string url_sha = picosha2::hash256_hex_string( repo.second );
|
std::string url_sha = picosha2::hash256_hex_string( repo.second );
|
||||||
m_repository_list.push_back(
|
m_repository_list.push_back( std::make_tuple( url_sha.substr( 0, 16 ), repo.first,
|
||||||
std::make_tuple( url_sha.substr( 0, 16 ), repo.first, repo.second ) );
|
repo.second ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +767,7 @@ void PLUGIN_CONTENT_MANAGER::DiscardRepositoryCache( const wxString& aRepository
|
||||||
m_repository_cache.erase( aRepositoryId );
|
m_repository_cache.erase( aRepositoryId );
|
||||||
|
|
||||||
wxFileName repo_cache = wxFileName( PATHS::GetUserCachePath(), "" );
|
wxFileName repo_cache = wxFileName( PATHS::GetUserCachePath(), "" );
|
||||||
repo_cache.AppendDir( "pcm" );
|
repo_cache.AppendDir( wxT( "pcm" ) );
|
||||||
repo_cache.AppendDir( aRepositoryId );
|
repo_cache.AppendDir( aRepositoryId );
|
||||||
|
|
||||||
if( repo_cache.DirExists() )
|
if( repo_cache.DirExists() )
|
||||||
|
@ -853,24 +859,25 @@ PCM_PACKAGE_STATE PLUGIN_CONTENT_MANAGER::GetPackageState( const wxString& aRepo
|
||||||
const wxString PLUGIN_CONTENT_MANAGER::GetPackageUpdateVersion( const PCM_PACKAGE& aPackage )
|
const wxString PLUGIN_CONTENT_MANAGER::GetPackageUpdateVersion( const PCM_PACKAGE& aPackage )
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_installed.find( aPackage.identifier ) != m_installed.end(),
|
wxASSERT_MSG( m_installed.find( aPackage.identifier ) != m_installed.end(),
|
||||||
"GetPackageUpdateVersion called on a not installed package" );
|
wxT( "GetPackageUpdateVersion called on a not installed package" ) );
|
||||||
|
|
||||||
const PCM_INSTALLATION_ENTRY& installation_entry = m_installed.at( aPackage.identifier );
|
const PCM_INSTALLATION_ENTRY& entry = m_installed.at( aPackage.identifier );
|
||||||
|
|
||||||
auto installed_ver_it = std::find_if(
|
auto installed_ver_it = std::find_if(
|
||||||
installation_entry.package.versions.begin(), installation_entry.package.versions.end(),
|
entry.package.versions.begin(), entry.package.versions.end(),
|
||||||
[&]( const PACKAGE_VERSION& ver )
|
[&]( const PACKAGE_VERSION& ver )
|
||||||
{
|
{
|
||||||
return ver.version == installation_entry.current_version;
|
return ver.version == entry.current_version;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
wxASSERT_MSG( installed_ver_it != installation_entry.package.versions.end(),
|
wxASSERT_MSG( installed_ver_it != entry.package.versions.end(),
|
||||||
"Installed package version not found" );
|
wxT( "Installed package version not found" ) );
|
||||||
|
|
||||||
auto ver_it = std::find_if( aPackage.versions.begin(), aPackage.versions.end(),
|
auto ver_it = std::find_if( aPackage.versions.begin(), aPackage.versions.end(),
|
||||||
[&]( const PACKAGE_VERSION& ver )
|
[&]( const PACKAGE_VERSION& ver )
|
||||||
{
|
{
|
||||||
return ver.compatible && installed_ver_it->status >= ver.status
|
return ver.compatible
|
||||||
|
&& installed_ver_it->status >= ver.status
|
||||||
&& installed_ver_it->parsed_version < ver.parsed_version;
|
&& installed_ver_it->parsed_version < ver.parsed_version;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -880,8 +887,7 @@ const wxString PLUGIN_CONTENT_MANAGER::GetPackageUpdateVersion( const PCM_PACKAG
|
||||||
time_t PLUGIN_CONTENT_MANAGER::getCurrentTimestamp() const
|
time_t PLUGIN_CONTENT_MANAGER::getCurrentTimestamp() const
|
||||||
{
|
{
|
||||||
return std::chrono::duration_cast<std::chrono::seconds>(
|
return std::chrono::duration_cast<std::chrono::seconds>(
|
||||||
std::chrono::system_clock::now().time_since_epoch() )
|
std::chrono::system_clock::now().time_since_epoch() ).count();
|
||||||
.count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -892,12 +898,12 @@ void PLUGIN_CONTENT_MANAGER::SaveInstalledPackages()
|
||||||
nlohmann::json js;
|
nlohmann::json js;
|
||||||
js["packages"] = nlohmann::json::array();
|
js["packages"] = nlohmann::json::array();
|
||||||
|
|
||||||
for( const auto& entry : m_installed )
|
for( std::pair<const wxString, PCM_INSTALLATION_ENTRY>& pair : m_installed )
|
||||||
{
|
{
|
||||||
js["packages"].emplace_back( entry.second );
|
js["packages"].emplace_back( pair.second );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileName f( SETTINGS_MANAGER::GetUserSettingsPath(), "installed_packages.json" );
|
wxFileName f( SETTINGS_MANAGER::GetUserSettingsPath(), wxT( "installed_packages.json" ) );
|
||||||
std::ofstream stream( f.GetFullPath().ToUTF8() );
|
std::ofstream stream( f.GetFullPath().ToUTF8() );
|
||||||
|
|
||||||
stream << std::setw( 4 ) << js << std::endl;
|
stream << std::setw( 4 ) << js << std::endl;
|
||||||
|
@ -914,7 +920,7 @@ const std::vector<PCM_INSTALLATION_ENTRY> PLUGIN_CONTENT_MANAGER::GetInstalledPa
|
||||||
std::vector<PCM_INSTALLATION_ENTRY> v;
|
std::vector<PCM_INSTALLATION_ENTRY> v;
|
||||||
|
|
||||||
std::for_each( m_installed.begin(), m_installed.end(),
|
std::for_each( m_installed.begin(), m_installed.end(),
|
||||||
[&v]( const auto& entry )
|
[&v]( const std::pair<const wxString, PCM_INSTALLATION_ENTRY>& entry )
|
||||||
{
|
{
|
||||||
v.push_back( entry.second );
|
v.push_back( entry.second );
|
||||||
} );
|
} );
|
||||||
|
@ -935,7 +941,7 @@ const wxString&
|
||||||
PLUGIN_CONTENT_MANAGER::GetInstalledPackageVersion( const wxString& aPackageId ) const
|
PLUGIN_CONTENT_MANAGER::GetInstalledPackageVersion( const wxString& aPackageId ) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_installed.find( aPackageId ) != m_installed.end(),
|
wxASSERT_MSG( m_installed.find( aPackageId ) != m_installed.end(),
|
||||||
"Installed package not found." );
|
wxT( "Installed package not found." ) );
|
||||||
|
|
||||||
return m_installed.at( aPackageId ).current_version;
|
return m_installed.at( aPackageId ).current_version;
|
||||||
}
|
}
|
||||||
|
@ -962,20 +968,23 @@ void PLUGIN_CONTENT_MANAGER::SetPinned( const wxString& aPackageId, const bool a
|
||||||
int PLUGIN_CONTENT_MANAGER::GetPackageSearchRank( const PCM_PACKAGE& aPackage,
|
int PLUGIN_CONTENT_MANAGER::GetPackageSearchRank( const PCM_PACKAGE& aPackage,
|
||||||
const wxString& aSearchTerm )
|
const wxString& aSearchTerm )
|
||||||
{
|
{
|
||||||
wxArrayString terms = wxStringTokenize( aSearchTerm.Lower(), " ", wxTOKEN_STRTOK );
|
wxArrayString terms = wxStringTokenize( aSearchTerm.Lower(), wxS( " " ), wxTOKEN_STRTOK );
|
||||||
int rank = 0;
|
int rank = 0;
|
||||||
|
|
||||||
const auto find_term_matches = [&]( const wxString& str )
|
const auto find_term_matches =
|
||||||
{
|
[&]( const wxString& str )
|
||||||
int result = 0;
|
{
|
||||||
wxString lower = str.Lower();
|
int result = 0;
|
||||||
|
wxString lower = str.Lower();
|
||||||
|
|
||||||
for( const wxString& term : terms )
|
for( const wxString& term : terms )
|
||||||
if( lower.Find( term ) != wxNOT_FOUND )
|
{
|
||||||
result += 1;
|
if( lower.Find( term ) != wxNOT_FOUND )
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Match on package id
|
// Match on package id
|
||||||
if( terms.size() == 1 && terms[0] == aPackage.identifier )
|
if( terms.size() == 1 && terms[0] == aPackage.identifier )
|
||||||
|
@ -1002,7 +1011,7 @@ int PLUGIN_CONTENT_MANAGER::GetPackageSearchRank( const PCM_PACKAGE& aPackage,
|
||||||
rank += 3 * find_term_matches( aPackage.maintainer->name );
|
rank += 3 * find_term_matches( aPackage.maintainer->name );
|
||||||
|
|
||||||
// Match on resources
|
// Match on resources
|
||||||
for( const auto& entry : aPackage.resources )
|
for( const std::pair<const std::string, wxString>& entry : aPackage.resources )
|
||||||
{
|
{
|
||||||
rank += find_term_matches( entry.first );
|
rank += find_term_matches( entry.first );
|
||||||
rank += find_term_matches( entry.second );
|
rank += find_term_matches( entry.second );
|
||||||
|
@ -1021,8 +1030,8 @@ PLUGIN_CONTENT_MANAGER::GetRepositoryPackageBitmaps( const wxString& aRepository
|
||||||
{
|
{
|
||||||
std::unordered_map<wxString, wxBitmap> bitmaps;
|
std::unordered_map<wxString, wxBitmap> bitmaps;
|
||||||
|
|
||||||
wxFileName resources_file = wxFileName( PATHS::GetUserCachePath(), "resources.zip" );
|
wxFileName resources_file = wxFileName( PATHS::GetUserCachePath(), wxT( "resources.zip" ) );
|
||||||
resources_file.AppendDir( "pcm" );
|
resources_file.AppendDir( wxT( "pcm" ) );
|
||||||
resources_file.AppendDir( aRepositoryId );
|
resources_file.AppendDir( aRepositoryId );
|
||||||
|
|
||||||
if( !resources_file.FileExists() )
|
if( !resources_file.FileExists() )
|
||||||
|
@ -1036,10 +1045,10 @@ PLUGIN_CONTENT_MANAGER::GetRepositoryPackageBitmaps( const wxString& aRepository
|
||||||
|
|
||||||
for( wxArchiveEntry* entry = zip.GetNextEntry(); entry; entry = zip.GetNextEntry() )
|
for( wxArchiveEntry* entry = zip.GetNextEntry(); entry; entry = zip.GetNextEntry() )
|
||||||
{
|
{
|
||||||
wxArrayString path_parts =
|
wxArrayString path_parts = wxSplit( entry->GetName(), wxFileName::GetPathSeparator(),
|
||||||
wxSplit( entry->GetName(), wxFileName::GetPathSeparator(), (wxChar) 0 );
|
(wxChar) 0 );
|
||||||
|
|
||||||
if( path_parts.size() != 2 || path_parts[1] != "icon.png" )
|
if( path_parts.size() != 2 || path_parts[1] != wxT( "icon.png" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -1051,7 +1060,7 @@ PLUGIN_CONTENT_MANAGER::GetRepositoryPackageBitmaps( const wxString& aRepository
|
||||||
catch( ... )
|
catch( ... )
|
||||||
{
|
{
|
||||||
// Log and ignore
|
// Log and ignore
|
||||||
wxLogTrace( "Error loading png bitmap for entry %s from %s", entry->GetName(),
|
wxLogTrace( wxT( "Error loading png bitmap for entry %s from %s" ), entry->GetName(),
|
||||||
resources_file.GetFullPath() );
|
resources_file.GetFullPath() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1064,19 +1073,19 @@ std::unordered_map<wxString, wxBitmap> PLUGIN_CONTENT_MANAGER::GetInstalledPacka
|
||||||
{
|
{
|
||||||
std::unordered_map<wxString, wxBitmap> bitmaps;
|
std::unordered_map<wxString, wxBitmap> bitmaps;
|
||||||
|
|
||||||
wxFileName resources_dir_fn( m_3rdparty_path, "" );
|
wxFileName resources_dir_fn( m_3rdparty_path, wxEmptyString );
|
||||||
resources_dir_fn.AppendDir( "resources" );
|
resources_dir_fn.AppendDir( wxT( "resources" ) );
|
||||||
wxDir resources_dir( resources_dir_fn.GetPath() );
|
wxDir resources_dir( resources_dir_fn.GetPath() );
|
||||||
|
|
||||||
if( !resources_dir.IsOpened() )
|
if( !resources_dir.IsOpened() )
|
||||||
return bitmaps;
|
return bitmaps;
|
||||||
|
|
||||||
wxString subdir;
|
wxString subdir;
|
||||||
bool more = resources_dir.GetFirst( &subdir, "", wxDIR_DIRS | wxDIR_HIDDEN );
|
bool more = resources_dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN );
|
||||||
|
|
||||||
while( more )
|
while( more )
|
||||||
{
|
{
|
||||||
wxFileName icon( resources_dir_fn.GetPath(), "icon.png" );
|
wxFileName icon( resources_dir_fn.GetPath(), wxT( "icon.png" ) );
|
||||||
icon.AppendDir( subdir );
|
icon.AppendDir( subdir );
|
||||||
|
|
||||||
if( icon.FileExists() )
|
if( icon.FileExists() )
|
||||||
|
@ -1092,7 +1101,7 @@ std::unordered_map<wxString, wxBitmap> PLUGIN_CONTENT_MANAGER::GetInstalledPacka
|
||||||
catch( ... )
|
catch( ... )
|
||||||
{
|
{
|
||||||
// Log and ignore
|
// Log and ignore
|
||||||
wxLogTrace( "Error loading png bitmap from %s", icon.GetFullPath() );
|
wxLogTrace( wxT( "Error loading png bitmap from %s" ), icon.GetFullPath() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1120,16 +1129,14 @@ void PLUGIN_CONTENT_MANAGER::RunBackgroundUpdate()
|
||||||
// Only fetch repositories that have installed not pinned packages
|
// Only fetch repositories that have installed not pinned packages
|
||||||
std::unordered_set<wxString> repo_ids;
|
std::unordered_set<wxString> repo_ids;
|
||||||
|
|
||||||
for( auto& entry : m_installed )
|
for( std::pair<const wxString, PCM_INSTALLATION_ENTRY>& pair : m_installed )
|
||||||
{
|
{
|
||||||
if( !entry.second.pinned )
|
if( !pair.second.pinned )
|
||||||
repo_ids.insert( entry.second.repository_id );
|
repo_ids.insert( pair.second.repository_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( const auto& entry : m_repository_list )
|
for( const auto& [ repository_id, name, url ] : m_repository_list )
|
||||||
{
|
{
|
||||||
const wxString& repository_id = std::get<0>( entry );
|
|
||||||
|
|
||||||
if( repo_ids.count( repository_id ) == 0 )
|
if( repo_ids.count( repository_id ) == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1145,18 +1152,16 @@ void PLUGIN_CONTENT_MANAGER::RunBackgroundUpdate()
|
||||||
// Count packages with updates
|
// Count packages with updates
|
||||||
int availableUpdateCount = 0;
|
int availableUpdateCount = 0;
|
||||||
|
|
||||||
for( auto& entry : m_installed )
|
for( std::pair<const wxString, PCM_INSTALLATION_ENTRY>& pair : m_installed )
|
||||||
{
|
{
|
||||||
PCM_INSTALLATION_ENTRY& installed_package = entry.second;
|
PCM_INSTALLATION_ENTRY& entry = pair.second;
|
||||||
|
|
||||||
if( m_repository_cache.find( installed_package.repository_id )
|
if( m_repository_cache.find( entry.repository_id ) != m_repository_cache.end() )
|
||||||
!= m_repository_cache.end() )
|
|
||||||
{
|
{
|
||||||
PCM_PACKAGE_STATE state =
|
PCM_PACKAGE_STATE state = GetPackageState( entry.repository_id,
|
||||||
GetPackageState( installed_package.repository_id,
|
entry.package.identifier );
|
||||||
installed_package.package.identifier );
|
|
||||||
|
|
||||||
if( state == PPS_UPDATE_AVAILABLE && !installed_package.pinned )
|
if( state == PPS_UPDATE_AVAILABLE && !entry.pinned )
|
||||||
availableUpdateCount++;
|
availableUpdateCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue