| | 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 | } |