Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access to ECW files with names in UTF-8 #70

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions gdal/frmts/ecw/ecwcreatecopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ CPLErr GDALECWCompressor::Initialize(
return CE_Failure;
}

m_OStream.Access( fpVSIL, TRUE, (BOOLEAN) bSeekable, pszFilename,
m_OStream.Access( fpVSIL, TRUE, (BOOLEAN) bSeekable, pszFilename,
0, -1 );
}

Expand Down Expand Up @@ -1069,9 +1069,25 @@ CPLErr GDALECWCompressor::Initialize(
if( oError.GetErrorNumber() == NCS_SUCCESS )
{
if( fpVSIL == NULL )
oError = Open( (char *) pszFilename, false, true );
{
#if ECWSDK_VERSION>=40
if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) )
{
wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 );

oError = Open( pwszFilename, false, true );
CPLFree( pwszFilename );
}
else
#endif//ECWSDK_VERSION>=40
{
oError = Open( (char *) pszFilename, false, true );
}
}
else
{
oError = CNCSJP2FileView::Open( &(m_OStream) );
}
}

if( oError.GetErrorNumber() == NCS_SUCCESS )
Expand Down
14 changes: 13 additions & 1 deletion gdal/frmts/ecw/ecwdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,19 @@ CNCSJP2FileView *ECWDataset::OpenFileView( const char *pszDatasetName,
//we always open in read only mode. This should be improved in the future.
try
{
oErr = poFileView->Open( (char *) pszDatasetName, bProgressive, false );
#if ECWSDK_VERSION>=40
if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) )
{
wchar_t *pwszDatasetName = CPLRecodeToWChar( pszDatasetName, CPL_ENC_UTF8, CPL_ENC_UCS2 );

oErr = poFileView->Open( pwszDatasetName, bProgressive, false );
CPLFree( pwszDatasetName );
}
else
#endif //#if ECWSDK_VERSION>=40
{
oErr = poFileView->Open( (char *) pszDatasetName, bProgressive, false );
}
}
catch(...)
{
Expand Down
17 changes: 15 additions & 2 deletions gdal/frmts/ecw/gdal_ecw.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,21 @@ class VSIIOStream : public CNCSJPCIOStream
}
CPLDebug( "ECW", "Using filename '%s' for temporary directory determination purposes.", osFilenameUsed.c_str() );
}
return(CNCSJPCIOStream::Open((char *)osFilenameUsed.c_str(),
(bool) bWrite));
#if ECWSDK_VERSION>=40
if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) )
{
wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 );
CNCSError oError;
oError = CNCSJPCIOStream::Open( pwszFilename, (bool) bWrite );
CPLFree( pwszFilename );
return oError;
}
else
#endif//ECWSDK_VERSION>=40
{
return(CNCSJPCIOStream::Open((char *)osFilenameUsed.c_str(),
(bool) bWrite));
}
}

virtual bool NCS_FASTCALL Seek() {
Expand Down