/** \file ResourcesManager.cpp \brief Define the class to manage and load the resources linked with the themes \author alpha_one_x86 \licence GPL3, see the file COPYING */ #include #include #include #include #include "cpp11addition.h" #include "ResourcesManager.h" #include "FacilityEngine.h" std::regex ResourcesManager::slashEnd; /// \brief Create the manager and load the defaults variables ResourcesManager::ResourcesManager() { slashEnd=std::regex("[/\\\\]$"); //load the internal path searchPath.push_back(":/"); #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE //load the user path but only if exists and writable //load the ultracopier path #ifdef ULTRACOPIER_VERSION_PORTABLE #ifdef ULTRACOPIER_VERSION_PORTABLEAPPS ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,"Ultracopier is compiled with the flag: ULTRACOPIER_VERSION_PORTABLEAPPS"); //load the data folder path QDir dir(QApplication::applicationDirPath()); dir.cdUp(); dir.cdUp(); dir.cd(QStringLiteral("Data"); searchPath.push_back(ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString())); writablePath=ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString()); #else ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,"Ultracopier is compiled with the flag: ULTRACOPIER_VERSION_PORTABLE"); //load the ultracopier path QDir dir(QApplication::applicationDirPath()); dir.cd(QStringLiteral("Data")); searchPath.push_back(ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString())); writablePath=ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString()); #endif #else ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,"Ultracopier is compiled as user privacy mode"); #ifdef Q_OS_WIN32 #define EXTRA_HOME_PATH QStringLiteral("\\ultracopier\\") #else #define EXTRA_HOME_PATH QStringLiteral("/.config/Ultracopier/") #endif #ifdef Q_OS_LINUX QDir linuxArchIndepDir(QStringLiteral("/usr/share/ultracopier/")); if(linuxArchIndepDir.exists()) searchPath.push_back(ResourcesManager::AddSlashIfNeeded(linuxArchIndepDir.absolutePath().toStdString())); QDir linuxPluginsDir(QStringLiteral("/usr/lib/ultracopier/")); if(linuxPluginsDir.exists()) searchPath.push_back(ResourcesManager::AddSlashIfNeeded(linuxPluginsDir.absolutePath().toStdString())); #endif //load the user path but only if exists and writable QDir dir(QDir::homePath()+EXTRA_HOME_PATH); if(dir.exists()) { writablePath=ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString()); searchPath.push_back(ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString())); } //if not exists try to create it else if(dir.mkpath(dir.absolutePath())) { //if created, then have write permissions writablePath=ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString()); searchPath.push_back(ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString())); } //load the ultracopier path searchPath.push_back(ResourcesManager::AddSlashIfNeeded(QApplication::applicationDirPath().toStdString())); #endif #else QDir dir(QApplication::applicationDirPath()); writablePath=ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString()); #endif vectorRemoveDuplicatesForSmallList(searchPath); #ifdef ULTRACOPIER_DEBUG unsigned int index=0; while(index &fileToCheck) const { unsigned int index=0; while(index &fileToCheck) const { QDir dir(QString::fromStdString(path)); if(dir.exists()) // if the path have been found, then return the full path { bool allFileToCheckIsFound=true; unsigned int index=0; std::string partialPath=ResourcesManager::AddSlashIfNeeded(dir.absolutePath().toStdString()); while(index &ResourcesManager::getReadPath() const { return searchPath; } /// \brief remove folder bool ResourcesManager::removeFolder(const std::string &dir) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"folder to remove: "+dir); bool errorFound=false; QDir currentDir(QString::fromStdString(dir)); QFileInfoList files = currentDir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); int index=0; const int &loop_size=files.size(); while(index