20#include "KoDirectoryStore.h"
27KoDirectoryStore::KoDirectoryStore(
const TQString& path, Mode _mode )
30 const int pos = path.findRev(
'/' );
32 if ( pos != -1 && pos != (
int)m_basePath.length()-1 )
33 m_basePath = m_basePath.left( pos );
34 if ( !m_basePath.endsWith(
"/") )
36 m_currentPath = m_basePath;
37 kdDebug(s_area) <<
"KoDirectoryStore::KoDirectoryStore base path:" << m_basePath << endl;
38 m_bGood = init( _mode );
41KoDirectoryStore::~KoDirectoryStore()
45bool KoDirectoryStore::init( Mode _mode )
48 TQDir dir( m_basePath );
51 dir = TQDir::current();
53 if ( _mode == Write && dir.mkdir( m_basePath ) ) {
54 kdDebug(s_area) <<
"KoDirectoryStore::init Directory created: " << m_basePath << endl;
60bool KoDirectoryStore::openReadOrWrite(
const TQString& name,
int iomode )
63 int pos =
name.findRev(
'/');
67 enterAbsoluteDirectory( TQString() );
74 m_stream =
new TQFile( m_basePath + name );
81 if ( iomode == IO_ReadOnly )
86bool KoDirectoryStore::enterRelativeDirectory(
const TQString& dirName )
88 TQDir origDir( m_currentPath );
89 m_currentPath += dirName;
90 if ( !m_currentPath.endsWith(
"/") )
93 TQDir newDir( m_currentPath );
94 if ( newDir.exists() )
97 if (
mode() == Write && origDir.mkdir( dirName ) ) {
98 kdDebug(s_area) <<
"Created " << dirName <<
" under " << origDir.absPath() << endl;
104bool KoDirectoryStore::enterAbsoluteDirectory(
const TQString& path )
106 m_currentPath = m_basePath + path;
108 TQDir newDir( m_currentPath );
109 Q_ASSERT( newDir.exists() );
110 return newDir.exists();
113bool KoDirectoryStore::fileExists(
const TQString& absPath )
const
115 kdDebug(s_area) <<
"KoDirectoryStore::fileExists " << m_basePath+absPath << endl;
116 return TQFile::exists( m_basePath + absPath );
void pushDirectory()
Stacks the current directory.
void popDirectory()
Restores the previously pushed directory.
TQIODevice::Offset m_iSize
Current size of the file named m_sName.
virtual bool init(Mode mode)
Init store - called by constructor.
bool enterDirectory(const TQString &directory)
Enters one or multiple directories.
TQIODevice * m_stream
The stream for the current read or write operation.
const char * name(StdAction id)