1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26 
27 #include <basic/basmgr.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <svx/svxerr.hxx>
30 #include <filter/msfilter/svxmsbas.hxx>
31 
32 using namespace com::sun::star;
33 
SaveOrDelMSVBAStorage(sal_Bool bSaveInto,const String & rStorageName)34 sal_uLong SvxImportMSVBasic::SaveOrDelMSVBAStorage( sal_Bool bSaveInto,
35                                                 const String& rStorageName )
36 {
37     sal_uLong nRet = ERRCODE_NONE;
38     uno::Reference < embed::XStorage > xSrcRoot( rDocSh.GetStorage() );
39     String aDstStgName( GetMSBasicStorageName() );
40     SotStorageRef xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, aDstStgName,
41                                 STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYALL ) );
42     if( xVBAStg.Is() && !xVBAStg->GetError() )
43     {
44         xVBAStg = 0;
45         if( bSaveInto )
46         {
47             BasicManager *pBasicMan = rDocSh.GetBasicManager();
48             if( pBasicMan && pBasicMan->IsBasicModified() )
49                 nRet = ERRCODE_SVX_MODIFIED_VBASIC_STORAGE;
50 
51             SotStorageRef xSrc = SotStorage::OpenOLEStorage( xSrcRoot, aDstStgName, STREAM_STD_READ );
52             SotStorageRef xDst = xRoot->OpenSotStorage( rStorageName, STREAM_READWRITE | STREAM_TRUNC );
53             xSrc->CopyTo( xDst );
54             xDst->Commit();
55             ErrCode nError = xDst->GetError();
56             if ( nError == ERRCODE_NONE )
57                 nError = xSrc->GetError();
58             if ( nError != ERRCODE_NONE )
59                 xRoot->SetError( nError );
60         }
61     }
62 
63     return nRet;
64 }
65 
66 // check if the MS-VBA-Storage exists in the RootStorage of the DocShell.
67 // If it exists, then return the WarningId for losing the information.
GetSaveWarningOfMSVBAStorage(SfxObjectShell & rDocSh)68 sal_uLong SvxImportMSVBasic::GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocSh)
69 {
70     uno::Reference < embed::XStorage > xSrcRoot( rDocSh.GetStorage() );
71     SvStorageRef xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, GetMSBasicStorageName(),
72                     STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYALL ));
73     return ( xVBAStg.Is() && !xVBAStg->GetError() )
74                     ? ERRCODE_SVX_VBASIC_STORAGE_EXIST
75                     : ERRCODE_NONE;
76 }
77 
GetMSBasicStorageName()78 String SvxImportMSVBasic::GetMSBasicStorageName()
79 {
80     return String( RTL_CONSTASCII_USTRINGPARAM( "_MS_VBA_Macros" ) );
81 }
82