KDint xmBadaStat ( const KDchar* path, struct stat* buf )
{
	struct tm       t;
	FileAttributes  attr;
	DateTime        dt;
	result          r;

	r = File::GetAttributes ( path, attr );

	if ( IsFailed ( r ) )
	{
		goto failed;
	}

	dt = attr.GetLastModifiedTime ( );

	t.tm_year = dt.GetYear   ( );
	t.tm_mon  = dt.GetMonth  ( ) - 1;
	t.tm_mday = dt.GetDay    ( );
	t.tm_hour = dt.GetHour   ( );
	t.tm_min  = dt.GetMinute ( );
	t.tm_sec  = dt.GetSecond ( );

	buf->st_mtime = mktime ( &t );
	buf->st_mode  = attr.IsDirectory ( ) ? 0x4000 : 0x8000;
	buf->st_size  = attr.GetFileSize ( );

	return 0;

failed :

	xmBadaSetError ( r );

	return -1;
}
bool SimpleCache::GetFileForIndex(int index, ByteBuffer & data) {

	String filePath;
	BuildPathForFileInCache(index, filePath);

	if (!File::IsFileExist(filePath)) {
		return false;
	}

	AppLog("Reading data from cached file at %S", filePath.GetPointer());

	File cachedFile;
	cachedFile.Construct(filePath, L"r+");
	if (IsFailed(GetLastResult())) {
		AppLog("Error opening destination file in cache");
		return false;
	}

	FileAttributes fAttributes;
	File::GetAttributes(filePath, fAttributes);

	data.Construct(fAttributes.GetFileSize());
	cachedFile.Read(data);
	AppLog("Read cache: %d bytes", data.GetCapacity());
	if (IsFailed(GetLastResult())) {
		AppLog("Error reading from cached file");
		return false;
	}

	return true;

}
KDint xmBadaRename ( const KDchar* _old, const KDchar* _new )
{
	FileAttributes attr;
	result         r;

	r = File::GetAttributes ( _old, attr );

	if ( IsFailed ( r ) )
	{
		goto failed;
	}

	if ( attr.IsDirectory ( ) )
	{
		r = Directory::Rename ( _old, _new );
	}
	else
	{
		r = File::Move ( _old, _new );
	}

	if ( IsFailed ( r ) )
	{
		goto failed;
	}

	return 0;

failed :

	xmBadaSetError ( r );

	return -1;
}
Beispiel #4
0
/**
   adds a mnemonic tag associated with an unresolved path (which
   gets resolved) to the managers known mnemonic
   @param tag the mnemonic reference
   @param an unresolved path name that may contain additional $ variables
   @return whether or not the path was added resolved to a directory and added
   to the manager's known mnemonic
*/
bool 
SysPathMgr::add(
            const String& tag, 
            const String& unresolved)
{
    bool res = false;

    String resolved = resolve(unresolved);
    
    // if it does not exist create
    FileAttributes attrs;
    if ( !FileUtils::getAttributes( resolved, attrs ) )
    {
        if (!FileUtils::mkdirs( resolved ))
        {
            CBLOGERR(_logger, NTEXT("SysPathMgr::add: could not create directory '") + resolved + NTEXT("'"));
            return false;
        }

        // update the file attributes with another call to get info in the directory
        FileUtils::getAttributes( resolved, attrs );
    }

    if (!attrs.isDirectory())
    {
        CBLOGERR(_logger, NTEXT("SysPathMgr::add: found a file where a directory '") + resolved + NTEXT("' was expected"));
        return false;
    }

    _paths[tag] = resolved;

    return res;
}
bool ZLbadaFSManager::canRemoveFile(const std::string &path) const {
	AppLog("ZLbadaFSManager::canRemoveFile %s",path.c_str());
	result r = E_SUCCESS;
	FileAttributes attr;
    r = File::GetAttributes(path.c_str(), attr);
	//TODO   if(IsFailed(r)) goto CATCH;
    if (!attr.IsReadOnly())	AppLog("true"); else AppLog("false");
   return !attr.IsReadOnly();
//	return access(parentPath(path).c_str(), W_OK) == 0;
}
Beispiel #6
0
int FileUtils::rmdir(
    const String &dirName )
{
    int res = 0;
    
    String cleanName = FileUtils::properName( dirName );
    
    { // required because the directory would otherwise be in use
#if defined(_WINDOWS) || defined(WIN32)
        FileIterator it(new FileIterImpWin32);
#else
        FileIterator it(new FileIterImpUnix);
#endif
        String deletePattern = cleanName;
        deletePattern += FileUtils::PATH_SEP;
        deletePattern += FileUtils::ALL_FILES_PAT;

        String dataFileName;

        FileIterator::Status stat = it.findFirst( deletePattern, dataFileName );
        while ( (res == 0) && (stat == FileIterator::cFound) )
        {
            // construct the path to the target
            String targetName = cleanName;
            targetName += FileUtils::PATH_SEP;
            targetName += dataFileName;

            // check to see if the target is a directory
            FileAttributes attrs;
            if ( FileUtils::getAttributes( targetName, attrs ) && 
                 attrs.isDirectory() )
            {
                // if this is a directory, then call rmdir to delete
                res = FileUtils::rmdir( targetName );
            }
            else
            {
                // otherwise delete all the file from this directory
                res = FileUtils::fileDelete( targetName ) ? 0 : -1;
            }

            stat = it.findNext( dataFileName );
        }
    }

#if defined(_WINDOWS) || defined(WIN32)
    res = _trmdir( cleanName.c_str() );
#else
    // now delete the target directory
    res = ::rmdir( cleanName.c_str() );
#endif

    return res;
}
Beispiel #7
0
ArrayListT<Trip *> * IRailAPI::testRoutePlanner(){
	result r = E_SUCCESS;
	String fileName(L"/Home/2.xml");
	File *file = new File();
	FileAttributes sourcefilemeta;
	File::GetAttributes(fileName, sourcefilemeta);
	int filesize = sourcefilemeta.GetFileSize();
	ByteBuffer buffer;
	buffer.Construct(filesize);
	//AppLog("Read buffer size %d", buffer.GetLimit());
	r = file->Construct(fileName, L"r"); //for write: w or w+
	r = file->Read(buffer); //to write: file->Write *beware of the permission w instead of r
	delete file; //closes the file, there is no default close method for files, its gets closed when its scope is closed
	buffer.SetPosition(0);
	ArrayListT<Trip *> * test = createTripList(&buffer);
	//AppLog("completed trips");
	return test;
}
FileIterator::Status 
FileIterImpUnix::findFirst(
            const String &findStr,
            FileAttributes &attrs )
{    
    FileIterator::Status status = FileIterator::cFindError;
    
    closeFind();

    // split the filter from the base path
    StringUtils::splitBack(
        FileUtils::PATH_SEP, 
        findStr,
        &_basePath, &_filter);

    // Make sure that the user has not passed us a directory
    FileAttributes sourceAttrs;
    if ( fpattern_isvalid(_filter.c_str()) &&
         FileUtils::getAttributes(_basePath, sourceAttrs) && 
         sourceAttrs.isDirectory() )
    {
        // have the directory, so now start returning the 
        // and a valid starch path - make sure that the
        // path is fully resolved
        char resolvedPath[MAXPATHLEN+1];
        resolvedPath[0] = '\0';
        
        if ( ::realpath(_basePath.c_str(), resolvedPath) != NULL )
        {
            _fd = ::opendir( resolvedPath );
            if ( _fd != NULL )
            {
                status = findNext( attrs );
            }
        }
    }
    
    return status;
}
Beispiel #9
0
bool 
FileUtils::getFile( 
    const String& fileName, 
    char*& buff, 
    size_t& buffSize )
{
    // initialize the output parameters
    buff = NULL;
    buffSize = 0;
    
    FileAttributes attrs;
    if ( getAttributes( fileName, attrs ) )
    {
        size_t tempBuffSize = (size_t)attrs.getFileSize();
        char* tempBuff = new char[ tempBuffSize ];

#ifdef __GNUG__
        std::ifstream input( fileName.c_str(),
                             std::ios::in |
                             std::ios::binary );
#else
        std::ifstream input( fileName.c_str(),
                             std::ios_base::in |
                             std::ios_base::binary );
#endif

        if ( input.read( tempBuff, tempBuffSize ).good() )
        {
            buff = tempBuff;
            buffSize = tempBuffSize;
        }
        else
        {
            delete [] tempBuff;
        }
    }
    
    return buff != NULL;
}
Beispiel #10
0
void
test_fiterator()
{
#if defined(_WINDOWS) || defined(WIN32)

    TCHAR winFolder[ MAX_PATH + 1 ];
    if ( GetWindowsDirectory( winFolder, MAX_PATH ) > 0 )
    {
        FileIterator iter( new FileIterImpWin32 );
        FileAttributes fileAttr;
        String fileName;
        String folder = winFolder;

        folder += NTEXT("\\*.dll");

        for (   FileIterator::Status stat = iter.findFirst( folder, fileName, &fileAttr );
                stat == FileIterator::cFound;
                stat = iter.findNext( fileName, &fileAttr ) )
        {
            COUT << fileName.c_str() << ": " << fileAttr.getFileSize() << std::endl;
        }
    }
#else
    FileIterator iter( new FileIterImpUnix );
    FileAttributes fileAttr;
    String fileName;
    String folder = NTEXT("/etc/*.conf");

    for (   FileIterator::Status stat = iter.findFirst( folder, fileName, &fileAttr );
            stat == FileIterator::cFound;
            stat = iter.findNext( fileName, &fileAttr ) )
    {
        COUT << fileName.c_str() << ": " << fileAttr.getFileSize() << std::endl;
    }

#endif
}
ZLFileInfo ZLbadaFSManager::fileInfo(const std::string &path) const {
	AppLog("ZLbadaFSManager::fileInfo %s",path.c_str());
	ZLFileInfo info;
	//struct stat fileStat;
    result r = E_SUCCESS;
    FileAttributes attr;
    Tizen::Base::String badaPath(path.c_str());
    r = File::GetAttributes(badaPath, attr);
   //TODO if(IsFailed(r)) goto CATCH;

	//info.Exists = stat(path.c_str(), &fileStat) == 0; stat - не работает
    info.Exists = (r==E_SUCCESS);

	AppLog("ZLbadaFSManager::fileInfo r = %d", r);
	if (info.Exists) {
		info.Size = attr.GetFileSize();//fileStat.st_size;
		//AppLog("ZLbadaFSManager::fileInfo.Size %d",fileStat.st_size);
		AppLog("ZLbadaFSManager::fileInfo.Size %d",info.Size);
		//AppLog("ZLbadaFSManager::fileInfo.st_mode %x",fileStat.st_mode);
		info.IsDirectory = attr.IsDirectory();//S_ISDIR(fileStat.st_mode);
		if (info.IsDirectory) AppLog("ZLbadaFSManager::fileInfo.IsDirectory");
	}
	return info;
}
Beispiel #12
0
int 
StdFileImpl::init( 
    const DOMNode* config, 
    RefCountedPtr<SysContext>& ctx )
{
    int res = -1;
    
    if ( (config != NULL) && (config->getNodeType() == DOMNode::ELEMENT_NODE) )
    {
        const DOMElement* configElem = (const DOMElement*)config;
        
        String val;
        
        // Get the log level setting [optional]
        DOMNodeList* levels = DomUtils::getNodeList( configElem, LOG_LEVEL );
        if ( levels != NULL )
        {
            for ( XMLSize_t i = 0, sz = levels->getLength(); i < sz; i++ )
            {
                if ( DomUtils::getNodeValue( (DOMElement*)levels->item( i ), &val ) )
                {
                    int level = StringUtils::toInt( val );
                    if ( level >= StdLogger::LOGC_ALL )
                    {
                        _logAll = true;
                    }
                    else
                    {
                        _levels.insert( level );
                    }
                }
            }
        }
        
        // get the log file path [required]
        DOMElement* logFileElement = NULL;
        String logFileName;
        if ( DomUtils::selectSingleNode( configElem, FILE_NAME, (DOMNode**)&logFileElement ) )
        {
            if ( DomUtils::getNodeValue( logFileElement, &val ) )
            {	
				RefCountedPtr<SysPathMgr> paths;
				REFCOUNTED_CAST(iSysComponent, SysPathMgr, ctx->getComponent(SysPathMgr::getRegistryName()), paths);
                if ( paths != NULL )
                {
                    logFileName = paths->getPath( val );
                }
                else
                {
                    logFileName = val;
                }

                DOMElement* numFilesElement = NULL;
                DOMElement* sizeFileElement = NULL;

                int numLogs = 0;
                _SizePerLog = 0;
                if ( DomUtils::selectSingleNode( configElem, NUM_FILES, (DOMNode**)&numFilesElement ) )
                {
                    if (DomUtils::getNodeValue( numFilesElement, &val ) )
                    {
                        numLogs = StringUtils::toInt(val);
                    }
                    else 
                    {
                        numLogs = 1;
                    }
                }
                if ( DomUtils::selectSingleNode( configElem, FILE_SIZE, (DOMNode**)&sizeFileElement ) )
                {
                    if (DomUtils::getNodeValue( sizeFileElement, &val ) )
                    {
                        _SizePerLog = StringUtils::toLong(val);
                    }				
                }
                
                if ( (numLogs <= 0) || (_SizePerLog <= 0) )
                {
#ifdef __GNUG__
                    _logFile.open( logFileName.c_str(), std::ios::out | std::ios::app );
#else
                    _logFile.open( logFileName.c_str(), std::ios_base::out | std::ios_base::app );
#endif
                    _logFileNames.push_back( logFileName );
                    _logIndex = 0;
                    _SizePerLog = 0;
                    res = 0;
                }
                else
                {
                    int i;
                    if ( numLogs == 1 )
                    {
                        _logFileNames.push_back( logFileName );
                    }
                    else
                    {
                        for ( i = 1; i <= numLogs; i++ )
                        {
                            _logFileNames.push_back( logFileName + StringUtils::toString(i)+ NTEXT(".txt") );
                        }
                    }

                    FileAttributes fattrs;
                    if ( !FileUtils::getAttributes( _logFileNames[0].c_str(), fattrs ) )
                    {
#ifdef __GNUG__
                        _logFile.open(_logFileNames[0].c_str(), std::ios::out | std::ios::app );
#else
                        _logFile.open(_logFileNames[0].c_str(), std::ios_base::out | std::ios_base::app );
#endif
                        _logIndex = 0;
                        res = 0;
                    }
                    else 
                    {
                        int useindex = 0;
                        struct tm filetime = fattrs.getModifyTime();
                        time_t currtime = ::time(NULL);
                        double besttime = ::difftime( currtime, mktime(&filetime) );
                        for (i = 1; i < numLogs; i++)
                        {
                            if ( FileUtils::getAttributes( _logFileNames[i].c_str(), fattrs ) )
                            {
                                filetime = fattrs.getModifyTime();
                                double thisdiff = ::difftime( currtime, ::mktime(&filetime) );
                                if ( thisdiff < besttime )
                                {
                                    besttime = thisdiff;
                                    useindex = i;
                                }
                            }
                        }

                        FileUtils::getAttributes( _logFileNames[useindex].c_str(), fattrs );
                        if ( (int) fattrs.getFileSize() < _SizePerLog )
                        {
#ifdef __GNUG__
                            _logFile.open(_logFileNames[useindex].c_str(), std::ios::out | std::ios::app );
#else
                            _logFile.open(_logFileNames[useindex].c_str(), std::ios_base::out | std::ios_base::app );
#endif
                            _logIndex = useindex;
                            res = 0;
                        }
                        else
                        {
                            if ( (useindex + 1) >= (int)_logFileNames.size() )
                            {
                                useindex = 0;
                            }
                            else
                            {
                                useindex += 1;
                            }
#ifdef __GNUG__
                            _logFile.open(_logFileNames[useindex].c_str(), std::ios::out | std::ios::trunc );
#else
                            _logFile.open(_logFileNames[useindex].c_str(), std::ios_base::out | std::ios_base::trunc );
#endif
                            _logIndex = useindex;
                            res = 0;
                            
                        }
                    }
                    
                }
            }
        }
    }
    
    return res;
}
Beispiel #13
0
bool 
FileUtils::getAttributes(
    const String &source, 
    FileAttributes &outAttrs )
{
    bool res = false;
    ASSERT_D( source.length() > 0 );
#if defined(_WINDOWS) || defined(WIN32)

    // get the full path of the input source and get it's attributes
    WIN32_FILE_ATTRIBUTE_DATA attrs;
    TCHAR abspath[_MAX_PATH];
    String properSource = FileUtils::properName( _tfullpath( abspath, source.c_str(), _MAX_PATH ) );
    res = ::GetFileAttributesEx( properSource.c_str(), GetFileExInfoStandard, &attrs) == TRUE;
    if ( res )
    {
        // parse out the file name
        String::size_type pos = properSource.rfind(FileUtils::PATH_SEP);
        if ( pos != String::npos )
        {
            String name = properSource.substr( pos + 1 );
            outAttrs.setFileName( name );
        }
        else
        {
            outAttrs.setFileName( properSource );
        }

        // fill out the size and time structures
        outAttrs.setFileSize( attrs.nFileSizeLow );
        outAttrs.setFileSizeEx( attrs.nFileSizeHigh );

        FILETIME localFileTime;
        SYSTEMTIME sysTime;
        struct tm tmTime;

        if ( ::FileTimeToLocalFileTime( &attrs.ftCreationTime, &localFileTime ) )
        {
            if ( ::FileTimeToSystemTime( &localFileTime, &sysTime ) )
            {
                tmTime.tm_year= sysTime.wYear - 1900;
                tmTime.tm_mon  = sysTime.wMonth - 1;
                tmTime.tm_wday = sysTime.wDayOfWeek;
                tmTime.tm_mday = sysTime.wDay;
                tmTime.tm_hour = sysTime.wHour;
                tmTime.tm_min = sysTime.wMinute;
                tmTime.tm_sec = sysTime.wSecond;

                outAttrs.setCreateTime( tmTime );
            }
        }

        if ( ::FileTimeToLocalFileTime( &attrs.ftLastWriteTime, &localFileTime ) )
        {
            if ( ::FileTimeToSystemTime( &localFileTime, &sysTime ) )
            {
                tmTime.tm_year= sysTime.wYear - 1900;
                tmTime.tm_mon  = sysTime.wMonth - 1;
                tmTime.tm_wday = sysTime.wDayOfWeek;
                tmTime.tm_mday = sysTime.wDay;
                tmTime.tm_hour = sysTime.wHour;
                tmTime.tm_min = sysTime.wMinute;
                tmTime.tm_sec = sysTime.wSecond;

                outAttrs.setModifyTime( tmTime );
            }
        }

        // finally, fill out the attributes
        outAttrs.setArchive( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE );
        outAttrs.setCompressed( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) == FILE_ATTRIBUTE_COMPRESSED );
        outAttrs.setDirectory( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY );
        outAttrs.setHidden( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN );
        outAttrs.setOffline( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) == FILE_ATTRIBUTE_OFFLINE );
        outAttrs.setReadonly( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY );
        outAttrs.setTemp( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) == FILE_ATTRIBUTE_TEMPORARY );
        outAttrs.setSystem( ( attrs.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) == FILE_ATTRIBUTE_SYSTEM );
    }

#else

    String resolvedPath = FileUtils::resolve( source );
    if ( resolvedPath.length() > 0 )
    {
        struct stat buff;
        res =  ::stat( resolvedPath.c_str(), &buff ) == 0;
        if ( res )
        {
            String theFileName;
            if ( StringUtils::splitBack( 
                     FileUtils::PATH_SEP,
                     resolvedPath,
                     NULL, &theFileName ) )
            {
                outAttrs.setFileName( theFileName );
            }
            else
            {
                outAttrs.setFileName( resolvedPath );
            }
            
            outAttrs.setFileSize( buff.st_size );
            outAttrs.setFileSizeEx(0);
            
            struct tm tmTime;
            
            tmTime = *::gmtime( &buff.st_atime );
            outAttrs.setCreateTime( tmTime );
            
            tmTime = *::gmtime( &buff.st_mtime );    
            outAttrs.setModifyTime( tmTime );
            
            outAttrs.setArchive( !S_ISDIR(buff.st_mode) );
            outAttrs.setDirectory( S_ISDIR(buff.st_mode) );
            outAttrs.setHidden( theFileName[0] == NTEXT('.') );
            outAttrs.setReadonly( ( buff.st_mode & S_IWUSR) == 0 );

            outAttrs.setCompressed( false );
            outAttrs.setOffline( false );
            outAttrs.setTemp( false );
            outAttrs.setSystem( false );   
        }    
    }
    
#endif

    return res;

}
Beispiel #14
0
bool 
FileUtils::fileCopy( 
    const String &source, 
    const String& dest,
    const bool replace )
{
    ASSERT_D( source.length() > 0 );
    ASSERT_D( dest.length() > 0 );

#if defined(_WINDOWS) || defined(WIN32)
    return ::CopyFile( source.c_str(), dest.c_str(), replace ? FALSE : TRUE ) == TRUE;
#else

    // validate the source file 
    FileAttributes attrs;
    bool res = FileUtils::getAttributes( source, attrs );
    if ( !res || attrs.isDirectory() )
    {
        return false;
    }

    // if the destination file exists, replace is false, then we don't 
    // allow the procedure to complete
    FileAttributes destattrs;
    if ( FileUtils::getAttributes( dest, destattrs ) && 
         !destattrs.isDirectory() && 
         (!replace || destattrs.isReadonly()) )
    {
        return false;
    }

#ifdef __GNUG__
            IFSTREAM input( source.c_str(),
                                 std::ios::in |
                                 std::ios::binary );
            OFSTREAM output( dest.c_str(),
                                 std::ios::out |
                                 std::ios::binary );
#else
            IFSTREAM input( source.c_str(),
                                 std::ios_base::in |
                                 std::ios_base::binary );
            OFSTREAM output( dest.c_str(),
                                 std::ios::out |
                                 std::ios::binary );
#endif

    if ( input.good() && output.good() )
    {
        std::auto_ptr<char> buff( new char[COPY_BUFF_SIZE] );
        if ( buff.get() != NULL )
        {
            const char* pBuff = buff.get();
#ifdef __GNUG__
            input.seekg( 0, std::ios::end );
            int numBytesLeft = input.tellg() ;
            input.seekg( 0, std::ios::beg );
#else
            input.seekg( 0, std::ios_base::end );
            int numBytesLeft = input.tellg() ;
            input.seekg( 0, std::ios_base::beg );
#endif

            while ( numBytesLeft > 0 && res )
            {
                int numToRead = (numBytesLeft > COPY_BUFF_SIZE) ? COPY_BUFF_SIZE : numBytesLeft;
                res = ( input.read( (char*)pBuff, numToRead ) && 
                        output.write( pBuff, numToRead ) );
                numBytesLeft -= numToRead;
            }
        }
    
        if ( res )
        {
            res = FileUtils::setAttributes( dest, attrs );
        }
    }
    
    return res;
#endif

}
Beispiel #15
0
int 
SysPathMgr::init( 
            const DOMNode* config, 
            RefCountedPtr<SysContext>& ctx )
{
    int res = -1;

    REFCOUNTED_CAST(iSysComponent, StdLogger, ctx->getComponent( StdLogger::getRegistryName()), _logger);

	// I expect the config node to be an element node
    if ( ( config != NULL ) && ( config->getNodeType() == DOMNode::ELEMENT_NODE ) )
    {
        // set the root to be the current directory by default
        String root(NTEXT("."));

        Mapping rootAttrs;
        if ( DomUtils::getNodeValue( (const DOMElement*)config, NULL, &rootAttrs ) )
        {
            rootAttrs.getIfAvailable(SYS_PATH_ROOTATTR, root);
        }

        // resolve whatever we have in the root and then verify a file does not exist
        // in place of the intended directory
        _root = FileUtils::resolve( root );

        FileAttributes fattrs;
        if ( !FileUtils::getAttributes( _root, fattrs ) )
        {
            if (!FileUtils::mkdirs( _root ))
            {
                CBLOGERR(_logger, NTEXT("SysPathMgr::init: could not create directory '") + _root + NTEXT("'"));
                return -1;
            }

            // update the file attributes with another call to get info in the directory
            FileUtils::getAttributes( _root, fattrs );
        }

        if (!fattrs.isDirectory())
        {
            CBLOGERR(_logger, NTEXT("SysPathMgr::init: found a file where a directory '") + _root + NTEXT("' was expected"));
            return -1;
        }

        // put a special key with the root attribute in the map
    	_paths[ SYS_PATH_IND + SYS_PATH_ROOTATTR ] = _root;

        // ok to this point, no errors
        res = 0;

        // iterate through the list of child elements whose tag is SYS_PATH_ENTRY
        // and get the name attribute and value. If all is found properly, then
        // construct a counter whose value is retrieved from the config node
        DOMNodeList* children = DomUtils::getNodeList( (const DOMElement*)config, SYS_PATH_ENTRY );
        if ( children != NULL )
        {
            for ( XMLSize_t i = 0, sz = children->getLength() ;
                  i < sz; i++ )
            {
                DOMNode* child = children->item(i);
                if ( (child != NULL) && (child->getNodeType() == DOMNode::ELEMENT_NODE) )
                {
                    String value;
                    Mapping attrs;

                    bool found = DomUtils::getNodeValue( (const DOMElement*)child, &value, &attrs );
                    if ( found )
                    {
                        res = 0;

                        String tagName;
                        attrs.getIfAvailable(SYS_PATH_TAGATTR, tagName);

                        if ( tagName.length() > 0 )
                        {
                            add( tagName, value );
                        }
                    }
                }
            }
        }
    }

    return res;
}
Beispiel #16
0
result
CategoryItemForm::ReadCustomListItems()
{
	result r = E_SUCCESS;
	String dirName(L"/Home/catalog/"+dir);
	Directory* pDir;
	DirEnumerator* pDirEnum;

	pDir = new Directory; // allocate Directory instance

	// Open directory
	r = pDir->Construct(dirName);

	// Read all directory entries
	pDirEnum = pDir->ReadN();

	String contentType;
	int i = 0;
	while(pDirEnum->MoveNext() == E_SUCCESS) {
		DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
		if(dirEntry.IsNomalFile()) {
			//AppLog("%S", dirEntry.GetName().GetPointer());
			if(!dirEntry.GetName().Equals("category.info", false)) {

				String fileName(dirName+"/"+dirEntry.GetName());

				String title, desc;
				String iTempStr, iTempStr2;

				File file;
				result r = file.Construct(fileName, L"r");
				if( IsFailed(r) )
				{
						AppLog("File::Consturct() is failed by %s", GetErrorMessage(r));
				}

				FileAttributes fileAttrs;
				file.GetAttributes(fileName, fileAttrs);
				long long size = fileAttrs.GetFileSize();


				ByteBuffer readBuffer;
				readBuffer.Construct((int)size + 1);

				r = file.Read(readBuffer);
				if( IsFailed(r) )
				{
						AppLog("File::Read() is failed by %s", GetErrorMessage(r));
				}

				char* data = new char[readBuffer.GetLimit()+1];
				readBuffer.SetPosition(0);
				readBuffer.GetArray((byte*)data, 0, readBuffer.GetLimit());
				data[readBuffer.GetLimit()] ='\0';
				//String str = String(data);

				String str;
				r = StringUtil::Utf8ToString(data, str);
				delete data;
				if(IsFailed(r)) {
					AppLog("File read error. File : %S", fileName.GetPointer());
					continue;
				}

				file.Seek(FILESEEKPOSITION_BEGIN, 0);
				file.Read(title);

				r = TextPic::GetTranslated(title);
				if (IsFailed(r)) {
					continue;
				}

				int linecount = 0;
				while(file.Read(iTempStr) != E_END_OF_FILE) {
					linecount++;
					iTempStr2.Append(iTempStr);
				}

				anciilist.Add(*(new String(iTempStr2)));
				titlelist.Add(*(new String(title)));
				filelist.Add(*(new String(fileName)));

				ItemListForm::AddListItem(*CategoryList, title, iTempStr2, i++, linecount);
				file.Flush();
			}
		}
	}

	delete pDirEnum;
	delete pDir;

	return r;
}