Example #1
0
/* public slots */
void ShredThread::run()
{
    PERCENT *p = new PERCENT();
    quint64 _size = getDirSize(tempDir) + getDirSize(homeDir);
    //qDebug()<<_size<<"common size";
    p->setSize( _size );
    SettingsDialog::clean_Directory( tempDir, this, p);
    SettingsDialog::clean_Directory( homeDir, this, p);
    p->clear();
    msleep(1333);
}
Example #2
0
/* private slots */
qint64 ShredThread::getDirSize(QString &dir)
{
    uint _size = 0;
    QDir::Filters flags =
            QDir::AllEntries |
            QDir::NoDotAndDotDot |
            QDir::Hidden |
            QDir::System |
            QDir::AllDirs;
    QDir d;
    d.setPath(dir);
    QList<QFileInfo> entry = d.entryInfoList(flags);
    if ( !entry.isEmpty() ) {
        QList<QFileInfo>::const_iterator i;
        for ( i=entry.constBegin(); i<entry.constEnd(); i++ ) {
            QFileInfo item = *i;
            if ( !item.exists() ) continue;
            QString path = item.canonicalFilePath();
            if ( path==d.absoluteFilePath(dir)
                 || item.isSymLink() )
                continue;
            if ( item.isDir() ) {
                _size += getDirSize(path);
            } else {
                _size += item.size();
            };
        };
    };
    return _size;
}
unsigned int getDirSize(const char* path)
{
	DIR *dp;
	struct dirent *entry;
	struct stat statbuf;
	unsigned int size=0;
	char newDir[256];
	if ((dp=opendir(path))==NULL) {
		return 0;
	}
	chdir(path);
	while ((entry=readdir(dp))!=NULL)
	{
		if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
		{
			stat(entry->d_name, &statbuf);
			if ((statbuf.st_mode&S_IFMT)==S_IFDIR) 	{
				sprintf(newDir, "%s/%s", path, entry->d_name);
				size+=getDirSize(newDir);
			}
			else if ((statbuf.st_mode&S_IFMT)==S_IFREG) {
				size+=statbuf.st_size;
			}
		}
	}
	return size;
}
long long getDirSize(wxString& directoryFile, long& numFiles)
{
   wxDir dir;
   wxString filename;
   long long totalSize = 0;
   if (!dir.Exists(directoryFile))
   {
      numFiles++;
      return getFileSize(directoryFile);
   }
   else
   {
      dir.Open(directoryFile);
      if (dir.IsOpened())
      {
         wxString wxStrFileName;
         bool cont = dir.GetFirst(&filename);
         while (cont)
         {
            wxStrFileName = directoryFile + "\\" + filename;
            totalSize = totalSize + getDirSize(wxStrFileName, numFiles);
            cont = dir.GetNext(&filename);
         }
      }
   }
   return totalSize;
}
Example #5
0
int getDirSize( const char * path, int includeSubdirs, unsigned int * dirSize )
{
    char dirPath[MAX_FILENAME_LENGTH];
	unsigned int size = 0;
    if( "" == path ){
        return false;
    }

    memset( dirPath,0,MAX_FILENAME_LENGTH );
    strcpy( dirPath,path );

    if( dirPath[strlen(dirPath)-1] != '/' )
        dirPath[strlen(dirPath)] = '/';
    if( strlen(dirPath) > MAX_FILENAME_LENGTH )
        return false;

    DIR_STATE_STRUCT *dir;
	dir = fat_opendir((const char*)dirPath);
    if (dir == NULL)
        return false;
    
    struct stat stat_buf;
	DIR_ENTRY *currentEntry;
    char* filename;

	while(fat_readdir_ex(dir, &stat_buf) != NULL)
	{
		filename = currentEntry->d_name;

        if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0)
            continue;

        if (!(stat_buf.st_mode & S_IFDIR)) {
			size += (stat_buf.st_size+511)/512;
			_usedSecNums +=(stat_buf.st_size+511)/512;
		}
		else if (includeSubdirs)
		{
			// calculate the size recursively 
            unsigned int subDirSize = 0;
			char dirPathBuffer[MAX_FILENAME_LENGTH];

            memset( dirPathBuffer,0,MAX_FILENAME_LENGTH );
            strcpy( dirPathBuffer,dirPath );
            memset( dirPath,0,MAX_FILENAME_LENGTH );
            sprintf( dirPath,"%s%s",dirPathBuffer,filename );
            int succ = getDirSize( dirPath, includeSubdirs, &subDirSize );
            if( succ ) {
                size += (subDirSize+511)/512;
                _usedSecNums +=(subDirSize+511)/512;
            }
            memset( dirPath,0,MAX_FILENAME_LENGTH );
            strcpy( dirPath,dirPathBuffer );
        }
    }

	fat_closedir(dir);

    *dirSize = size;
Example #6
0
}

int fat_getDiskSpaceInfo( char * diskName, unsigned int * total, unsigned int * used, unsigned int * freeSpace )
{
	_usedSecNums = 0;

	if( !strcmp("",diskName) )
		return -1;
    if( !fat_getDiskTotalSpace(diskName, total) )
		return -1;
	if( !getDirSize(diskName, true, used) )
		return -1;

    *used = _usedSecNums;
    if( *total <= *used ){
   	 	*freeSpace = 0;
   	}else{
    	*freeSpace = *total - *used;
  	}
long long getDirSize(wxString& directoryFile)
{
   long numFiles;
   return getDirSize(directoryFile, numFiles);
}