32 #include <boost/filesystem.hpp>
34 #include <QTemporaryFile>
35 #if defined (Q_OS_WIN32) || defined (Q_OS_MAC)
36 #include <QApplication>
41 #include <QStandardPaths>
50 if (!suffix.isEmpty () && suffix.at (suffix.size () - 1) !=
'/')
53 QStringList candidates;
60 candidates << QApplication::applicationDirPath () +
"/share/" + suffix;
61 #elif defined (Q_OS_MAC) && !defined (USE_UNIX_LAYOUT)
62 candidates << QApplication::applicationDirPath () +
"/../Resources/share/" + suffix;
65 candidates << INSTALL_PREFIX
"/share/leechcraft/" + suffix;
67 candidates <<
"/usr/local/share/leechcraft/" + suffix
68 <<
"/usr/share/leechcraft/" + suffix;
73 qWarning () << Q_FUNC_INFO
74 <<
"unknown system path"
75 << static_cast<int> (path);
76 return QStringList ();
82 if (QFile::exists (cand + filename))
83 return cand + filename;
85 qWarning () << Q_FUNC_INFO
94 return QUrl::fromLocalFile (
GetSysPath (path, subfolder, filename));
99 return QString (qgetenv (
"PATH")).split (
":", QString::SkipEmptyParts);
103 const std::function<
bool (QFileInfo)>& filter)
105 for (
const auto& dir : paths)
107 const QFileInfo fi (dir +
'/' + name);
111 if (filter && !filter (fi))
114 return fi.absoluteFilePath ();
126 path = QStandardPaths::writableLocation (QStandardPaths::CacheLocation);
129 path = QDir::home ().path () +
"/.leechcraft/";
134 throw std::runtime_error (
"cannot get root path");
136 if (!path.endsWith (
'/'))
139 path +=
"leechcraft5/";
142 if (!QDir {}.exists (path) &&
143 !QDir {}.mkpath (path))
144 throw std::runtime_error (
"cannot create path " + path.toStdString ());
151 auto home = QDir::home ();
152 path.prepend (
".leechcraft/");
154 if (!home.exists (path) &&
156 throw std::runtime_error (qPrintable (QObject::tr (
"Could not create %1")
157 .arg (QDir::toNativeSeparators (home.filePath (path)))));
162 throw std::runtime_error (qPrintable (QObject::tr (
"Could not cd into %1")
163 .arg (QDir::toNativeSeparators (home.filePath (path)))));
168 QTemporaryFile file (QDir::tempPath () +
"/" + pattern);
170 QString name = file.fileName ();
178 const auto& info = boost::filesystem::space (path.toStdString ());