Ticket #6271: 19997.vidsg.patch

File 19997.vidsg.patch, 4.2 KB (added by gnassas@…, 17 years ago)
  • mythvideo/mythvideo/dbcheck.cpp

     
    11#include <QString>
    22#include <QRegExp>
    33#include <QStringList>
     4#include <QDir>
    45
    56#include <mythtv/mythcontext.h>
    67#include <mythtv/mythdb.h>
    78#include <mythtv/mythdbcon.h>
    89#include <mythtv/mythdbparams.h>
     10#include <mythtv/libmyth/storagegroup.h>
    911
    1012#include "videodlg.h"
    1113#include "dbcheck.h"
     
    3840    const QString lastMythDVDDBVersion = "1002";
    3941    const QString lastMythVideoVersion = "1010";
    4042
    41     const QString currentDatabaseVersion = "1022";
     43    const QString currentDatabaseVersion = "1023";
    4244
    4345    const QString OldMythVideoVersionName = "VideoDBSchemaVer";
    4446    const QString OldMythDVDVersionName = "DVDDBSchemaVer";
     
    825827             performActualUpdate(updates, "1022", dbver, MythVideoVersionName);
    826828         }
    827829
     830        if (dbver == "1022")
     831        {
     832            // 1023 rearranges video filenames from prefixes &
     833            // absolute paths to relative paths within storage
     834            // groups.
     835
     836            MSqlQuery loop(MSqlQuery::InitCon());
     837            if (!loop.exec("SELECT data, hostname FROM settings "
     838                           "WHERE value='VideoStartupDir'"))
     839            {
     840                MythDB::DBError(QObject::tr("Error: Unable to retrieve "
     841                                            "VideoStartupDirs"), loop);
     842            } else {
     843
     844                // Part 1 - create storage group entries based on the
     845                // values of VideoStartupDir for each host. N.B. DB
     846                // updates are done within the StorageGroup class
     847
     848                // arrange prefixes by size so we can remove them in
     849                // order of decreasing length to avoid problems with
     850                // short paths being substrings of longer ones
     851                QMap<int, QString> prefixes;
     852
     853                while (loop.next())
     854                {
     855                    QString hostname = loop.value(1).toString();
     856                    QStringList dirs = loop.value(0).toString().split(":", QString::SkipEmptyParts);
     857
     858                    StorageGroup sg("Videos", hostname, false);
     859
     860                    for (int i = 0; i < dirs.size(); i++)
     861                    {
     862                        QString videoDir = QDir::cleanPath(dirs[i]);
     863                        sg.AddDir(videoDir);
     864
     865                        if (videoDir.right(1) != "/")
     866                            videoDir += "/";
     867                        prefixes[-videoDir.length()] = videoDir;
     868                    }
     869
     870                    sg.Save();
     871                }
     872
     873                // Part 2 - remove prefixes from video filenames
     874
     875                QStringList updates;
     876
     877                foreach (QString dir, prefixes)
     878                {
     879                    QString sql = QString("UPDATE videometadata "
     880                                          "SET filename = SUBSTR(filename,%1) "
     881                                          "WHERE LEFT(filename,%2) = '%3'")
     882                        .arg(dir.length()+1).arg(dir.length()).arg(dir);
     883                    updates += sql;
     884                }
     885
     886                performActualUpdate(updates, "1023", dbver, MythVideoVersionName);
     887            }
     888        }
    828889    }
    829890}
    830891
  • mythvideo/mythvideo/playercommand.cpp

     
    44
    55#include <mythtv/libmythui/mythmainwindow.h>
    66#include <mythtv/libmythui/mythsystem.h>
     7#include <mythtv/libmyth/storagegroup.h>
    78
    89#include "dbaccess.h"
    910#include "metadata.h"
     
    9394
    9495    bool Play() const
    9596    {
    96         return gContext->GetMainWindow()->HandleMedia(m_handler, m_mrl,
     97        StorageGroup videos("Videos");
     98        QString fullName = videos.FindRecordingFile(m_mrl);
     99        return gContext->GetMainWindow()->HandleMedia(m_handler,
     100                fullName.length() > 0 ? fullName : m_mrl,
    97101                m_plot, m_title, m_director, m_length, m_year);
    98102    }
    99103