Esempio n. 1
0
void allTests()
	{
	int err=chdir("C:\\");
	test(err==0);

	make_tree();
	create_files();
	renaming();
	directory();
	attributes();
	searching();
	deletion();
	temporary_files();

	if (close_console)
		{
		test_Close();
		close(0);
		close(1);
		close(2);

		CloseSTDLIB();
		}
	}
bool ModelBackendOneFile::booksToLoad( const QString& path, QStringList& booksPaths )
{
    QDir dir(path);
    if(!dir.exists())
        return false;

    dir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Files | QDir::Readable);
    dir.setSorting(QDir::DirsFirst | QDir::Name);

    QStringList sub_list;
    QStringList list = dir.entryList();

    QStringList::const_iterator i = list.begin();
    QStringList::const_iterator itEnd = list.end();

    QFileInfo fi;
    while(i != itEnd)
    {
        QString file_path = dir.filePath(*i);
        fi.setFile(file_path);

        if(!fi.exists())
            return false;

        const QString& name = fi.fileName();

        if (!name.startsWith(".") && fi.isDir()) {
            sub_list += file_path;
            ++i;
            continue;
        }

        if (name.startsWith(".") || !BookInfo::isBook(file_path)) {
            ++i;
            continue;
        }

        // Handle problematic characters
        if(name.contains("+"))
        {
            // Rename the file
            QFile renaming(file_path);
            if(renaming.exists())
            {
                QString newFilePath(file_path);
                newFilePath.replace("+", "");
                qDebug() << Q_FUNC_INFO << "Renaming: " << file_path << " to " << newFilePath;
                if(renaming.rename(newFilePath))
                {
                    fi.setFile(renaming);
                    file_path = fi.absoluteFilePath();
                }
                else
                    return false;
            }
            else
                return false;
        }

        booksPaths.append(file_path);

        ++i;
    }

    QStringList::const_iterator j = sub_list.begin();
    while(j != sub_list.end())
    {
        if(!booksToLoad(*j, booksPaths))
            return false;
        ++j;
    }

    return true;
}