14 #include <QApplication> 27 bool DataLocations::mTestMode =
false;
28 bool DataLocations::mRunFromBuildFolder =
false;
29 bool DataLocations::mBuildFolderChecked =
false;
30 QString DataLocations::mWebsiteUrl =
"";
43 QString dataRootConfigFile = settingsPath +
"/data_root_location.txt";
44 if (QFileInfo(dataRootConfigFile).exists())
46 return readTestDataPathFromFile(dataRootConfigFile);
57 QString dataRootConfigFile = settingsPath +
"/large_data_root_location.txt";
58 if (QFileInfo(dataRootConfigFile).exists())
60 return readTestDataPathFromFile(dataRootConfigFile);
64 return CX_LARGE_DATA_ROOT;
72 path = QString(
"%1/%2/%3").arg(
getTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
73 if (QFileInfo(path).exists())
76 path = QString(
"%1/%2/%3").arg(
getLargeTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
77 if (QFileInfo(path).exists())
83 QString DataLocations::readTestDataPathFromFile(QString filename)
86 file.open(QFile::ReadOnly);
87 QString cxDataRoot(file.readAll());
93 QString homepath = QDir::homePath() +
"/" + CX_SYSTEM_BASE_NAME +
"_settings";
96 homepath = homepath +
"/temp";
104 QDir dir(pathToDelete);
105 CX_LOG_INFO() <<
"Going to delete:" << dir.absolutePath();
106 dir.removeRecursively();
119 QString path(qApp->applicationDirPath()+
"/../../..");
120 QString bundle = QDir(qApp->applicationDirPath()+
"/../..").canonicalPath();
121 if (QFileInfo(bundle).isBundle())
122 return QDir(path).canonicalPath();
124 return qApp->applicationDirPath();
126 QString path(qApp->applicationDirPath());
137 QString appPath(qApp->applicationDirPath());
139 QString installLocation = appPath;
141 installLocation = appPath +
"/plugins";
143 if (QFile(installLocation).exists())
144 retval << installLocation;
146 QString fallbackInstallLocation = appPath;
147 if (QFile(fallbackInstallLocation).exists())
148 retval << fallbackInstallLocation; }
153 QString buildLocation = bundlePath;
155 buildLocation = bundlePath +
"/plugins";
157 if (QFile(buildLocation).exists())
158 retval << buildLocation;
179 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_CONFIG_ROOT_RELATIVE_INSTALLED);
180 if (QDir(path).exists())
181 return QStringList() << QDir(path).canonicalPath();
184 std::cout <<
"DataLocations::getRootConfigPaths(): Cannot find config root path: " << path << std::endl;
185 return QStringList();
192 if (QDir(CX_OPTIONAL_CONFIG_ROOT).exists())
193 retval << QDir(CX_OPTIONAL_CONFIG_ROOT).canonicalPath();
194 if (QDir(CX_CONFIG_ROOT).exists())
195 retval << QDir(CX_CONFIG_ROOT).canonicalPath();
204 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_DOC_ROOT_RELATIVE_INSTALLED);
206 if (QDir(path).exists())
207 return QDir(path).canonicalPath();
210 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << path;
215 if (QDir(CX_DOC_ROOT).exists())
216 return QDir(CX_DOC_ROOT).canonicalPath();
219 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << CX_DOC_ROOT;
227 for (
int i=0; i<root.size(); ++i)
228 retval << root[i] + suffix;
236 QStringList splitName = name.split(
".");
237 splitName[splitName.size()-1] = ext;
238 return splitName.join(
".");
250 return findConfigPath(
"", pathRelativeToConfigRoot, alternativeAbsolutePath);
255 QFileInfo filePath(
findConfigFilePath(fileName, pathRelativeToConfigRoot, alternativeAbsolutePath));
256 return filePath.absolutePath() +
"/";
264 QString path = root +
"/" + pathRelativeToConfigRoot +
"/" + fileName;
266 if (QFileInfo(path).exists())
270 QString path = QString(alternativeAbsolutePath +
"/" + fileName);
272 if (QFileInfo(path).exists())
275 reportWarning(
"DataLocations::findConfigFile. Error: Can't find " + fileName +
" in any of\n" + paths.join(
" \n"));
279 QString DataLocations::checkExecutableExist(QString path, QString filename)
282 path = QDir::cleanPath(path);
283 if (QDir(path).exists(filename))
298 result = DataLocations::checkExecutableExist(qApp->applicationDirPath(), filename);
299 if (!result.isEmpty())
307 mWebsiteUrl = websiteUrl;
317 return QString(
"http://custusx.org/uploads");
322 QString version(CustusX_VERSION_STRING);
323 if (version.contains(
"dev"))
325 QString url = QString(
"%1/user_doc/%2")
333 if(!mBuildFolderChecked)
338 QString pathToConfigFile = bundlePath +
"/../source/resource/core/settings/cxConfig.h";
339 if (QFile(pathToConfigFile).exists())
341 std::cout <<
"Using paths from build folder" << std::endl;
342 mRunFromBuildFolder =
true;
345 mRunFromBuildFolder =
false;
346 mBuildFolderChecked =
true;
349 return mRunFromBuildFolder;
static QString getExistingTestData(QString pathRelativeToTestDataRoot, QString filename="")
Return full path to test data, both normal and large repositories are searched.
bool removeNonemptyDirRecursively(const QString &dirName)
static QString findConfigPath(QString fileName, QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
static bool isRunFromBuildFolder()
static QString getWebsiteUserDocumentationURL()
static QString getLargeTestDataPath()
return path to test data folder containing large data sets
static QStringList getRootConfigPaths()
static void setWebsiteURL(QString websiteUrl)
static QString findConfigFolder(QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
void reportWarning(QString msg)
static QString getCachePath()
return path to a folder that is used during execution, will be cleared at start and stop...
static QString getWebsiteURL()
static QString findConfigFilePath(QString fileName, QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
static QString getTestDataPath()
return path to test data folder
static QString getPersistentWritablePath()
Path to location usable for persistent and temporary storage of config. Do not use directly...
static QStringList getDefaultPluginsPath()
return the folder where plugins should be located, by default.
static QString getRootConfigPath()
return path to root config folder. May be replaced with getExistingConfigPath()
QString changeExtension(QString name, QString ext)
static QString findExecutableInStandardLocations(QString filename)
look for an exe in the same folder as the executable or bundle.
static QStringList appendStringToAllElements(QStringList root, QString suffix)
static void setTestMode()
set a testing mode that changes location of settings files to a temp folder.
static void deletePersistentWritablePath()
Deletes the folder called *_settings.
static QString getDocPath()
return path to folder containing documentation files
static QString getBundlePath()
return the folder where the bundle or executable are located.
static QString getUploadsUrl()
Namespace for all CustusX production code.