Kaydet (Commit) f62d15a2 authored tarafından Michael Stahl's avatar Michael Stahl Kaydeden (comit) Andras Timar

desktop: stop --convert-to from creating some not requested ...

... file format by default if the requested filter does not exist.

Much better to write an error message and do nothing.

Change-Id: Ie5404772e7aae5751126bd4c2784b58177804448
(cherry picked from commit c994ce8a)
Reviewed-on: https://gerrit.libreoffice.org/20007Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
(cherry picked from commit de7a50d6)
üst e7da6dec
...@@ -128,7 +128,8 @@ const SfxFilter* impl_lookupExportFilterForUrl( const rtl::OUString& rUrl, const ...@@ -128,7 +128,8 @@ const SfxFilter* impl_lookupExportFilterForUrl( const rtl::OUString& rUrl, const
return pBestMatch; return pBestMatch;
} }
const SfxFilter* impl_getExportFilterFromUrl( const rtl::OUString& rUrl, const rtl::OUString& rFactory ) static const SfxFilter* impl_getExportFilterFromUrl(
const rtl::OUString& rUrl, const rtl::OUString& rFactory)
{ {
try try
{ {
...@@ -146,10 +147,8 @@ try ...@@ -146,10 +147,8 @@ try
OUString aTempName; OUString aTempName;
FileBase::getSystemPathFromFileURL( rUrl, aTempName ); FileBase::getSystemPathFromFileURL( rUrl, aTempName );
OString aSource = OUStringToOString ( aTempName, osl_getThreadTextEncoding() ); OString aSource = OUStringToOString ( aTempName, osl_getThreadTextEncoding() );
OString aFactory = OUStringToOString ( rFactory, osl_getThreadTextEncoding() ); std::cerr << "Error: no export filter for " << aSource << " found, aborting." << std::endl;
std::cerr << "Error: no export filter for " << aSource << " found, now using the default filter for " << aFactory << std::endl;
pFilter = SfxFilter::GetDefaultFilterFromFactory( rFactory );
} }
return pFilter; return pFilter;
...@@ -539,7 +538,13 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ ...@@ -539,7 +538,13 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
aFilter = impl_GuessFilter( aOutFile, aDocService ); aFilter = impl_GuessFilter( aOutFile, aDocService );
} }
sal_Int32 nFilterOptionsIndex = aFilter.indexOf( ':' ); if (aFilter.isEmpty())
{
std::cerr << "Error: no export filter" << std::endl;
}
else
{
sal_Int32 nFilterOptionsIndex = aFilter.indexOf(':');
Sequence<PropertyValue> conversionProperties( 0 < nFilterOptionsIndex ? 3 : 2 ); Sequence<PropertyValue> conversionProperties( 0 < nFilterOptionsIndex ? 3 : 2 );
conversionProperties[0].Name = "Overwrite"; conversionProperties[0].Name = "Overwrite";
conversionProperties[0].Value <<= sal_True; conversionProperties[0].Value <<= sal_True;
...@@ -547,10 +552,10 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ ...@@ -547,10 +552,10 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
conversionProperties[1].Name = "FilterName"; conversionProperties[1].Name = "FilterName";
if( 0 < nFilterOptionsIndex ) if( 0 < nFilterOptionsIndex )
{ {
conversionProperties[1].Value <<= aFilter.copy( 0, nFilterOptionsIndex ); conversionProperties[1].Value <<= aFilter.copy(0, nFilterOptionsIndex);
conversionProperties[2].Name = "FilterOptions"; conversionProperties[2].Name = "FilterOptions";
conversionProperties[2].Value <<= aFilter.copy( nFilterOptionsIndex+1 ); conversionProperties[2].Value <<= aFilter.copy(nFilterOptionsIndex + 1);
} }
else else
{ {
...@@ -558,20 +563,20 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ ...@@ -558,20 +563,20 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
} }
OUString aTempName; OUString aTempName;
FileBase::getSystemPathFromFileURL( aName, aTempName ); FileBase::getSystemPathFromFileURL(aName, aTempName);
OString aSource8 = OUStringToOString ( aTempName, osl_getThreadTextEncoding() ); OString aSource8 = OUStringToOString(aTempName, osl_getThreadTextEncoding());
FileBase::getSystemPathFromFileURL( aOutFile, aTempName ); FileBase::getSystemPathFromFileURL(aOutFile, aTempName);
OString aTargetURL8 = OUStringToOString(aTempName, osl_getThreadTextEncoding() ); OString aTargetURL8 = OUStringToOString(aTempName, osl_getThreadTextEncoding());
if( aDispatchRequest.aRequestType != REQUEST_CAT ) if (aDispatchRequest.aRequestType != REQUEST_CAT)
{ {
std::cout << "convert " << aSource8 << " -> " << aTargetURL8; std::cout << "convert " << aSource8 << " -> " << aTargetURL8;
std::cout << " using filter : " << OUStringToOString( aFilter, osl_getThreadTextEncoding() ) << std::endl; std::cout << " using filter : " << OUStringToOString(aFilter, osl_getThreadTextEncoding()) << std::endl;
if( FStatHelper::IsDocument( aOutFile ) ) if (FStatHelper::IsDocument(aOutFile))
std::cout << "Overwriting: " << OUStringToOString( aTempName, osl_getThreadTextEncoding() ) << std::endl ; std::cout << "Overwriting: " << OUStringToOString(aTempName, osl_getThreadTextEncoding()) << std::endl ;
} }
try try
{ {
xStorable->storeToURL( aOutFile, conversionProperties ); xStorable->storeToURL(aOutFile, conversionProperties);
} }
catch (const Exception& rException) catch (const Exception& rException)
{ {
...@@ -581,33 +586,34 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ ...@@ -581,33 +586,34 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
std::cerr << std::endl; std::cerr << std::endl;
} }
if( aDispatchRequest.aRequestType == REQUEST_CAT ) if (aDispatchRequest.aRequestType == REQUEST_CAT)
{ {
osl::File aFile( fileForCat ); osl::File aFile(fileForCat);
osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read ); osl::File::RC aRC = aFile.open(osl_File_OpenFlag_Read);
if( aRC != osl::File::E_None ) if (aRC != osl::File::E_None)
{ {
std::cerr << "Error: Cannot read from temp file" << std::endl; std::cerr << "Error: Cannot read from temp file" << std::endl;
} }
else else
{ {
sal_Bool eof; sal_Bool eof;
for( ;; ) for (;;)
{ {
aFile.isEndOfFile( &eof ); aFile.isEndOfFile( &eof );
if( eof ) if (eof)
break; break;
rtl::ByteSequence bseq; rtl::ByteSequence bseq;
aFile.readLine( bseq ); aFile.readLine(bseq);
unsigned const char * aStr = reinterpret_cast< unsigned char const * >( bseq.getConstArray() ); unsigned const char * aStr = reinterpret_cast<unsigned char const *>(bseq.getConstArray());
for( sal_Int32 i = 0; i < bseq.getLength(); i++ ) for (sal_Int32 i = 0; i < bseq.getLength(); ++i)
{ {
std::cout << aStr[i]; std::cout << aStr[i];
} }
std::cout << std::endl; std::cout << std::endl;
} }
aFile.close(); aFile.close();
osl::File::remove( fileForCat ); osl::File::remove(fileForCat);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment