示例#1
0
void CFileContent::load() {
	ifstream is( realPath_m, ifstream::binary );
	if ( !is )
		throw FileNotFoundException( userPath_m.c_str(), "" );

	is.seekg( 0, is.end );
	size_m = (size_t) is.tellg();
	is.seekg( 0, is.beg );

	char * buf = new char[size_m];
	is.read( buf, size_m );

	size_m = (size_t) is.tellg();

	data_m.insert( data_m.begin(), buf, buf + size_m );
	delete[] buf;

	if ( !is.good() )
		throw FileErrorException( userPath_m.c_str() );

	is.close();

	modificationTime();
	creationTime();
}
示例#2
0
void CDirContent::load() {
	int rc;
	DIR * dir;
	dirent entry;
	dirent * result;
	Log.ger<>( DEBUG_REQUEST, "Directory:", realPath_m, userPath_m );
	vector<CHTMLGenerator> files_m;

	if ( !( dir = opendir( realPath_m.c_str() ) ) ) {
		int errNo = errno;

		switch ( errNo ) {
			case EACCES:
				throw PermissionDeniedException( userPath_m );
			case ENOENT:
				throw FileNotFoundException( userPath_m );
			default:
				throw FileErrorException( userPath_m );
		}
	}

	while ( !( rc = readdir_r( dir, &entry, &result ) ) ) {
		if ( result == nullptr )
			break;
		files_m.push_back( CHTMLGenerator( result->d_name ) );
		Log.ger<>( DEBUG_REQUEST, "Directory", result->d_name, (int)result->d_type );
		if ( result->d_type == DT_DIR || result->d_type == DT_REG )
			files_m.back().makeHyperlink( makeLink( result->d_name ) );
		files_m.back().enlarge();
		if ( !strcmp( result->d_name, ".." ) )
			files_m.back().setPriority( -2 );
		else if ( !strcmp( result->d_name, "." ) )
			files_m.back().setPriority( -1 );
	}

	stable_sort( files_m.begin(), files_m.end() );

	CHTMLGenerator table( string( "Index of " ) + userPath_m );
	table.enlarge( 2 ).makeTable( files_m );
	if ( rc )
		table.append( "\nAn error occured while reading directory content. Try to refresh page\n" );
	string rawHTML = table.wrap( string( "Index of " ) + userPath_m.c_str() );
	data_m.insert( data_m.begin(), rawHTML.begin(), rawHTML.end() );

	closedir( dir );

	size_m = data_m.size();

	modificationTime();
	creationTime();
}
示例#3
0
void CollectionConfiguration::copyConfiguration(const QHelpEngineCore &source,
                                                QHelpEngineCore &target)
{
    setCreationTime(target, creationTime(source));
    setWindowTitle(target, windowTitle(source));
    target.setCurrentFilter(source.currentFilter());
    setCacheDir(target, cacheDir(source), cacheDirIsRelativeToCollection(source));
    setFilterFunctionalityEnabled(target, filterFunctionalityEnabled(source));
    setFilterToolbarVisible(target, filterToolbarVisible(source));
    setAddressBarEnabled(target, addressBarEnabled(source));
    setAddressBarVisible(target, addressBarVisible(source));
    setDocumentationManagerEnabled(target, documentationManagerEnabled(source));
    setApplicationIcon(target, applicationIcon(source));
    setAboutMenuTexts(target, aboutMenuTexts(source));
    setAboutIcon(target, aboutIcon(source));
    setAboutTexts(target, aboutTexts(source));
    setAboutImages(target, aboutImages(source));
    setDefaultHomePage(target, defaultHomePage(source));
}
bool CollectionConfiguration::isNewer(const QHelpEngineCore &newer,
                                const QHelpEngineCore &older)
{
    return creationTime(newer) > creationTime(older);
}
void AbstractAspect::writeBasicAttributes(QXmlStreamWriter * writer) const
{
	writer->writeAttribute("creation_time" , creationTime().toString("yyyy-dd-MM hh:mm:ss:zzz"));
	writer->writeAttribute("caption_spec", captionSpec());
	writer->writeAttribute("name", name());
}
示例#6
0
		std::time_t File::creationTime() const
		{
			_mutex.lock();
			
			return creationTime(_filePath);
		}
示例#7
0
gbool GUrlCache::GetCacheStats(const char *directory, time_t &oldest,DWORD &spaceInUse, int &filesInUse)
{

    CFileFind finder;

    CString dir = directory;

    // add separator
    int l = dir.GetLength();
    if (l == 0) return FALSE;
    if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';

    dir += "*.*";

    CString path;

    CTime creationTime((time_t)0);
    CTime accessTime((time_t)0);
    CTime writeTime((time_t)0);

    // setup the find structure
    BOOL bWorking = finder.FindFile(dir);


    while (bWorking)  { // for all entrys
        if (stop) break;

        bWorking = finder.FindNextFile();

        path = finder.GetFilePath();

        creationTime = (time_t)0;
        accessTime = (time_t)0;
        writeTime = (time_t)0;

        BOOL ret=finder.GetCreationTime(creationTime);
        finder.GetLastAccessTime(accessTime);
        finder.GetLastWriteTime(writeTime);
        time_t t = creationTime.GetTime();

        if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());


        if (finder.IsDots( )) {	// ignore . ..

        } else 	if (finder.IsDirectory( )) { // recursively step down
            GetCacheStats(path,oldest,spaceInUse,filesInUse);
        }
        else {

            DWORD length = finder.GetLength();

            TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
            oldest = min(oldest,t);
            filesInUse++;
            spaceInUse += length;

        }


    }
    finder.Close();


    return TRUE;
}
示例#8
0
// recursively remove a file branch
gbool GUrlCache::RemoveFiles(const char *directory,time_t olderThan)
{

    CFileFind finder;

    CString dir = directory;

    // add separator
    int l = dir.GetLength();
    if (l == 0) return FALSE;
    if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';

    dir += "*.*";

    CString path;

    CTime creationTime((time_t)0);
    CTime accessTime((time_t)0);
    CTime writeTime((time_t)0);

    // setup the find structure
    BOOL bWorking = finder.FindFile(dir);

    LONGLONG fileSum=0;

    while (bWorking)  { // for all entrys
        if (stop) break;

        bWorking = finder.FindNextFile();

        path = finder.GetFilePath();

        creationTime = (time_t)0;
        accessTime = (time_t)0;
        writeTime = (time_t)0;

        BOOL ret=finder.GetCreationTime(creationTime);
        finder.GetLastAccessTime(accessTime);
        finder.GetLastWriteTime(writeTime);
        time_t t = creationTime.GetTime();

        // if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());


        if (finder.IsDots( )) {	// ignore . ..

        } else 	if (finder.IsDirectory( )) { // recursively step down
            RemoveFiles(path,olderThan);
            RemoveDirectory(path);
        }
        else {

            DWORD length = finder.GetLength();

            TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
            if (olderThan >0 ) {

                if (t < olderThan) {
                    if (RemoveFile(path))
                        fileSum += length;
                }


            } else {
                if (RemoveFile(path))
                    fileSum += length;
            }

        }


    }
    finder.Close();

    TRACE("%ld bytes deleted \n",(long) fileSum);

    return TRUE;
}
示例#9
0
// add files to list
gbool GFileSorter::AddFiles(const char *directory,time_t &maxFileTime,BOOL &stop)
{

    CFileFind finder;

    CString dir = directory;

    // add separator
    int l = dir.GetLength();
    if (l == 0) return FALSE;
    if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';

    dir += "*.*";

    CString path;

    CTime creationTime((time_t)0);
    CTime accessTime((time_t)0);
    CTime writeTime((time_t)0);

    // setup the find structure
    BOOL bWorking = finder.FindFile(dir);


    while (bWorking)  { // for all entrys
        if (stop) break;

        bWorking = finder.FindNextFile();

        path = finder.GetFilePath();

        creationTime = (time_t)0;
        accessTime = (time_t)0;
        writeTime = (time_t)0;

        BOOL ret=finder.GetCreationTime(creationTime);
        finder.GetLastAccessTime(accessTime);
        finder.GetLastWriteTime(writeTime);

        time_t t = creationTime.GetTime();

        if (writeTime.GetTime()>0) t = max(t,writeTime.GetTime()); // HG wg Kristof

        if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());

        if (finder.IsDots( )) {	// ignore . ..

        } else 	if (finder.IsDirectory( )) { // recursively step down

            t=0; // we want to delete empty directories new 20.10.98
            AddFiles(path,t,stop);

            DWORD length = 0;

            // to do get date of latest
            TRACE("D %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);

            // time is the max of the child time +1
            GFSortEntry *e = new GFSortEntry(path,t+1,length,gtrue);

            if (!e) break;
            if (!Add(e)) break;

            if (t>maxFileTime) maxFileTime = t;


        }
        else {

            DWORD length = finder.GetLength(); // get length 64
            fileSum += length;

            TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
            GFSortEntry *e = new GFSortEntry(path,t,length);

            if (t>maxFileTime) maxFileTime = t;

            if (!e) break;
            if (!Add(e)) break;
        }


    }
    finder.Close();

    //TRACE("%ld bytes \n",(long)fileSum);

    return TRUE;
}