Commit 44ca3530 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

throw better IO_ERROR message on bad GITHUB URL, improved formatting and comments.

parent 65b0343b
Loading
Loading
Loading
Loading
+11 −16
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ typedef MODULE_MAP::const_iterator MODULE_CITER;

/**
 * Class GH_CACHE
 * assists only within GITHUB_PLUGIN and hold a map of footprint name to wxZipEntry
 * assists only within GITHUB_PLUGIN and holds a map of footprint name to wxZipEntry
 */
struct GH_CACHE : public MODULE_MAP
{
@@ -100,7 +100,7 @@ const wxString& GITHUB_PLUGIN::GetFileExtension() const
wxArrayString GITHUB_PLUGIN::FootprintEnumerate(
        const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
    D(printf("%s: this:%p  aLibraryPath:'%s'\n", __func__, this, TO_UTF8(aLibraryPath) );)
    //D(printf("%s: this:%p  aLibraryPath:'%s'\n", __func__, this, TO_UTF8(aLibraryPath) );)

    cacheLib( aLibraryPath );

@@ -118,7 +118,7 @@ wxArrayString GITHUB_PLUGIN::FootprintEnumerate(
MODULE* GITHUB_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
        const wxString& aFootprintName, const PROPERTIES* aProperties )
{
    D(printf("%s: this:%p  aLibraryPath:'%s'\n", __func__, this, TO_UTF8(aLibraryPath) );)
    // D(printf("%s: this:%p  aLibraryPath:'%s'\n", __func__, this, TO_UTF8(aLibraryPath) );)

    cacheLib( aLibraryPath );

@@ -166,18 +166,13 @@ void GITHUB_PLUGIN::cacheLib( const wxString& aLibraryPath ) throw( IO_ERROR )
{
    if( !m_cache || m_lib_path != aLibraryPath )
    {
        D(printf("%s: this:%p  m_lib_path:'%s'  aLibraryPath:'%s'\n",
            __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );)
        //D(printf("%s: this:%p  m_lib_path:'%s'  aLibraryPath:'%s'\n", __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );)

        delete m_cache;
        m_cache = new GH_CACHE();
        remote_get_zip( aLibraryPath );

        m_lib_path = aLibraryPath;

        D(printf("%s2: this:%p  m_lib_path:'%s'  aLibraryPath:'%s'\n",
            __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );)

        wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() );

        // @todo: generalize this name encoding from a PROPERTY (option) later
@@ -232,7 +227,7 @@ void GITHUB_PLUGIN::remote_get_zip( const wxString& aRepoURL ) throw( IO_ERROR )

    if( !repoURL_zipURL( aRepoURL, &zip_url ) )
    {
        wxString msg = wxString::Format( _("Unable to parse URL: %s"), GetChars( m_lib_path ) );
        wxString msg = wxString::Format( _( "Unable to parse URL:\n'%s'" ), GetChars( aRepoURL ) );
        THROW_IO_ERROR( msg );
    }

@@ -246,8 +241,9 @@ void GITHUB_PLUGIN::remote_get_zip( const wxString& aRepoURL ) throw( IO_ERROR )

    try
    {
        h.open( zip_url );      // only one file, therefore do it synchronously.
        ostringstream os;

        h.open( zip_url );      // only one file, therefore do it synchronously.
        os << &h;

        // Keep zip file byte image in RAM.  That plus the MODULE_MAP will constitute
@@ -295,4 +291,3 @@ int main( int argc, char** argv )
}

#endif