Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Attempt to fix Windows GPKG project storage
Fixes #33057 (hopefully)
  • Loading branch information
elpaso committed Dec 6, 2019
1 parent cfbe664 commit 3dcbde9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/core/providers/ogr/qgsgeopackageprojectstorage.cpp
Expand Up @@ -293,22 +293,29 @@ QgsGeoPackageProjectUri QgsGeoPackageProjectStorage::decodeUri( const QString &u
{
QUrl url = QUrl::fromEncoded( uri.toUtf8() );
QUrlQuery urlQuery( url.query() );
const QString urlAsString( url.toString( ) );

QgsGeoPackageProjectUri gpkgUri;

// Check for windows paths: github issue #33057
const QRegularExpression winLocalPath { R"(^[A-Za-z]:)" };
// Check for windows network shares: github issue #31310
const QString path { url.toString().startsWith( QStringLiteral( "//" ) ) ? url.toString() : url.path() };
gpkgUri.valid = url.isValid() && QFile::exists( path );
gpkgUri.database = path;
const QString path { ( winLocalPath.match( urlAsString ).hasMatch() ||
urlAsString.startsWith( QStringLiteral( "//" ) ) ) ?
urlAsString :
url.path() };

gpkgUri.valid = QFile::exists( path );
gpkgUri.database = path;
gpkgUri.projectName = urlQuery.queryItemValue( "projectName" );

return gpkgUri;
}

QString QgsGeoPackageProjectStorage::filePath( const QString &uri )
{
const QgsGeoPackageProjectUri gpkgUri { decodeUri( uri ) };
return gpkgUri.valid ? gpkgUri.database : QString();
return gpkgUri.valid ? gpkgUri.database : QString();
}


Expand Down
6 changes: 4 additions & 2 deletions src/gui/providers/ogr/qgsgeopackageprojectstoragedialog.cpp
Expand Up @@ -48,10 +48,12 @@ QgsGeoPackageProjectStorageDialog::QgsGeoPackageProjectStorageDialog( bool savin

connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
{
const QString fileName{QFileInfo( path ).fileName()};
const QString fileName{ QFileInfo( path ).fileName() };
if ( mCboConnection->findData( path ) == -1 )
{
mCboConnection->addItem( QFileInfo( path ).fileName(), path );
// the call to filePath standardizes the path and prevents
// an error when opening the file on windows
mCboConnection->addItem( fileName, QFileInfo( path ).filePath() );
mCboConnection->setItemData( mCboConnection->findText( fileName ), path, Qt::ItemDataRole::ToolTipRole );
}
mCboConnection->setCurrentIndex( mCboConnection->findText( fileName ) );
Expand Down

0 comments on commit 3dcbde9

Please sign in to comment.