diff options
author | Tuukka Orava <tuukka.orava@outlook.com> | 2024-04-09 09:28:27 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-04-09 10:51:14 +0200 |
commit | f3d0a184c4da57907a1fcf1ed784340be7d974d6 (patch) | |
tree | a567d9c93dd4427080308cfbff3f2247e3238ce5 /basic/source/runtime/methods.cxx | |
parent | 83f1a6f8172ab5688bb3e3883e33ed8295d3f5b7 (diff) |
tdf#147132 Flatten Basic function implementations
Change-Id: I077e042c82cbefd1d46db5ca8d5983a0870a296c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165903
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/source/runtime/methods.cxx')
-rw-r--r-- | basic/source/runtime/methods.cxx | 178 |
1 files changed, 81 insertions, 97 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index a97e66dc6c41..4dfcdc210ea3 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -429,18 +429,14 @@ void SbRtl_CurDir(StarBASIC *, SbxArray & rPar, bool) void SbRtl_ChDir(StarBASIC * pBasic, SbxArray & rPar, bool) { rPar.Get(0)->PutEmpty(); - if (rPar.Count() == 2) - { - // VBA: track current directory per document type (separately for Writer, Calc, Impress, etc.) - if( SbiRuntime::isVBAEnabled() ) - { - ::basic::vba::registerCurrentDirectory(getDocumentModel(pBasic), - rPar.Get(1)->GetOUString()); - } - } - else + if (rPar.Count() != 2) + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + // VBA: track current directory per document type (separately for Writer, Calc, Impress, etc.) + if( SbiRuntime::isVBAEnabled() ) { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + ::basic::vba::registerCurrentDirectory(getDocumentModel(pBasic), + rPar.Get(1)->GetOUString()); } } @@ -448,9 +444,7 @@ void SbRtl_ChDrive(StarBASIC *, SbxArray & rPar, bool) { rPar.Get(0)->PutEmpty(); if (rPar.Count() != 2) - { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - } + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); } @@ -499,129 +493,119 @@ void implStepRenameOSL( const OUString& aSource, const OUString& aDest ) void SbRtl_FileCopy(StarBASIC *, SbxArray & rPar, bool) { rPar.Get(0)->PutEmpty(); - if (rPar.Count() == 3) + if (rPar.Count() != 3) + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + OUString aSource = rPar.Get(1)->GetOUString(); + OUString aDest = rPar.Get(2)->GetOUString(); + if( hasUno() ) { - OUString aSource = rPar.Get(1)->GetOUString(); - OUString aDest = rPar.Get(2)->GetOUString(); - if( hasUno() ) + const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess(); + if( xSFI.is() ) { - const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess(); - if( xSFI.is() ) + try { - try - { - xSFI->copy( getFullPath( aSource ), getFullPath( aDest ) ); - } - catch(const Exception & ) - { - StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND ); - } + xSFI->copy( getFullPath( aSource ), getFullPath( aDest ) ); } - } - else - { - FileBase::RC nRet = File::copy( getFullPath( aSource ), getFullPath( aDest ) ); - if( nRet != FileBase::E_None ) + catch(const Exception & ) { StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND ); } } } else - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + { + FileBase::RC nRet = File::copy( getFullPath( aSource ), getFullPath( aDest ) ); + if( nRet != FileBase::E_None ) + { + StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND ); + } + } } void SbRtl_Kill(StarBASIC *, SbxArray & rPar, bool) { rPar.Get(0)->PutEmpty(); - if (rPar.Count() == 2) - { - OUString aFileSpec = rPar.Get(1)->GetOUString(); + if (rPar.Count() != 2) + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - if( hasUno() ) + OUString aFileSpec = rPar.Get(1)->GetOUString(); + + if( hasUno() ) + { + const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess(); + if( xSFI.is() ) { - const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess(); - if( xSFI.is() ) + OUString aFullPath = getFullPath( aFileSpec ); + if( !xSFI->exists( aFullPath ) || xSFI->isFolder( aFullPath ) ) { - OUString aFullPath = getFullPath( aFileSpec ); - if( !xSFI->exists( aFullPath ) || xSFI->isFolder( aFullPath ) ) - { - StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND ); - return; - } - try - { - xSFI->kill( aFullPath ); - } - catch(const Exception & ) - { - StarBASIC::Error( ERRCODE_IO_GENERAL ); - } + StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND ); + return; + } + try + { + xSFI->kill( aFullPath ); + } + catch(const Exception & ) + { + StarBASIC::Error( ERRCODE_IO_GENERAL ); } - } - else - { - File::remove( getFullPath( aFileSpec ) ); } } else { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + File::remove( getFullPath( aFileSpec ) ); } } void SbRtl_MkDir(StarBASIC * pBasic, SbxArray & rPar, bool bWrite) { rPar.Get(0)->PutEmpty(); - if (rPar.Count() == 2) + if (rPar.Count() != 2) + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + OUString aPath = rPar.Get(1)->GetOUString(); + if ( SbiRuntime::isVBAEnabled() ) { - OUString aPath = rPar.Get(1)->GetOUString(); - if ( SbiRuntime::isVBAEnabled() ) + // In vba if the full path is not specified then + // folder is created relative to the curdir + INetURLObject aURLObj( getFullPath( aPath ) ); + if ( aURLObj.GetProtocol() != INetProtocol::File ) { - // In vba if the full path is not specified then - // folder is created relative to the curdir - INetURLObject aURLObj( getFullPath( aPath ) ); - if ( aURLObj.GetProtocol() != INetProtocol::File ) - { - SbxArrayRef pPar = new SbxArray(); - SbxVariableRef pResult = new SbxVariable(); - SbxVariableRef pParam = new SbxVariable(); - pPar->Insert(pResult.get(), pPar->Count()); - pPar->Insert(pParam.get(), pPar->Count()); - SbRtl_CurDir( pBasic, *pPar, bWrite ); - - OUString sCurPathURL; - File::getFileURLFromSystemPath(pPar->Get(0)->GetOUString(), sCurPathURL); - - aURLObj.SetURL( sCurPathURL ); - aURLObj.Append( aPath ); - File::getSystemPathFromFileURL(aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ),aPath ) ; - } + SbxArrayRef pPar = new SbxArray(); + SbxVariableRef pResult = new SbxVariable(); + SbxVariableRef pParam = new SbxVariable(); + pPar->Insert(pResult.get(), pPar->Count()); + pPar->Insert(pParam.get(), pPar->Count()); + SbRtl_CurDir( pBasic, *pPar, bWrite ); + + OUString sCurPathURL; + File::getFileURLFromSystemPath(pPar->Get(0)->GetOUString(), sCurPathURL); + + aURLObj.SetURL( sCurPathURL ); + aURLObj.Append( aPath ); + File::getSystemPathFromFileURL(aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ),aPath ) ; } + } - if( hasUno() ) + if( hasUno() ) + { + const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess(); + if( xSFI.is() ) { - const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess(); - if( xSFI.is() ) + try { - try - { - xSFI->createFolder( getFullPath( aPath ) ); - } - catch(const Exception & ) - { - StarBASIC::Error( ERRCODE_IO_GENERAL ); - } + xSFI->createFolder( getFullPath( aPath ) ); + } + catch(const Exception & ) + { + StarBASIC::Error( ERRCODE_IO_GENERAL ); } - } - else - { - Directory::create( getFullPath( aPath ) ); } } else { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + Directory::create( getFullPath( aPath ) ); } } |