2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 11:02:36 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 11:02:36 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 11:02:36 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 11:02:36 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 11:02:36 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 11:02:36 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 09:05:02 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_basic.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <vcl/dialog.hxx>
|
|
|
|
#include <vcl/edit.hxx>
|
|
|
|
#include <vcl/button.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <osl/security.h>
|
2000-09-26 08:02:02 +00:00
|
|
|
#include <osl/file.hxx>
|
2000-10-13 08:22:40 +00:00
|
|
|
#include <tools/urlobj.hxx>
|
2010-10-16 03:18:35 -05:00
|
|
|
#include <osl/mutex.hxx>
|
2003-11-18 16:00:39 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "runtime.hxx"
|
|
|
|
|
|
|
|
#ifdef _USE_UNO
|
|
|
|
|
|
|
|
// <-- encoding
|
2006-01-16 11:57:32 +00:00
|
|
|
#include <sal/alloca.h>
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <rtl/byteseq.hxx>
|
|
|
|
#include <rtl/textenc.h>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#include <rtl/textenc.h>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
// encoding -->
|
2000-11-02 11:03:49 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
|
2001-07-11 15:09:45 +00:00
|
|
|
#include <com/sun/star/ucb/XContentProvider.hpp>
|
2001-07-24 11:14:38 +00:00
|
|
|
#include <com/sun/star/ucb/XContentProviderManager.hpp>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
|
|
#include <com/sun/star/io/XOutputStream.hpp>
|
|
|
|
#include <com/sun/star/io/XStream.hpp>
|
|
|
|
#include <com/sun/star/io/XSeekable.hpp>
|
|
|
|
#include <com/sun/star/bridge/XBridge.hpp>
|
|
|
|
#include <com/sun/star/bridge/XBridgeFactory.hpp>
|
|
|
|
|
2000-11-02 11:03:49 +00:00
|
|
|
using namespace comphelper;
|
2000-09-18 15:18:56 +00:00
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::ucb;
|
|
|
|
using namespace com::sun::star::io;
|
|
|
|
using namespace com::sun::star::bridge;
|
|
|
|
|
|
|
|
#endif /* _USE_UNO */
|
|
|
|
|
|
|
|
#include "iosys.hxx"
|
|
|
|
#include "sbintern.hxx"
|
|
|
|
|
|
|
|
// Der Input-Dialog:
|
|
|
|
|
|
|
|
class SbiInputDialog : public ModalDialog {
|
|
|
|
Edit aInput;
|
|
|
|
OKButton aOk;
|
|
|
|
CancelButton aCancel;
|
|
|
|
String aText;
|
|
|
|
DECL_LINK( Ok, Window * );
|
|
|
|
DECL_LINK( Cancel, Window * );
|
|
|
|
public:
|
|
|
|
SbiInputDialog( Window*, const String& );
|
|
|
|
const String& GetInput() { return aText; }
|
|
|
|
};
|
|
|
|
|
|
|
|
SbiInputDialog::SbiInputDialog( Window* pParent, const String& rPrompt )
|
2004-01-06 18:42:19 +00:00
|
|
|
:ModalDialog( pParent, WB_3DLOOK | WB_MOVEABLE | WB_CLOSEABLE ),
|
|
|
|
aInput( this, WB_3DLOOK | WB_LEFT | WB_BORDER ),
|
2000-09-18 15:18:56 +00:00
|
|
|
aOk( this ), aCancel( this )
|
|
|
|
{
|
|
|
|
SetText( rPrompt );
|
|
|
|
aOk.SetClickHdl( LINK( this, SbiInputDialog, Ok ) );
|
|
|
|
aCancel.SetClickHdl( LINK( this, SbiInputDialog, Cancel ) );
|
|
|
|
SetMapMode( MapMode( MAP_APPFONT ) );
|
|
|
|
|
|
|
|
Point aPt = LogicToPixel( Point( 50, 50 ) );
|
|
|
|
Size aSz = LogicToPixel( Size( 145, 65 ) );
|
|
|
|
SetPosSizePixel( aPt, aSz );
|
|
|
|
aPt = LogicToPixel( Point( 10, 10 ) );
|
|
|
|
aSz = LogicToPixel( Size( 120, 12 ) );
|
|
|
|
aInput.SetPosSizePixel( aPt, aSz );
|
|
|
|
aPt = LogicToPixel( Point( 15, 30 ) );
|
|
|
|
aSz = LogicToPixel( Size( 45, 15) );
|
|
|
|
aOk.SetPosSizePixel( aPt, aSz );
|
|
|
|
aPt = LogicToPixel( Point( 80, 30 ) );
|
|
|
|
aSz = LogicToPixel( Size( 45, 15) );
|
|
|
|
aCancel.SetPosSizePixel( aPt, aSz );
|
|
|
|
|
|
|
|
aInput.Show();
|
|
|
|
aOk.Show();
|
|
|
|
aCancel.Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK_INLINE_START( SbiInputDialog, Ok, Window *, pWindow )
|
|
|
|
{
|
2006-06-19 16:45:30 +00:00
|
|
|
(void)pWindow;
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
aText = aInput.GetText();
|
|
|
|
EndDialog( 1 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
IMPL_LINK_INLINE_END( SbiInputDialog, Ok, Window *, pWindow )
|
|
|
|
|
|
|
|
IMPL_LINK_INLINE_START( SbiInputDialog, Cancel, Window *, pWindow )
|
|
|
|
{
|
2006-06-19 16:45:30 +00:00
|
|
|
(void)pWindow;
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
EndDialog( 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
IMPL_LINK_INLINE_END( SbiInputDialog, Cancel, Window *, pWindow )
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SbiStream::SbiStream()
|
|
|
|
: pStrm( 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiStream::~SbiStream()
|
|
|
|
{
|
|
|
|
delete pStrm;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ummappen eines SvStream-Fehlers auf einen StarBASIC-Code
|
|
|
|
|
|
|
|
void SbiStream::MapError()
|
|
|
|
{
|
|
|
|
if( pStrm )
|
|
|
|
switch( pStrm->GetError() )
|
|
|
|
{
|
|
|
|
case SVSTREAM_OK:
|
|
|
|
nError = 0; break;
|
|
|
|
case SVSTREAM_FILE_NOT_FOUND:
|
|
|
|
nError = SbERR_FILE_NOT_FOUND; break;
|
|
|
|
case SVSTREAM_PATH_NOT_FOUND:
|
|
|
|
nError = SbERR_PATH_NOT_FOUND; break;
|
|
|
|
case SVSTREAM_TOO_MANY_OPEN_FILES:
|
|
|
|
nError = SbERR_TOO_MANY_FILES; break;
|
|
|
|
case SVSTREAM_ACCESS_DENIED:
|
|
|
|
nError = SbERR_ACCESS_DENIED; break;
|
|
|
|
case SVSTREAM_INVALID_PARAMETER:
|
|
|
|
nError = SbERR_BAD_ARGUMENT; break;
|
|
|
|
case SVSTREAM_OUTOFMEMORY:
|
|
|
|
nError = SbERR_NO_MEMORY; break;
|
|
|
|
default:
|
|
|
|
nError = SbERR_IO_ERROR; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _USE_UNO
|
|
|
|
|
|
|
|
// TODO: Code is copied from daemons2/source/uno/asciiEncoder.cxx
|
|
|
|
|
2008-06-24 15:03:52 +00:00
|
|
|
::rtl::OUString findUserInDescription( const ::rtl::OUString& aDescription )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2008-06-24 15:03:52 +00:00
|
|
|
::rtl::OUString user;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
sal_Int32 index;
|
|
|
|
sal_Int32 lastIndex = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
index = aDescription.indexOf((sal_Unicode) ',', lastIndex);
|
2008-06-24 15:03:52 +00:00
|
|
|
::rtl::OUString token = (index == -1) ? aDescription.copy(lastIndex) : aDescription.copy(lastIndex, index - lastIndex);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
lastIndex = index + 1;
|
|
|
|
|
|
|
|
sal_Int32 eindex = token.indexOf((sal_Unicode)'=');
|
2008-06-24 15:03:52 +00:00
|
|
|
::rtl::OUString left = token.copy(0, eindex).toAsciiLowerCase().trim();
|
|
|
|
::rtl::OUString right = INetURLObject::decode( token.copy(eindex + 1).trim(), '%',
|
2000-10-13 08:22:40 +00:00
|
|
|
INetURLObject::DECODE_WITH_CHARSET );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-06-24 15:03:52 +00:00
|
|
|
if(left.equals(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user"))))
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
user = right;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(index != -1);
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-05-23 07:47:19 +00:00
|
|
|
// Hack for #83750
|
|
|
|
BOOL runsInSetup( void );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
BOOL needSecurityRestrictions( void )
|
|
|
|
{
|
|
|
|
#ifdef _USE_UNO
|
|
|
|
static BOOL bNeedInit = TRUE;
|
|
|
|
static BOOL bRetVal = TRUE;
|
|
|
|
|
|
|
|
if( bNeedInit )
|
|
|
|
{
|
2001-05-23 07:47:19 +00:00
|
|
|
// Hack for #83750, use internal flag until
|
|
|
|
// setup provides own service manager
|
|
|
|
if( runsInSetup() )
|
|
|
|
{
|
|
|
|
// Setup is not critical
|
|
|
|
bRetVal = FALSE;
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
bNeedInit = FALSE;
|
|
|
|
|
|
|
|
// Get system user to compare to portal user
|
|
|
|
oslSecurity aSecurity = osl_getCurrentSecurity();
|
2008-06-24 15:03:52 +00:00
|
|
|
::rtl::OUString aSystemUser;
|
2000-09-18 15:18:56 +00:00
|
|
|
sal_Bool bRet = osl_getUserName( aSecurity, &aSystemUser.pData );
|
|
|
|
if( !bRet )
|
|
|
|
{
|
|
|
|
// No valid security! -> Secure mode!
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
|
|
|
|
if( !xSMgr.is() )
|
|
|
|
return TRUE;
|
|
|
|
Reference< XBridgeFactory > xBridgeFac( xSMgr->createInstance
|
2010-11-05 08:20:56 +01:00
|
|
|
( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.bridge.BridgeFactory" )) ), UNO_QUERY );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
Sequence< Reference< XBridge > > aBridgeSeq;
|
|
|
|
sal_Int32 nBridgeCount = 0;
|
|
|
|
if( xBridgeFac.is() )
|
|
|
|
{
|
|
|
|
aBridgeSeq = xBridgeFac->getExistingBridges();
|
|
|
|
nBridgeCount = aBridgeSeq.getLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nBridgeCount == 0 )
|
|
|
|
{
|
|
|
|
// No bridges -> local
|
|
|
|
bRetVal = FALSE;
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through all bridges to find (portal) user property
|
|
|
|
const Reference< XBridge >* pBridges = aBridgeSeq.getConstArray();
|
|
|
|
bRetVal = FALSE; // Now only TRUE if user different from portal user is found
|
|
|
|
sal_Int32 i;
|
|
|
|
for( i = 0 ; i < nBridgeCount ; i++ )
|
|
|
|
{
|
|
|
|
const Reference< XBridge >& rxBridge = pBridges[ i ];
|
2008-06-24 15:03:52 +00:00
|
|
|
::rtl::OUString aDescription = rxBridge->getDescription();
|
|
|
|
::rtl::OUString aPortalUser = findUserInDescription( aDescription );
|
2000-09-18 15:18:56 +00:00
|
|
|
if( aPortalUser.getLength() > 0 )
|
|
|
|
{
|
|
|
|
// User Found, compare to system user
|
|
|
|
if( aPortalUser == aSystemUser )
|
|
|
|
{
|
|
|
|
// Same user -> system security is ok, bRetVal stays FALSE
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Different user -> Secure mode!
|
|
|
|
bRetVal = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// No user found or PortalUser != SystemUser -> Secure mode! (Keep default value)
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRetVal;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-07-11 15:09:45 +00:00
|
|
|
// Returns TRUE if UNO is available, otherwise the old file
|
|
|
|
// system implementation has to be used
|
|
|
|
// #89378 New semantic: Don't just ask for UNO but for UCB
|
2000-09-18 15:18:56 +00:00
|
|
|
BOOL hasUno( void )
|
|
|
|
{
|
|
|
|
#ifdef _USE_UNO
|
|
|
|
static BOOL bNeedInit = TRUE;
|
|
|
|
static BOOL bRetVal = TRUE;
|
|
|
|
|
|
|
|
if( bNeedInit )
|
|
|
|
{
|
|
|
|
bNeedInit = FALSE;
|
|
|
|
Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
|
|
|
|
if( !xSMgr.is() )
|
2001-07-11 15:09:45 +00:00
|
|
|
{
|
|
|
|
// No service manager at all
|
2000-09-18 15:18:56 +00:00
|
|
|
bRetVal = FALSE;
|
2001-07-11 15:09:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-05 08:20:56 +01:00
|
|
|
Reference< XContentProviderManager > xManager( xSMgr->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
|
|
|
|
( "com.sun.star.ucb.UniversalContentBroker" )) ), UNO_QUERY );
|
2001-07-24 11:14:38 +00:00
|
|
|
|
2010-11-05 08:20:56 +01:00
|
|
|
if ( !( xManager.is() && xManager->queryContentProvider( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "file:///" )) ).is() ) )
|
2001-07-11 15:09:45 +00:00
|
|
|
{
|
|
|
|
// No UCB
|
|
|
|
bRetVal = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return bRetVal;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-26 08:02:02 +00:00
|
|
|
|
|
|
|
#ifndef _OLD_FILE_IMPL
|
|
|
|
|
|
|
|
class OslStream : public SvStream
|
|
|
|
{
|
2010-10-16 03:18:35 -05:00
|
|
|
osl::File maFile;
|
2000-09-26 08:02:02 +00:00
|
|
|
short mnStrmMode;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OslStream( const String& rName, short nStrmMode );
|
|
|
|
~OslStream();
|
|
|
|
virtual ULONG GetData( void* pData, ULONG nSize );
|
|
|
|
virtual ULONG PutData( const void* pData, ULONG nSize );
|
|
|
|
virtual ULONG SeekPos( ULONG nPos );
|
|
|
|
virtual void FlushData();
|
|
|
|
virtual void SetSize( ULONG nSize );
|
|
|
|
};
|
|
|
|
|
|
|
|
OslStream::OslStream( const String& rName, short nStrmMode )
|
|
|
|
: maFile( rName )
|
|
|
|
, mnStrmMode( nStrmMode )
|
|
|
|
{
|
|
|
|
sal_uInt32 nFlags;
|
|
|
|
|
|
|
|
if( (nStrmMode & (STREAM_READ | STREAM_WRITE)) == (STREAM_READ | STREAM_WRITE) )
|
|
|
|
{
|
|
|
|
nFlags = OpenFlag_Read | OpenFlag_Write;
|
|
|
|
}
|
|
|
|
else if( nStrmMode & STREAM_WRITE )
|
|
|
|
{
|
|
|
|
nFlags = OpenFlag_Write;
|
|
|
|
}
|
|
|
|
else //if( nStrmMode & STREAM_READ )
|
|
|
|
{
|
|
|
|
nFlags = OpenFlag_Read;
|
|
|
|
}
|
|
|
|
|
2010-10-16 03:18:35 -05:00
|
|
|
osl::FileBase::RC nRet = maFile.open( nFlags );
|
|
|
|
if( nRet == osl::FileBase::E_NOENT && nFlags != OpenFlag_Read )
|
2000-09-26 08:02:02 +00:00
|
|
|
{
|
|
|
|
nFlags |= OpenFlag_Create;
|
|
|
|
nRet = maFile.open( nFlags );
|
|
|
|
}
|
|
|
|
|
2010-10-16 03:18:35 -05:00
|
|
|
if( nRet != osl::FileBase::E_None )
|
2000-09-26 08:02:02 +00:00
|
|
|
{
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OslStream::~OslStream()
|
|
|
|
{
|
2006-06-19 16:45:30 +00:00
|
|
|
maFile.close();
|
2000-09-26 08:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ULONG OslStream::GetData( void* pData, ULONG nSize )
|
|
|
|
{
|
|
|
|
sal_uInt64 nBytesRead = nSize;
|
2010-10-16 03:18:35 -05:00
|
|
|
osl::FileBase::RC nRet = osl::FileBase::E_None;
|
2006-06-19 16:45:30 +00:00
|
|
|
nRet = maFile.read( pData, nBytesRead, nBytesRead );
|
2000-09-26 08:02:02 +00:00
|
|
|
return (ULONG)nBytesRead;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG OslStream::PutData( const void* pData, ULONG nSize )
|
|
|
|
{
|
|
|
|
sal_uInt64 nBytesWritten;
|
2010-10-16 03:18:35 -05:00
|
|
|
osl::FileBase::RC nRet = osl::FileBase::E_None;
|
2006-06-19 16:45:30 +00:00
|
|
|
nRet = maFile.write( pData, (sal_uInt64)nSize, nBytesWritten );
|
2000-09-26 08:02:02 +00:00
|
|
|
return (ULONG)nBytesWritten;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG OslStream::SeekPos( ULONG nPos )
|
|
|
|
{
|
2010-10-16 03:18:35 -05:00
|
|
|
osl::FileBase::RC nRet;
|
2000-09-26 08:02:02 +00:00
|
|
|
if( nPos == STREAM_SEEK_TO_END )
|
|
|
|
{
|
|
|
|
nRet = maFile.setPos( Pos_End, 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nRet = maFile.setPos( Pos_Absolut, (sal_uInt64)nPos );
|
|
|
|
}
|
|
|
|
sal_uInt64 nRealPos;
|
|
|
|
nRet = maFile.getPos( nRealPos );
|
2006-06-19 16:45:30 +00:00
|
|
|
return sal::static_int_cast<ULONG>(nRealPos);
|
2000-09-26 08:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OslStream::FlushData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OslStream::SetSize( ULONG nSize )
|
|
|
|
{
|
2010-10-16 03:18:35 -05:00
|
|
|
osl::FileBase::RC nRet = osl::FileBase::E_None;
|
2006-06-19 16:45:30 +00:00
|
|
|
nRet = maFile.setSize( (sal_uInt64)nSize );
|
2000-09-26 08:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
#ifdef _USE_UNO
|
|
|
|
|
|
|
|
class UCBStream : public SvStream
|
|
|
|
{
|
|
|
|
Reference< XInputStream > xIS;
|
|
|
|
Reference< XOutputStream > xOS;
|
|
|
|
Reference< XStream > xS;
|
|
|
|
Reference< XSeekable > xSeek;
|
|
|
|
public:
|
|
|
|
UCBStream( Reference< XInputStream > & xIS );
|
|
|
|
UCBStream( Reference< XOutputStream > & xOS );
|
|
|
|
UCBStream( Reference< XStream > & xS );
|
|
|
|
~UCBStream();
|
|
|
|
virtual ULONG GetData( void* pData, ULONG nSize );
|
|
|
|
virtual ULONG PutData( const void* pData, ULONG nSize );
|
|
|
|
virtual ULONG SeekPos( ULONG nPos );
|
|
|
|
virtual void FlushData();
|
|
|
|
virtual void SetSize( ULONG nSize );
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
ULONG UCBErrorToSvStramError( ucb::IOErrorCode nError )
|
|
|
|
{
|
|
|
|
ULONG eReturn = ERRCODE_IO_GENERAL;
|
|
|
|
switch( nError )
|
|
|
|
{
|
|
|
|
case ucb::IOErrorCode_ABORT: eReturn = SVSTREAM_GENERALERROR; break;
|
|
|
|
case ucb::IOErrorCode_NOT_EXISTING: eReturn = SVSTREAM_FILE_NOT_FOUND; break;
|
|
|
|
case ucb::IOErrorCode_NOT_EXISTING_PATH: eReturn = SVSTREAM_PATH_NOT_FOUND; break;
|
|
|
|
case ucb::IOErrorCode_OUT_OF_FILE_HANDLES: eReturn = SVSTREAM_TOO_MANY_OPEN_FILES; break;
|
|
|
|
case ucb::IOErrorCode_ACCESS_DENIED: eReturn = SVSTREAM_ACCESS_DENIED; break;
|
|
|
|
case ucb::IOErrorCode_LOCKING_VIOLATION: eReturn = SVSTREAM_SHARING_VIOLATION; break;
|
|
|
|
|
|
|
|
case ucb::IOErrorCode_INVALID_ACCESS: eReturn = SVSTREAM_INVALID_ACCESS; break;
|
|
|
|
case ucb::IOErrorCode_CANT_CREATE: eReturn = SVSTREAM_CANNOT_MAKE; break;
|
|
|
|
case ucb::IOErrorCode_INVALID_PARAMETER: eReturn = SVSTREAM_INVALID_PARAMETER; break;
|
|
|
|
|
|
|
|
case ucb::IOErrorCode_CANT_READ: eReturn = SVSTREAM_READ_ERROR; break;
|
|
|
|
case ucb::IOErrorCode_CANT_WRITE: eReturn = SVSTREAM_WRITE_ERROR; break;
|
|
|
|
case ucb::IOErrorCode_CANT_SEEK: eReturn = SVSTREAM_SEEK_ERROR; break;
|
|
|
|
case ucb::IOErrorCode_CANT_TELL: eReturn = SVSTREAM_TELL_ERROR; break;
|
|
|
|
|
|
|
|
case ucb::IOErrorCode_OUT_OF_MEMORY: eReturn = SVSTREAM_OUTOFMEMORY; break;
|
|
|
|
|
|
|
|
case SVSTREAM_FILEFORMAT_ERROR: eReturn = SVSTREAM_FILEFORMAT_ERROR; break;
|
|
|
|
case ucb::IOErrorCode_WRONG_VERSION: eReturn = SVSTREAM_WRONGVERSION;
|
|
|
|
case ucb::IOErrorCode_OUT_OF_DISK_SPACE: eReturn = SVSTREAM_DISK_FULL; break;
|
|
|
|
|
|
|
|
case ucb::IOErrorCode_BAD_CRC: eReturn = ERRCODE_IO_BADCRC; break;
|
|
|
|
}
|
|
|
|
return eReturn;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
UCBStream::UCBStream( Reference< XInputStream > & rStm )
|
|
|
|
: xIS( rStm )
|
|
|
|
, xSeek( rStm, UNO_QUERY )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UCBStream::UCBStream( Reference< XOutputStream > & rStm )
|
|
|
|
: xOS( rStm )
|
|
|
|
, xSeek( rStm, UNO_QUERY )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UCBStream::UCBStream( Reference< XStream > & rStm )
|
|
|
|
: xS( rStm )
|
|
|
|
, xSeek( rStm, UNO_QUERY )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UCBStream::~UCBStream()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( xIS.is() )
|
|
|
|
xIS->closeInput();
|
|
|
|
else if( xOS.is() )
|
|
|
|
xOS->closeOutput();
|
|
|
|
else if( xS.is() )
|
2000-10-19 07:36:50 +00:00
|
|
|
{
|
2006-06-19 16:45:30 +00:00
|
|
|
Reference< XInputStream > xIS_ = xS->getInputStream();
|
|
|
|
if( xIS_.is() )
|
|
|
|
xIS_->closeInput();
|
2000-10-19 07:36:50 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG UCBStream::GetData( void* pData, ULONG nSize )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2000-10-19 07:36:50 +00:00
|
|
|
Reference< XInputStream > xISFromS;
|
2000-09-18 15:18:56 +00:00
|
|
|
if( xIS.is() )
|
|
|
|
{
|
|
|
|
Sequence<sal_Int8> aData;
|
|
|
|
nSize = xIS->readBytes( aData, nSize );
|
|
|
|
rtl_copyMemory( pData, aData.getConstArray(), nSize );
|
|
|
|
return nSize;
|
|
|
|
}
|
2000-10-19 07:36:50 +00:00
|
|
|
else if( xS.is() && (xISFromS = xS->getInputStream()).is() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
Sequence<sal_Int8> aData;
|
2000-10-19 07:36:50 +00:00
|
|
|
nSize = xISFromS->readBytes( aData, nSize );
|
2000-09-18 15:18:56 +00:00
|
|
|
rtl_copyMemory( pData, aData.getConstArray(), nSize );
|
|
|
|
return nSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG UCBStream::PutData( const void* pData, ULONG nSize )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2000-10-19 07:36:50 +00:00
|
|
|
Reference< XOutputStream > xOSFromS;
|
2000-09-18 15:18:56 +00:00
|
|
|
if( xOS.is() )
|
|
|
|
{
|
|
|
|
Sequence<sal_Int8> aData( (const sal_Int8 *)pData, nSize );
|
|
|
|
xOS->writeBytes( aData );
|
|
|
|
return nSize;
|
|
|
|
}
|
2000-10-19 07:36:50 +00:00
|
|
|
else if( xS.is() && (xOSFromS = xS->getOutputStream()).is() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
Sequence<sal_Int8> aData( (const sal_Int8 *)pData, nSize );
|
2000-10-19 07:36:50 +00:00
|
|
|
xOSFromS->writeBytes( aData );
|
2000-09-18 15:18:56 +00:00
|
|
|
return nSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG UCBStream::SeekPos( ULONG nPos )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( xSeek.is() )
|
|
|
|
{
|
2006-06-19 16:45:30 +00:00
|
|
|
ULONG nLen = sal::static_int_cast<ULONG>( xSeek->getLength() );
|
2000-09-18 15:18:56 +00:00
|
|
|
if( nPos > nLen )
|
|
|
|
nPos = nLen;
|
|
|
|
xSeek->seek( nPos );
|
|
|
|
return nPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UCBStream::FlushData()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2000-10-19 07:36:50 +00:00
|
|
|
Reference< XOutputStream > xOSFromS;
|
2000-09-18 15:18:56 +00:00
|
|
|
if( xOS.is() )
|
|
|
|
xOS->flush();
|
2000-10-19 07:36:50 +00:00
|
|
|
else if( xS.is() && (xOSFromS = xS->getOutputStream()).is() )
|
|
|
|
xOSFromS->flush();
|
2000-09-18 15:18:56 +00:00
|
|
|
else
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UCBStream::SetSize( ULONG nSize )
|
|
|
|
{
|
2006-06-19 16:45:30 +00:00
|
|
|
(void)nSize;
|
|
|
|
|
2008-11-10 15:06:12 +00:00
|
|
|
DBG_ERROR( "not allowed to call from basic" );
|
2000-09-18 15:18:56 +00:00
|
|
|
SetError( ERRCODE_IO_GENERAL );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Oeffnen eines Streams
|
|
|
|
SbError SbiStream::Open
|
|
|
|
( short nCh, const ByteString& rName, short nStrmMode, short nFlags, short nL )
|
|
|
|
{
|
|
|
|
nMode = nFlags;
|
|
|
|
nLen = nL;
|
|
|
|
nChan = nCh;
|
|
|
|
nLine = 0;
|
|
|
|
nExpandOnWriteTo = 0;
|
|
|
|
if( ( nStrmMode & ( STREAM_READ|STREAM_WRITE ) ) == STREAM_READ )
|
|
|
|
nStrmMode |= STREAM_NOCREATE;
|
2000-10-13 08:22:40 +00:00
|
|
|
String aStr( rName, gsl_getSystemTextEncoding() );
|
|
|
|
String aNameStr = getFullPath( aStr );
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
#ifdef _USE_UNO
|
|
|
|
if( hasUno() )
|
|
|
|
{
|
|
|
|
Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
|
|
|
|
if( xSMgr.is() )
|
|
|
|
{
|
|
|
|
Reference< XSimpleFileAccess >
|
2010-11-05 08:20:56 +01:00
|
|
|
xSFI( xSMgr->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" )) ), UNO_QUERY );
|
2000-09-18 15:18:56 +00:00
|
|
|
if( xSFI.is() )
|
|
|
|
{
|
|
|
|
try
|
2000-10-13 08:22:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// #??? For write access delete file if it already exists (not for appending)
|
2004-11-15 15:36:40 +00:00
|
|
|
if( (nStrmMode & STREAM_WRITE) != 0 && !IsAppend() && !IsBinary() &&
|
2001-08-30 13:20:36 +00:00
|
|
|
xSFI->exists( aNameStr ) && !xSFI->isFolder( aNameStr ) )
|
2000-10-13 08:22:40 +00:00
|
|
|
{
|
|
|
|
xSFI->kill( aNameStr );
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
if( (nStrmMode & (STREAM_READ | STREAM_WRITE)) == (STREAM_READ | STREAM_WRITE) )
|
|
|
|
{
|
|
|
|
Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr );
|
|
|
|
pStrm = new UCBStream( xIS );
|
|
|
|
}
|
|
|
|
else if( nStrmMode & STREAM_WRITE )
|
|
|
|
{
|
|
|
|
Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr );
|
|
|
|
pStrm = new UCBStream( xIS );
|
|
|
|
// Open for writing is not implemented in ucb yet!!!
|
|
|
|
//Reference< XOutputStream > xIS = xSFI->openFileWrite( aNameStr );
|
|
|
|
//pStrm = new UCBStream( xIS );
|
|
|
|
}
|
|
|
|
else //if( nStrmMode & STREAM_READ )
|
|
|
|
{
|
|
|
|
Reference< XInputStream > xIS = xSFI->openFileRead( aNameStr );
|
|
|
|
pStrm = new UCBStream( xIS );
|
|
|
|
}
|
2000-10-13 08:22:40 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
2001-08-30 13:20:36 +00:00
|
|
|
nError = ERRCODE_IO_GENERAL;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
if( !pStrm )
|
2000-09-26 08:02:02 +00:00
|
|
|
{
|
|
|
|
#ifdef _OLD_FILE_IMPL
|
2000-09-18 15:18:56 +00:00
|
|
|
pStrm = new SvFileStream( aNameStr, nStrmMode );
|
2000-09-26 08:02:02 +00:00
|
|
|
#else
|
2001-05-30 09:44:49 +00:00
|
|
|
pStrm = new OslStream( aNameStr, nStrmMode );
|
2000-09-26 08:02:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
if( IsAppend() )
|
|
|
|
pStrm->Seek( STREAM_SEEK_TO_END );
|
|
|
|
MapError();
|
|
|
|
if( nError )
|
|
|
|
delete pStrm, pStrm = NULL;
|
|
|
|
return nError;
|
|
|
|
}
|
|
|
|
|
|
|
|
SbError SbiStream::Close()
|
|
|
|
{
|
|
|
|
if( pStrm )
|
|
|
|
{
|
|
|
|
if( !hasUno() )
|
2000-09-26 08:02:02 +00:00
|
|
|
{
|
|
|
|
#ifdef _OLD_FILE_IMPL
|
2000-09-18 15:18:56 +00:00
|
|
|
((SvFileStream *)pStrm)->Close();
|
2000-09-26 08:02:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
MapError();
|
|
|
|
delete pStrm;
|
|
|
|
pStrm = NULL;
|
|
|
|
}
|
|
|
|
nChan = 0;
|
|
|
|
return nError;
|
|
|
|
}
|
|
|
|
|
2005-01-13 17:48:03 +00:00
|
|
|
SbError SbiStream::Read( ByteString& rBuf, USHORT n, bool bForceReadingPerByte )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
nExpandOnWriteTo = 0;
|
2005-01-13 17:48:03 +00:00
|
|
|
if( !bForceReadingPerByte && IsText() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
pStrm->ReadLine( rBuf );
|
|
|
|
nLine++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !n ) n = nLen;
|
|
|
|
if( !n )
|
|
|
|
return nError = SbERR_BAD_RECORD_LENGTH;
|
|
|
|
rBuf.Fill( n, ' ' );
|
|
|
|
pStrm->Read( (void*)rBuf.GetBuffer(), n );
|
|
|
|
}
|
|
|
|
MapError();
|
|
|
|
if( !nError && pStrm->IsEof() )
|
|
|
|
nError = SbERR_READ_PAST_EOF;
|
|
|
|
return nError;
|
|
|
|
}
|
|
|
|
|
|
|
|
SbError SbiStream::Read( char& ch )
|
|
|
|
{
|
|
|
|
nExpandOnWriteTo = 0;
|
|
|
|
if( !aLine.Len() )
|
|
|
|
{
|
|
|
|
Read( aLine, 0 );
|
|
|
|
aLine += '\n';
|
|
|
|
}
|
|
|
|
ch = aLine.GetBuffer()[0];
|
|
|
|
aLine.Erase( 0, 1 );
|
|
|
|
return nError;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SbiStream::ExpandFile()
|
|
|
|
{
|
|
|
|
if ( nExpandOnWriteTo )
|
|
|
|
{
|
|
|
|
ULONG nCur = pStrm->Seek(STREAM_SEEK_TO_END);
|
|
|
|
if( nCur < nExpandOnWriteTo )
|
|
|
|
{
|
|
|
|
ULONG nDiff = nExpandOnWriteTo - nCur;
|
|
|
|
char c = 0;
|
|
|
|
while( nDiff-- )
|
|
|
|
*pStrm << c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pStrm->Seek( nExpandOnWriteTo );
|
|
|
|
}
|
|
|
|
nExpandOnWriteTo = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SbError SbiStream::Write( const ByteString& rBuf, USHORT n )
|
|
|
|
{
|
|
|
|
ExpandFile();
|
|
|
|
if( IsAppend() )
|
|
|
|
pStrm->Seek( STREAM_SEEK_TO_END );
|
|
|
|
|
|
|
|
if( IsText() )
|
|
|
|
{
|
|
|
|
aLine += rBuf;
|
|
|
|
// Raus damit, wenn das Ende ein LF ist, aber CRLF vorher
|
|
|
|
// strippen, da der SvStrm ein CRLF anfuegt!
|
2006-06-19 16:45:30 +00:00
|
|
|
USHORT nLineLen = aLine.Len();
|
|
|
|
if( nLineLen && aLine.GetBuffer()[ --nLineLen ] == 0x0A )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-06-19 16:45:30 +00:00
|
|
|
aLine.Erase( nLineLen );
|
|
|
|
if( nLineLen && aLine.GetBuffer()[ --nLineLen ] == 0x0D )
|
|
|
|
aLine.Erase( nLineLen );
|
2000-09-18 15:18:56 +00:00
|
|
|
pStrm->WriteLines( aLine );
|
|
|
|
aLine.Erase();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !n ) n = nLen;
|
|
|
|
if( !n )
|
|
|
|
return nError = SbERR_BAD_RECORD_LENGTH;
|
|
|
|
pStrm->Write( rBuf.GetBuffer(), n );
|
|
|
|
MapError();
|
|
|
|
}
|
|
|
|
return nError;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Zugriff auf das aktuelle I/O-System:
|
|
|
|
|
|
|
|
SbiIoSystem* SbGetIoSystem()
|
|
|
|
{
|
|
|
|
SbiInstance* pInst = pINST;
|
|
|
|
return pInst ? pInst->GetIoSystem() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SbiIoSystem::SbiIoSystem()
|
|
|
|
{
|
|
|
|
for( short i = 0; i < CHANNELS; i++ )
|
|
|
|
pChan[ i ] = NULL;
|
|
|
|
nChan = 0;
|
|
|
|
nError = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiIoSystem::~SbiIoSystem()
|
|
|
|
{
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
SbError SbiIoSystem::GetError()
|
|
|
|
{
|
|
|
|
SbError n = nError; nError = 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SbiIoSystem::Open
|
|
|
|
( short nCh, const ByteString& rName, short nMode, short nFlags, short nLen )
|
|
|
|
{
|
|
|
|
nError = 0;
|
|
|
|
if( nCh >= CHANNELS || !nCh )
|
|
|
|
nError = SbERR_BAD_CHANNEL;
|
|
|
|
else if( pChan[ nCh ] )
|
|
|
|
nError = SbERR_FILE_ALREADY_OPEN;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pChan[ nCh ] = new SbiStream;
|
|
|
|
nError = pChan[ nCh ]->Open( nCh, rName, nMode, nFlags, nLen );
|
|
|
|
if( nError )
|
|
|
|
delete pChan[ nCh ], pChan[ nCh ] = NULL;
|
|
|
|
}
|
|
|
|
nChan = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aktuellen Kanal schliessen
|
|
|
|
|
|
|
|
void SbiIoSystem::Close()
|
|
|
|
{
|
|
|
|
if( !nChan )
|
|
|
|
nError = SbERR_BAD_CHANNEL;
|
|
|
|
else if( !pChan[ nChan ] )
|
|
|
|
nError = SbERR_BAD_CHANNEL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nError = pChan[ nChan ]->Close();
|
|
|
|
delete pChan[ nChan ];
|
|
|
|
pChan[ nChan ] = NULL;
|
|
|
|
}
|
|
|
|
nChan = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown nach Programmlauf
|
|
|
|
|
|
|
|
void SbiIoSystem::Shutdown()
|
|
|
|
{
|
|
|
|
for( short i = 1; i < CHANNELS; i++ )
|
|
|
|
{
|
|
|
|
if( pChan[ i ] )
|
|
|
|
{
|
2006-10-12 13:29:28 +00:00
|
|
|
SbError n = pChan[ i ]->Close();
|
2000-09-18 15:18:56 +00:00
|
|
|
delete pChan[ i ];
|
|
|
|
pChan[ i ] = NULL;
|
|
|
|
if( n && !nError )
|
|
|
|
nError = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nChan = 0;
|
|
|
|
// Noch was zu PRINTen?
|
|
|
|
if( aOut.Len() )
|
|
|
|
{
|
|
|
|
String aOutStr( aOut, gsl_getSystemTextEncoding() );
|
|
|
|
#if defined GCC
|
2004-01-06 18:42:19 +00:00
|
|
|
Window* pParent = Application::GetDefDialogParent();
|
2000-09-18 15:18:56 +00:00
|
|
|
MessBox( pParent, WinBits( WB_OK ), String(), aOutStr ).Execute();
|
|
|
|
#else
|
2004-01-06 18:42:19 +00:00
|
|
|
MessBox( GetpApp()->GetDefDialogParent(), WinBits( WB_OK ), String(), aOutStr ).Execute();
|
2000-09-18 15:18:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
aOut.Erase();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aus aktuellem Kanal lesen
|
|
|
|
|
|
|
|
void SbiIoSystem::Read( ByteString& rBuf, short n )
|
|
|
|
{
|
|
|
|
if( !nChan )
|
|
|
|
ReadCon( rBuf );
|
|
|
|
else if( !pChan[ nChan ] )
|
|
|
|
nError = SbERR_BAD_CHANNEL;
|
|
|
|
else
|
|
|
|
nError = pChan[ nChan ]->Read( rBuf, n );
|
|
|
|
}
|
|
|
|
|
|
|
|
char SbiIoSystem::Read()
|
|
|
|
{
|
|
|
|
char ch = ' ';
|
|
|
|
if( !nChan )
|
|
|
|
{
|
|
|
|
if( !aIn.Len() )
|
|
|
|
{
|
|
|
|
ReadCon( aIn );
|
|
|
|
aIn += '\n';
|
|
|
|
}
|
|
|
|
ch = aIn.GetBuffer()[0];
|
|
|
|
aIn.Erase( 0, 1 );
|
|
|
|
}
|
|
|
|
else if( !pChan[ nChan ] )
|
|
|
|
nError = SbERR_BAD_CHANNEL;
|
|
|
|
else
|
|
|
|
nError = pChan[ nChan ]->Read( ch );
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SbiIoSystem::Write( const ByteString& rBuf, short n )
|
|
|
|
{
|
|
|
|
if( !nChan )
|
|
|
|
WriteCon( rBuf );
|
|
|
|
else if( !pChan[ nChan ] )
|
|
|
|
nError = SbERR_BAD_CHANNEL;
|
|
|
|
else
|
|
|
|
nError = pChan[ nChan ]->Write( rBuf, n );
|
|
|
|
}
|
|
|
|
|
|
|
|
short SbiIoSystem::NextChannel()
|
|
|
|
{
|
|
|
|
for( short i = 1; i < CHANNELS; i++ )
|
|
|
|
{
|
|
|
|
if( !pChan[ i ] )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
nError = SbERR_TOO_MANY_FILES;
|
|
|
|
return CHANNELS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nChannel == 0..CHANNELS-1
|
|
|
|
|
|
|
|
SbiStream* SbiIoSystem::GetStream( short nChannel ) const
|
|
|
|
{
|
|
|
|
SbiStream* pRet = 0;
|
|
|
|
if( nChannel >= 0 && nChannel < CHANNELS )
|
|
|
|
pRet = pChan[ nChannel ];
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SbiIoSystem::CloseAll(void)
|
|
|
|
{
|
|
|
|
for( short i = 1; i < CHANNELS; i++ )
|
|
|
|
{
|
|
|
|
if( pChan[ i ] )
|
|
|
|
{
|
2006-10-12 13:29:28 +00:00
|
|
|
SbError n = pChan[ i ]->Close();
|
2000-09-18 15:18:56 +00:00
|
|
|
delete pChan[ i ];
|
|
|
|
pChan[ i ] = NULL;
|
|
|
|
if( n && !nError )
|
|
|
|
nError = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Console Support
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
// Einlesen einer Zeile von der Console
|
|
|
|
|
|
|
|
void SbiIoSystem::ReadCon( ByteString& rIn )
|
|
|
|
{
|
|
|
|
String aPromptStr( aPrompt, gsl_getSystemTextEncoding() );
|
|
|
|
SbiInputDialog aDlg( NULL, aPromptStr );
|
|
|
|
if( aDlg.Execute() )
|
|
|
|
rIn = ByteString( aDlg.GetInput(), gsl_getSystemTextEncoding() );
|
|
|
|
else
|
|
|
|
nError = SbERR_USER_ABORT;
|
|
|
|
aPrompt.Erase();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ausgabe einer MessageBox, wenn im Console-Puffer ein CR ist
|
|
|
|
|
|
|
|
void SbiIoSystem::WriteCon( const ByteString& rText )
|
|
|
|
{
|
|
|
|
aOut += rText;
|
|
|
|
USHORT n1 = aOut.Search( '\n' );
|
|
|
|
USHORT n2 = aOut.Search( '\r' );
|
|
|
|
if( n1 != STRING_NOTFOUND || n2 != STRING_NOTFOUND )
|
|
|
|
{
|
|
|
|
if( n1 == STRING_NOTFOUND ) n1 = n2;
|
|
|
|
else
|
|
|
|
if( n2 == STRING_NOTFOUND ) n2 = n1;
|
|
|
|
if( n1 > n2 ) n1 = n2;
|
|
|
|
ByteString s( aOut.Copy( 0, n1 ) );
|
|
|
|
aOut.Erase( 0, n1 );
|
|
|
|
while( aOut.GetBuffer()[0] == '\n' || aOut.GetBuffer()[0] == '\r' )
|
|
|
|
aOut.Erase( 0, 1 );
|
2001-06-13 13:35:13 +00:00
|
|
|
String aStr( s, gsl_getSystemTextEncoding() );
|
2003-11-18 16:00:39 +00:00
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2004-01-06 18:42:19 +00:00
|
|
|
if( !MessBox( GetpApp()->GetDefDialogParent(),
|
2003-11-18 16:00:39 +00:00
|
|
|
WinBits( WB_OK_CANCEL | WB_DEF_OK ),
|
|
|
|
String(), aStr ).Execute() )
|
|
|
|
nError = SbERR_USER_ABORT;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|