13 #include <QTemporaryFile>
14 #if defined (Q_OS_WIN32) || defined (Q_OS_MAC)
15 #include <QApplication>
20 #include <QStandardPaths>
26 if (!suffix.isEmpty () && suffix.at (suffix.size () - 1) !=
'/')
35 return { QApplication::applicationDirPath () +
"/share/" + suffix };
36 #elif defined (Q_OS_MAC) && !defined (USE_UNIX_LAYOUT)
37 return { QApplication::applicationDirPath () +
"/../Resources/share/" + suffix };
40 return { INSTALL_PREFIX
"/share/leechcraft/" + suffix };
44 "/usr/local/share/leechcraft/" + suffix,
45 "/usr/share/leechcraft/" + suffix
50 qWarning () << Q_FUNC_INFO
51 <<
"unknown system path"
52 <<
static_cast<int> (path);
59 if (QFile::exists (cand + filename))
60 return cand + filename;
62 qWarning () << Q_FUNC_INFO
71 return QUrl::fromLocalFile (
GetSysPath (path, subfolder, filename));
76 return QString (qgetenv (
"PATH")).split (
':', Qt::SkipEmptyParts);
80 const std::function<
bool (QFileInfo)>& filter)
82 for (
const auto& dir : paths)
84 const QFileInfo fi (dir +
'/' + name);
88 if (filter && !filter (fi))
91 return fi.absoluteFilePath ();
103 path = QStandardPaths::writableLocation (QStandardPaths::CacheLocation);
106 path = QDir::home ().path () +
"/.leechcraft/";
111 throw std::runtime_error (
"cannot get root path");
113 if (!path.endsWith (
'/'))
116 path += QLatin1String (
"leechcraft5/");
119 if (!QDir {}.exists (path) &&
120 !QDir {}.mkpath (path))
121 throw std::runtime_error (
"cannot create path " + path.toStdString ());
128 auto home = QDir::home ();
129 path.prepend (
".leechcraft/");
131 if (!home.exists (path) &&
133 throw std::runtime_error (qPrintable (QObject::tr (
"Could not create %1")
134 .arg (QDir::toNativeSeparators (home.filePath (path)))));
137 throw std::runtime_error (qPrintable (QObject::tr (
"Could not cd into %1")
138 .arg (QDir::toNativeSeparators (home.filePath (path)))));
145 static const auto defaultPattern = QStringLiteral (
"lc_temp.XXXXXX");
146 QTemporaryFile file (QDir::tempPath () +
'/' + (pattern.isEmpty () ? defaultPattern : pattern));
148 QString name = file.fileName ();
156 const auto& info = std::filesystem::space (path.toStdString ());
159 .Capacity_ = info.capacity,
161 .Available_ = info.available