Esempio n. 1
0
task main()
{
	nNxtButtonTask = -2;
	nNxtExitClicks = 4;
	buildFileList();
  doDualModeFileSelection();
}
Esempio n. 2
0
void GameScannerThread::run(void)
{
    RunProlog();

    LOG(VB_GENERAL, LOG_INFO, QString("Beginning Game Scan."));

    m_files.clear();
    m_remove.clear();
    m_dbgames = RomInfo::GetAllRomInfo();

    buildFileList();
    verifyFiles();
    updateDB();

    RunEpilog();
}
Esempio n. 3
0
void GameHandler::processGames(GameHandler *handler)
{
    QString thequery;
    int maxcount = 0;
    MSqlQuery query(MSqlQuery::InitCon());

    if ((!handler->SystemRomPath().isEmpty()) && (handler->GameType() != "PC"))
    {
        QDir d(handler->SystemRomPath());
        if (d.exists())
            maxcount = buildFileCount(handler->SystemRomPath(),handler);
        else
        {
            LOG(VB_GENERAL, LOG_ERR, LOC +
                QString("ROM Path does not exist: %1")
                    .arg(handler->SystemRomPath()));
            return;
        }
    }
    else
        maxcount = 100;

    if (handler->GameType() == "PC")
    {
        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");

        QString message = QObject::tr("Scanning for %1 games...")
                                                .arg(handler->SystemName());
        MythUIBusyDialog *busyDialog = new MythUIBusyDialog(message, popupStack,
                                                "gamescanbusy");

        if (busyDialog->Create())
            popupStack->AddScreen(busyDialog, false);
        else
        {
            delete busyDialog;
            busyDialog = NULL;
        }

        m_GameMap[handler->SystemCmdLine()] =
                GameScan(handler->SystemCmdLine(),
                    handler->SystemCmdLine(),
                    inFileSystem,
                    handler->SystemName(),
                    handler->SystemCmdLine().left(handler->SystemCmdLine().lastIndexOf(QRegExp("/"))));

        if (busyDialog)
            busyDialog->Close();

        LOG(VB_GENERAL, LOG_INFO, LOC +
            QString("PC Game %1").arg(handler->SystemName()));
    }
    else
    {
        QString message = QObject::tr("Scanning for %1 games...")
                                                .arg(handler->SystemName());
        CreateProgress(message);

        if (m_progressDlg)
            m_progressDlg->SetTotal(maxcount);

        int filecount = 0;
        buildFileList(handler->SystemRomPath(), handler, &filecount);

        if (m_progressDlg)
        {
            m_progressDlg->Close();
            m_progressDlg = NULL;
        }
    }

    VerifyGameDB(handler);

    // If we still have some games in the list then update the database
    if (!m_GameMap.empty())
    {
        InitMetaDataMap(handler->GameType());

        UpdateGameDB(handler);

        romDB.clear();
        handler->setRebuild(true);
    }
    else
        handler->setRebuild(false);
}
Esempio n. 4
0
void GameHandler::buildFileList(QString directory, GameHandler *handler,
                                int* filecount)
{
    QDir RomDir(directory);

                                // If we can't read it's contents move on
    if (!RomDir.isReadable())
        return;

    RomDir.setSorting( QDir:: DirsFirst | QDir::Name );
    QFileInfoList List = RomDir.entryInfoList();
    for (QFileInfoList::const_iterator it = List.begin();
         it != List.end(); ++it)
    {
        QFileInfo Info = *it;
        QString RomName = Info.fileName();
        QString GameName = Info.completeBaseName();

        if (RomName == "." ||
            RomName == "..")
        {
            continue;
        }

        if (Info.isDir())
        {
            buildFileList(Info.filePath(), handler, filecount);
            continue;
        }
        else
        {

            if (handler->validextensions.count() > 0)
            {
                QRegExp r;

                r.setPattern("^" + Info.suffix() + "$");
                r.setCaseSensitivity(Qt::CaseInsensitive);
                QStringList result;
                for (int x = 0; x < handler->validextensions.size(); x++)
                {
                    QString extension = handler->validextensions.at(x);
                    if (extension.contains(r))
                        result.append(extension);
                }

                if (result.isEmpty())
                    continue;
            }

            m_GameMap[RomName] = GameScan(RomName,Info.filePath(),inFileSystem,
                                 GameName, Info.absoluteDir().path());

            LOG(VB_GENERAL, LOG_INFO, LOC + QString("Found ROM : (%1) - %2")
                    .arg(handler->SystemName()).arg(RomName));

            *filecount = *filecount + 1;
            if (m_progressDlg)
                m_progressDlg->SetProgress(*filecount);

        }
    }
}
Esempio n. 5
0
   "@param pattern The path and file name pattern to match against.\n"
   "@param recurse If true, the search will exhaustively recurse into subdirectories of the given path and match the given filename pattern.\n"
   "@return The path of the first file matched by the search or an empty string if no matching file could be found.\n\n"

   "@tsexample\n"
      "// Execute all .cs files in a subdirectory and its subdirectories.\n"
      "for( %file = findFirstFile( \"subdirectory/*.cs\" ); %file !$= \"\"; %file = findNextFile() )\n"
      "   exec( %file );\n"
   "@endtsexample\n\n"

   "@see findNextFile()"
   "@see getFileCount()"
   "@see findFirstFileMultiExpr()"
   "@ingroup FileSearches" )
{
   S32 numResults = buildFileList( pattern, recurse, false);

   // For Debugging
   //for ( S32 i = 0; i < sgFindFilesResults.size(); i++ )
   //   Con::printf( " [%i] [%s]", i, sgFindFilesResults[i].c_str() );

   sgFindFilesPos = 1;

   if(numResults < 0)
   {
      Con::errorf("findFirstFile() search directory not found: '%s'", pattern);
      return String();
   }

   return numResults ? sgFindFilesResults[0] : String();
}
Esempio n. 6
0
void VideoScannerThread::run()
{
    RunProlog();

    VideoMetadataListManager::metadata_list ml;
    VideoMetadataListManager::loadAllFromDatabase(ml);
    m_dbmetadata->setList(ml);

    QList<QByteArray> image_types = QImageReader::supportedImageFormats();
    QStringList imageExtensions;
    for (QList<QByteArray>::const_iterator p = image_types.begin();
         p != image_types.end(); ++p)
    {
        imageExtensions.push_back(QString(*p));
    }

    LOG(VB_GENERAL, LOG_INFO, QString("Beginning Video Scan."));

    uint counter = 0;
    FileCheckList fs_files;

    if (m_HasGUI)
        SendProgressEvent(counter, (uint)m_directories.size(),
                          tr("Searching for video files"));
    for (QStringList::const_iterator iter = m_directories.begin();
         iter != m_directories.end(); ++iter)
    {
        if (!buildFileList(*iter, imageExtensions, fs_files))
        {
            if (iter->startsWith("myth://"))
            {
                QUrl sgurl = *iter;
                QString host = sgurl.host().toLower();
                QString path = sgurl.path();

                m_liveSGHosts.removeAll(host);

                LOG(VB_GENERAL, LOG_ERR,
                    QString("Failed to scan :%1:").arg(*iter));
            }
        }
        if (m_HasGUI)
            SendProgressEvent(++counter);
    }

    PurgeList db_remove;
    verifyFiles(fs_files, db_remove);
    m_DBDataChanged = updateDB(fs_files, db_remove);

    if (m_DBDataChanged)
    {
        QCoreApplication::postEvent(m_parent,
            new VideoScanChanges(m_addList, m_movList,
                                 m_delList));

        QStringList slist;

        QList<int>::const_iterator i;
        for (i = m_addList.begin(); i != m_addList.end(); ++i)
            slist << QString("added::%1").arg(*i);
        for (i = m_movList.begin(); i != m_movList.end(); ++i)
            slist << QString("moved::%1").arg(*i);
        for (i = m_delList.begin(); i != m_delList.end(); ++i)
            slist << QString("deleted::%1").arg(*i);

        MythEvent me("VIDEO_LIST_CHANGE", slist);

        gCoreContext->SendEvent(me);
    }
    else
        gCoreContext->SendMessage("VIDEO_LIST_NO_CHANGE");

    RunEpilog();
}
Esempio n. 7
0
void UPnpMedia::BuildMediaMap(void)
{
    MSqlQuery query(MSqlQuery::InitCon());

    // For now this class only does the video stuff, but eventually other media too
    sMediaType = "VIDEO";

    if (sMediaType == "VIDEO")
    {
        QString RootVidDir = gCoreContext->GetSetting("VideoStartupDir");

        if (!RootVidDir.isEmpty())
        {

            FillMetaMaps();

            query.prepare("DELETE FROM upnpmedia WHERE class = :ITEMCLASS");
            query.bindValue(":ITEMCLASS", sMediaType);
            if (!query.exec())
            {
                MythDB::DBError("BuildMediaMap -- clearing table upnpmedia", query);
                VERBOSE(VB_IMPORTANT, LOC + "BuildMediaMap - aborting");
                return;
            }

            if (!query.exec("LOCK TABLES upnpmedia WRITE"))
                MythDB::DBError("BuildMediaMap -- lock tables", query);

            VERBOSE(VB_UPNP, LOC + QString("VideoStartupDir = %1")
                    .arg(RootVidDir));

            QStringList parts = RootVidDir.split(':', QString::SkipEmptyParts);

            int nextID = STARTING_VIDEO_OBJECTID;

            for ( QStringList::Iterator it = parts.begin(); it != parts.end();
                    ++it )
            {
                int filecount = nextID;

                VERBOSE(VB_GENERAL, LOC + QString("BuildMediaMap %1 scan "
                                                  "starting in :%2:")
                        .arg(sMediaType)
                        .arg(*it));

                nextID = buildFileList(*it,STARTING_VIDEO_OBJECTID, nextID,
                                       query);

                if (!gCoreContext->GetSetting("UPnP/RecordingsUnderVideos").isEmpty())
                {
                    VERBOSE(VB_ALL, "uPnP Unspecified error line 275, "
                            "upnpmedia.cpp");
                    //   nextID = buildRecordingList(*it,STARTING_VIDEO_OBJECTID,
                    //                                        nextID,query);
                }

                filecount = (filecount - nextID) * -1;

                VERBOSE(VB_GENERAL, LOC + QString("BuildMediaMap Done. Found "
                                                  "%1 objects").arg(filecount));

            }

            if (!query.exec("UNLOCK TABLES"))
                MythDB::DBError("BuildMediaMap -- unlock tables", query);

        }
        else
        {
            VERBOSE(VB_GENERAL, LOC + "BuildMediaMap - no VideoStartupDir set, "
                    " skipping scan.");
        }

    }
    else
    {
        VERBOSE(VB_GENERAL, LOC + QString("BuildMediaMap UNKNOWN MediaType %1 "
                                          ", skipping scan.").arg(sMediaType));
    }

}
Esempio n. 8
0
int UPnpMedia::buildFileList(QString directory, int rootID, int itemID, MSqlQuery &query)
{

    int parentid;
    QDir vidDir(directory);
    //VERBOSE(VB_UPNP, QString("buildFileList = %1, rootID = %2, itemID =
    //%3").arg(directory).arg(rootID).arg(itemID));

    if (rootID > 0)
        parentid = rootID;
    else
        parentid = itemID;

    vidDir.setSorting( QDir::DirsFirst | QDir::Name );
    QFileInfoList List = vidDir.entryInfoList();
    // If we can't read it's contents move on
    if (List.isEmpty())
        return itemID;

    for (QFileInfoList::iterator it = List.begin(); it != List.end(); ++it)
    {
        QFileInfo Info(*it);
        QString fName = Info.fileName();
        QString fPath = Info.filePath();

        // We don't want . or .. or something that specifically globs to
        // either.  The "??" and "?" cases can happen when the backend is
        // running in a non-UTF-8 locale and comes across a UTF-8 filename
        if (fName == "."  || fName == ".." || fName == "?" || fName == "??" ||
                fName == ".?" || fName == "?.")
            continue;

        if (Info.isDir())
        {
            // If we are about to recurse into the current directory (which
            // will cause an infinite recursive loop!), skip this entry.
            QDir subDir(fPath);
            if( subDir.canonicalPath() == vidDir.canonicalPath() )
                continue;

            itemID++;

            query.prepare("INSERT INTO upnpmedia "
                          "(intid, class, itemtype, parentid, itemproperties, "
                          "filepath, filename, title, coverart) "
                          "VALUES (:ITEMID, :ITEMCLASS, 'FOLDER', :PARENTID, '', "
                          ":FILEPATH, :FILENAME, :TITLE, :COVERART)");

            query.bindValue(":ITEMCLASS", sMediaType);
            query.bindValue(":ITEMID", itemID);
            query.bindValue(":PARENTID", parentid);
            query.bindValue(":FILEPATH", fPath);
            query.bindValue(":FILENAME", fName);

            query.bindValue(":TITLE", GetTitleName(fPath,fName));
            query.bindValue(":COVERART", GetCoverArt(fPath));

            if (!query.exec())
                MythDB::DBError("UPnpMedia::buildFileList", query);

            itemID = buildFileList(fPath, 0, itemID, query);
            continue;

        }
        else
        {
            /*
                        if (handler->validextensions.count() > 0)
                        {
                            QRegExp r;

                            r.setPattern("^" + Info.suffix() + "$");
                            r.setCaseSensitive(false);
                            QStringList result = handler->validextensions.grep(r);
                            if (result.isEmpty()) {
                                continue;
                            }
                        }
            */

            itemID++;

//            VERBOSE(VB_UPNP, QString("UPnpMedia Video File : (%1) (%2)")
//                      .arg(itemID)
//                                .arg(fName));

            query.prepare("INSERT INTO upnpmedia "
                          "(intid, class, itemtype, parentid, itemproperties, "
                          "filepath, filename, title, coverart) "
                          "VALUES (:ITEMID, :ITEMCLASS, 'FILE', :PARENTID, '', "
                          ":FILEPATH, :FILENAME, :TITLE, :COVERART)");

            query.bindValue(":ITEMCLASS", sMediaType);
            query.bindValue(":ITEMID", itemID);
            query.bindValue(":PARENTID", parentid);
            query.bindValue(":FILEPATH", fPath);
            query.bindValue(":FILENAME", fName);

            query.bindValue(":TITLE", GetTitleName(fPath,fName));
            query.bindValue(":COVERART", GetCoverArt(fPath));

            if (!query.exec())
                MythDB::DBError("UPnpMedia::buildFileList", query);

        }
    }

    return itemID;
}
Esempio n. 9
0
/*
 *  Paste files to destination
 */
void Worker::pasteFiles(bool cut)
{
    buildFileList();

    QList<QString> directoryList;

    QDir sourceDir(m_clipboardDir);

    QTime startTime = QTime::currentTime();

    emit progressTextChanged(QString("Copying files..."));

    // Create a list of directories to be created
    for (int i=0; i < m_directoryList.count(); i++)
    {
        QString sourcePath = m_directoryList.at(i);
        QString newDirPath = QString("%1/%2").arg(m_destination, sourceDir.relativeFilePath(sourcePath));

        qDebug() << sourcePath.toLatin1() << " > " << newDirPath.toLatin1();

        directoryList.append(newDirPath);
    }

    emit progressTextChanged("Creating directories...");

    qDebug() << "FILES";

    // Create a list of files to be copied
    for (int i=0; i < m_fileList.count(); i++)
    {
        QString sourcePath = m_fileList.at(i);
        QString newFilePath = QString("%1/%2").arg(m_destination, sourceDir.relativeFilePath(sourcePath));

        qDebug() << sourcePath.toLatin1() << " > " << newFilePath.toLatin1();

        m_fileMap.insert(sourcePath, newFilePath);
    }

    // First, create the directories
    for (int i = 0; i < directoryList.count(); i++)
    {
        QString newDir = directoryList.at(i);

        QDir dir(newDir);

        // If the directory already exists, skip it
        if (dir.exists())
            continue;

        bool success = dir.mkdir(newDir);

        if (!success)
            directoryErrorMap.insert(newDir, DirCreateError);
    }

    // If any of the directories couldn't be created, abort the process
    if (directoryErrorMap.count() > 0)
    {
        emit progressTextChanged("Directories couldn't be created.");
        emit fileOperationFinished();

        // Abort the process
        quit();
    }

    // Now, copy the files
    int fileCount = 0;
    QMapIterator<QString, QString> i(m_fileMap);
    while (i.hasNext())
    {
        i.next();
        fileCount++;
        QString sourceFilePath = i.key();
        QString newFilePath = i.value();

        QFile sourceFile(sourceFilePath);

        // Report the progress, but only every 50 milliseconds to prevent the UI thread
        // from being flooded with signals
        if (QTime::currentTime().msecsTo(startTime) <= -50)
        {
            startTime = QTime::currentTime();

            emit progressTextChanged(QString("Copying files (%1 of %2)...").arg(QString("%1").arg(fileCount),
                                                                                 QString("%1").arg(m_fileMap.count())));
            emit currentEntryChanged(sourceFile.fileName());

            double progress = (double)(fileCount) / (double)m_fileMap.count();
            emit progressValueChanged(progress);
        }

        // Copy the file
        bool success = sourceFile.copy(sourceFilePath, newFilePath);

        if (!success)
            fileErrorMap.insert(newFilePath, sourceFile.error());
    }

    // If we don't have to cut files we are done
    if (!cut)
    {
        if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0)
            emit progressTextChanged("All files were copied successfully.");
        else
            emit progressTextChanged("All files couldn't be copied successfully.");

        emit fileOperationFinished();

        // Done, time to self-destruct
        quit();
    }
    else
    {
        fileCount = 0;

        if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0)
        {
            // We copied all files successfully, so delete the old ones now
            i.toFront();
            while (i.hasNext())
            {
                i.next();
                fileCount++;
                QString sourceFilePath = i.key();

                QFile sourceFile(sourceFilePath);

                // Report the progress, but only every 50 milliseconds to prevent the UI thread
                // from being flooded with signals
                if (QTime::currentTime().msecsTo(startTime) <= -50)
                {
                    startTime = QTime::currentTime();

                    emit progressTextChanged(QString("Deleting old files (%1 of %2)...").arg(QString("%1").arg(fileCount),
                                                                                         QString("%1").arg(m_fileMap.count())));
                    emit currentEntryChanged(sourceFile.fileName());

                    double progress = (double)(fileCount) / (double)m_fileMap.count();
                    emit progressValueChanged(progress);
                }

                // Delete the file
                bool success = sourceFile.remove();

                if (!success)
                    fileErrorMap.insert(sourceFilePath, sourceFile.error());
            }

            emit progressTextChanged(QString("Deleting old directories..."));
            emit progressValueChanged(-1);

            // Then delete the directories
            for (int i=m_directoryList.count()-1; i >= 0; i--)
            {
                QString sourcePath = m_directoryList.at(i);

                QDir dir(sourcePath);

                // If it doesn't exist, it was most likely removed earlier
                if (!dir.exists())
                    continue;

                bool success = dir.rmdir(sourcePath);

                if (!success)
                    directoryErrorMap.insert(sourcePath, DirDeleteError);
            }

            // Check if files were copied and deleted successfully
            if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0)
                emit progressTextChanged("All of the files were cut and pasted successfully.");
            else
                emit progressTextChanged("All of the files couldn't be cut and pasted successfully.");

            emit fileOperationFinished();

            // Done, time to self-destruct
            quit();
        }
        else
        {
            // All files couldn't be copied, so delete the new copied files to revert the process
            i.toFront();
            while (i.hasNext())
            {
                i.next();
                fileCount++;
                QString newFilePath = i.value();

                QFile newFile(newFilePath);

                // Report the progress, but only every 50 milliseconds to prevent the UI thread
                // from being flooded with signals
                if (QTime::currentTime().msecsTo(startTime) <= -50)
                {
                    startTime = QTime::currentTime();

                    emit progressTextChanged(QString("Failed to copy all files, deleting copied files (%1 of %2)...").arg(QString("%1").arg(fileCount),
                                                                                         QString("%1").arg(m_fileMap.count())));
                    emit currentEntryChanged(newFile.fileName());

                    double progress = (double)(fileCount) / (double)m_fileMap.count();
                    emit progressValueChanged(progress);
                }

                // Delete the file
                newFile.remove();
            }

            emit progressTextChanged(QString("Failed to copy all files, deleting created directories..."));
            emit progressValueChanged(-1);

            // Delete the directories
            for (int i=directoryList.count()-1; i >= 0; i--)
            {
                QString newDir = directoryList.at(i);

                QDir dir(newDir);

                // If the directory already exists, skip it
                if (dir.exists())
                    continue;

                bool success = dir.rmdir(newDir);

                if (!success)
                    directoryErrorMap.insert(newDir, DirDeleteError);
            }

            emit progressTextChanged("All files couldn't be copied successfully.");

            emit fileOperationFinished();
        }
    }
}
Esempio n. 10
0
/*
 *  Delete files in the clipboard
 */
void Worker::deleteFiles()
{
    buildFileList();

    emit progressTextChanged(QString("Deleting files..."));

    QTime startTime = QTime::currentTime();

    // Start deleting files
    for (int i=0; i < m_fileList.count(); i++)
    {
        QString fullPath = m_fileList.at(i);

        QFile file(fullPath);

        // Report the progress
        if (QTime::currentTime().msecsTo(startTime) <= -50)
        {
            startTime = QTime::currentTime();
            emit progressTextChanged(QString("Deleting files (%1 of %2)...").arg(QString("%1").arg(i+1),
                                                                                 QString("%1").arg(m_fileList.count())));
            emit currentEntryChanged(file.fileName());

            double progress = (double)(i + 1) / (double)m_fileList.count();
            emit progressValueChanged(progress);
        }

        file.open(QIODevice::WriteOnly);

        // Remove the file
        bool success = file.remove();

        if (!success)
            fileErrorMap.insert(fullPath, file.error());
    }

    // And then delete directories
    // Reverse order so that the subdirectories are deleted first
    for (int i=m_directoryList.count()-1; i >= 0; i--)
    {
        QString fullPath = m_directoryList.at(i);

        QDir dir(fullPath);

        // If it doesn't exist, it was most likely removed earlier
        if (!dir.exists())
            continue;

        bool success = dir.rmdir(fullPath);

        if (!success)
            directoryErrorMap.insert(fullPath, DirDeleteError);

        if (QTime::currentTime().msecsTo(startTime) <= -50)
        {
            startTime = QTime::currentTime();
            emit progressTextChanged(QString("Deleting directories..."));
            emit currentEntryChanged(dir.dirName());
            emit progressValueChanged(-1);
        }
    }

    // We are done
    if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0)
        emit progressTextChanged("All files were deleted successfully.");
    else
        emit progressTextChanged("All files couldn't be deleted successfully.");

    emit fileOperationFinished();

    // Done, time to self-destruct
    quit();
}