Example #1
1
//------------------------------------------------------------------------------
QStringList recursiveFind(QString directory)
{
    //// подумать, нужен ли чистый рекурсивный поиск
    //// если нет, то сюда вставить обработку getModuleFilesList
    QStringList list;
    QDirIterator iterator (directory, QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
    while(iterator.hasNext())
    {
        iterator.next();
        list << iterator.fileInfo().absoluteFilePath();
    }
    return list;
}
Example #2
0
			void ThirdStep::initializePage ()
			{
				TotalSize_ = 0;
				QString path = field ("RootPath").toString ();

				QFileInfo pathInfo (path);
				if (pathInfo.isDir ())
				{
					QDirIterator it (path,
							QDirIterator::Subdirectories);
					while (it.hasNext ())
					{
						it.next ();
						QFileInfo info = it.fileInfo ();
						if (info.isFile () && info.isReadable ())
							TotalSize_ += info.size ();
					}
				}
				else if (pathInfo.isFile () &&
						pathInfo.isReadable ())
					TotalSize_ += pathInfo.size ();

				quint64 max = std::log (static_cast<long double> (TotalSize_ / 102400)) * 80;

				quint32 pieceSize = 32 * 1024;
				int shouldIndex = 0;
				for (; TotalSize_ / pieceSize >= max; pieceSize *= 2, ++shouldIndex) ;

				if (shouldIndex > PieceSize_->count () - 1)
					shouldIndex = PieceSize_->count () - 1;

				PieceSize_->setCurrentIndex (shouldIndex);

				on_PieceSize__currentIndexChanged ();
			}
void FileSystemModel::iterateFilesystem(ListingType type, bool sort)
{
    // clear and delete the filelist
    this->clear();

    // create a new filelist object
    this->m_filelist = new QStringList();

    // define a QDirIterator pointer
    QDirIterator *iterator = nullptr;

    // create the QDirIterator depending on the set name filters
    if (this->m_filters.isEmpty())
    {
        iterator = new QDirIterator(this->m_dir.absolutePath(),                                     // model directory
                                    this->qDirFiles(),                                              // filter
                                    QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);   // iterator flags
    }

    else
    {
        iterator = new QDirIterator(this->m_dir.absolutePath(), this->m_filters,                    // model directory and name filters
                                    this->qDirFiles(),                                              // filter
                                    QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);   // iterator flags
    }

// define iterator template
// for performance reasons, do not compare the type each time (SLOW, if for example more than 1 million + files)
// check the type once and than build the list straightforward
#define ITERATOR_BEGIN \
    while (iterator->hasNext()) { \
        (void) iterator->next(); // QDirIterator points to nothing at the beginning
#define ITERATOR_END }

        if (type == Filenames)
        {
            ITERATOR_BEGIN
                this->m_filelist->append(iterator->fileInfo().fileName());
            ITERATOR_END
        }
Example #4
0
/***************************************************************************
 * ScanDir
 ***************************************************************************/
QList<CNDSromData> CNDSromScanner::ScanDir(QString d, CNDSdbIfc * dbIfc, bool bAddDirs)
{
	QList<CNDSromData>	res;
	QDirIterator *		di;
	QFileInfo		fi;
	nds_rom_info_t		rom_info;
	uint			i;
	CNDSbgr555		bgr;

	this->Status("Scan gestartet.", 2000);
	if (bAddDirs)
	{
		di = new QDirIterator(d, QDirIterator::NoIteratorFlags);
	}
	else
	{
		di = new QDirIterator(d, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
	}

	while (di->hasNext())
	{
		di->next();
		fi = di->fileInfo();
		if (fi.isFile())
		{
			CNDSromData rd;

			rd.ROMpath = fi.absolutePath();
			DBG("ROMpath:" << rd.ROMpath);

			rd.ROMfilename = fi.fileName();
			DBG("ROMfilename:" << rd.ROMfilename);
			rd.ROMfilesize = (uint) fi.size();
			DBG("ROMfilesize:" << rd.ROMfilesize);

			this->Status(rd.ROMfilename);
			// Run ROM through Scanner
			if (this->ScanRom(rd.ROMpath, rd.ROMfilename, &rom_info))
			{
				rd.isROM = true;

				// ROM Version
				rd.ROMversion = rom_info.icon.version;
				DBG("ROMversion:" << rd.ROMversion);
				// CRC32
				rd.ROMcrc32 = (uint)rom_info.file_crc32;
				DBG("ROMcrc32:" << rd.ROMcrc32);
				// Internal ROM Name
				rd.ROMname = QString::fromUtf8((char *)rom_info.hdr.game_title, 
					get_romstring_size(rom_info.hdr.game_title, 12)).trimmed();
				DBG("ROMname:" << rd.ROMname);
				// ROM Serial
				rd.ROMserial = "NTR-" + QString::fromUtf8((char *)rom_info.hdr.game_code, 4) + "-";
				for (i=0; i<(sizeof(nds_rom_countries) / sizeof(nds_rom_countries[0])); i++)
				{
					if (nds_rom_countries[i].C == rom_info.hdr.game_code[3])
					{
						rd.ROMserial += QString(nds_rom_countries[i].Name);
						break;
					}
				}
				DBG("ROMserial:" << rd.ROMserial);
				// Game Title in native Languages
				rd.ROMlanguage[JPN].Name = QString::fromUtf16(rom_info.icon.title_jpn);
				DBG("ROMlanguage[JPN]:" << rd.ROMlanguage[JPN].Name);
				rd.ROMlanguage[ENG].Name = QString::fromUtf16(rom_info.icon.title_eng);
				DBG("ROMlanguage[ENG]:" << rd.ROMlanguage[ENG].Name);
				rd.ROMlanguage[FRN].Name = QString::fromUtf16(rom_info.icon.title_frn);
				DBG("ROMlanguage[FRN]:" << rd.ROMlanguage[FRN].Name);
				rd.ROMlanguage[GER].Name = QString::fromUtf16(rom_info.icon.title_grm);
				DBG("ROMlanguage[GER]:" << rd.ROMlanguage[GER].Name);
				rd.ROMlanguage[ITL].Name = QString::fromUtf16(rom_info.icon.title_itl);
				DBG("ROMlanguage[ITL]:" << rd.ROMlanguage[ITL].Name);
				rd.ROMlanguage[SPN].Name = QString::fromUtf16(rom_info.icon.title_spn);
				DBG("ROMlanguage[SPN]:" << rd.ROMlanguage[SPN].Name);
				// Only if Version > 1
				if (rd.ROMversion > 1)
				{
					rd.ROMlanguage[CHI].Name = QString::fromUtf16(rom_info.icon.title_chi);
					DBG("ROMlanguage[CHI]:" << rd.ROMlanguage[CHI].Name);
				}
				// ROM Code
				rd.ROMcode = QString::fromUtf8((char *)rom_info.hdr.maker_code, 
					get_romstring_size(rom_info.hdr.maker_code, 2)).trimmed();
				DBG("ROMcode:" << rd.ROMcode);
				// ROM Publisher
				rd.ROMpublisher = dbIfc->readVendor(
					rd.ROMcode.left(1).data()->unicode(),
					rd.ROMcode.right(1).data()->unicode());
				DBG("ROMpublisher:" << rd.ROMpublisher);
				// ROM Unitcode
				rd.ROMunitcode.setNum(rom_info.hdr.unit_code, 16);
				DBG("ROMunitcode:" << rd.ROMunitcode);
				// ROM Capacity
				rd.ROMcapacity = (((128*1024) << rom_info.hdr.dev_capacity)*8/(float)MB);
				DBG("ROMcapacity:" << rd.ROMcapacity);

				// ROM Displayname
				rd.ROMdisplname = rd.ROMfilename;
				rd.ROMdisplname.resize(rd.ROMdisplname.length() - 4);
				DBG("ROMdisplname:" << rd.ROMdisplname);

				rd.fixROMlanguage();

				// Create Icon
				rd.ROMicon = bgr.createIcon(&rom_info.icon);

			}

			res << rd;
			
		}
		else
		{
			if (bAddDirs)
			{
				bool	bSkipDir;

				bSkipDir = ((fi.fileName().compare(".") == 0) | (fi.fileName().compare("..") == 0));

				if (!bSkipDir)
				{
					CNDSromData rd;
	
					rd.ROMstate = STATE_DIRECTORY;
					rd.ROMpath = fi.absolutePath();
					DBG("ROMpath:" << rd.ROMpath);
					rd.ROMname = fi.fileName();
					DBG("ROMfilename:" << rd.ROMname);
	
					res << rd;
				}
			}
		}
	}

	this->Status("Scan abgeschlossen.", 2000);

	return (res);
}
Example #5
0
	void PackageProcessor::handlePackageUnarchFinished (int ret, QProcess::ExitStatus)
	{
		sender ()->deleteLater ();

		QProcess *unarch = qobject_cast<QProcess*> (sender ());
		int packageId = unarch->property ("PackageID").toInt ();
		const auto& stagingDir = unarch->property ("StagingDirectory").toString ();
		Mode mode = static_cast<Mode> (unarch->property ("Mode").toInt ());

		auto cleanupGuard = std::shared_ptr<void> (nullptr,
				[&stagingDir, this] (void*) { CleanupDir (stagingDir); });

		if (ret)
		{
			QString errString = QString::fromUtf8 (unarch->readAllStandardError ());
			qWarning () << Q_FUNC_INFO
					<< "unpacker exited with"
					<< ret
					<< errString
					<< "for"
					<< packageId
					<< unarch->property ("Path").toString ();

			QString errorString = tr ("Unable to unpack package archive, unpacker exited with %1: %2.")
					.arg (ret)
					.arg (errString);
			emit packageInstallError (packageId, errorString);

			return;
		}

		int oldId = -1;
		if (mode == MUpdate)
		{
			oldId = Core::Instance ().GetStorage ()->FindInstalledPackage (packageId);
			if (!CleanupBeforeUpdate (oldId, packageId))
			{
				qWarning () << Q_FUNC_INFO
						<< "unable to cleanup";
				return;
			}
		}

		QDir packageDir;
		try
		{
			packageDir = Core::Instance ().GetPackageDir (packageId);
		}
		catch (const std::exception& e)
		{
			qWarning () << Q_FUNC_INFO
					<< "while trying to get dir for package"
					<< packageId
					<< "got we exception"
					<< e.what ();
			QString errorString = tr ("Unable to get directory for the package: %1.")
					.arg (QString::fromUtf8 (e.what ()));
			emit packageInstallError (packageId, errorString);
			return;
		}

		QDirIterator dirIt (stagingDir,
				QDir::NoDotAndDotDot |
					QDir::Readable |
					QDir::NoSymLinks |
					QDir::Dirs |
					QDir::Files,
				QDirIterator::Subdirectories);
		while (dirIt.hasNext ())
		{
			dirIt.next ();
			QFileInfo fi = dirIt.fileInfo ();

			if (fi.isDir () ||
					fi.isFile ())
				if (!HandleEntry (packageId, fi, stagingDir, packageDir))
				{
					try
					{
						Remove (packageId);
					}
					catch (const std::exception& e)
					{
						qWarning () << Q_FUNC_INFO
								<< "while removing partially installed package"
								<< packageId
								<< "got:"
								<< e.what ();
					}

					QString errorString = tr ("Unable to copy "
							"files from staging area to "
							"destination directory.");
					emit packageInstallError (packageId, errorString);
					return;
				}
		}

		switch (mode)
		{
		case MInstall:
			emit packageInstalled (packageId);
			break;
		case MUpdate:
			emit packageUpdated (oldId, packageId);
			break;
		}
	}