35 #include <QApplication>
48 bool DataLocations::mTestMode =
false;
49 bool DataLocations::mRunFromBuildFolder =
false;
50 bool DataLocations::mBuildFolderChecked =
false;
51 QString DataLocations::mWebsiteUrl =
"";
63 QString dataRootConfigFile = settingsPath +
"/data_root_location.txt";
64 if (QFileInfo(dataRootConfigFile).exists())
66 return readTestDataPathFromFile(dataRootConfigFile);
77 QString dataRootConfigFile = settingsPath +
"/large_data_root_location.txt";
78 if (QFileInfo(dataRootConfigFile).exists())
80 return readTestDataPathFromFile(dataRootConfigFile);
84 return CX_LARGE_DATA_ROOT;
92 path = QString(
"%1/%2/%3").arg(
getTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
93 if (QFileInfo(path).exists())
96 path = QString(
"%1/%2/%3").arg(
getLargeTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
97 if (QFileInfo(path).exists())
103 QString DataLocations::readTestDataPathFromFile(QString filename)
105 QFile file(filename);
106 file.open(QFile::ReadOnly);
107 QString cxDataRoot(file.readAll());
113 QString homepath = QDir::homePath() +
"/" + CX_SYSTEM_BASE_NAME +
"_settings";
124 QDir dir(pathToDelete);
125 CX_LOG_INFO() <<
"Going to delete:" << dir.absolutePath();
126 dir.removeRecursively();
139 QString path(qApp->applicationDirPath()+
"/../../..");
140 QString bundle = QDir(qApp->applicationDirPath()+
"/../..").canonicalPath();
141 if (QFileInfo(bundle).isBundle())
142 return QDir(path).canonicalPath();
144 return qApp->applicationDirPath();
146 QString path(qApp->applicationDirPath());
157 QString appPath(qApp->applicationDirPath());
159 QString installLocation = appPath;
161 installLocation = appPath +
"/plugins";
163 if (QFile(installLocation).exists())
164 retval << installLocation;
166 QString fallbackInstallLocation = appPath;
167 if (QFile(fallbackInstallLocation).exists())
168 retval << fallbackInstallLocation; }
173 QString buildLocation = bundlePath;
175 buildLocation = bundlePath +
"/plugins";
177 if (QFile(buildLocation).exists())
178 retval << buildLocation;
189 return paths.front();
197 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_CONFIG_ROOT_RELATIVE_INSTALLED);
198 if (QDir(path).exists())
199 return QStringList() << QDir(path).canonicalPath();
202 std::cout <<
"DataLocations::getRootConfigPaths(): Cannot find config root path: " << path << std::endl;
203 return QStringList();
208 if (QDir(CX_CONFIG_ROOT).exists())
209 retval << QDir(CX_CONFIG_ROOT).canonicalPath();
210 if (QDir(CX_OPTIONAL_CONFIG_ROOT).exists())
211 retval << QDir(CX_OPTIONAL_CONFIG_ROOT).canonicalPath();
220 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_DOC_ROOT_RELATIVE_INSTALLED);
222 if (QDir(path).exists())
223 return QDir(path).canonicalPath();
226 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << path;
231 if (QDir(CX_DOC_ROOT).exists())
232 return QDir(CX_DOC_ROOT).canonicalPath();
235 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << CX_DOC_ROOT;
243 for (
int i=0; i<root.size(); ++i)
244 retval << root[i] + suffix;
252 QStringList splitName = name.split(
".");
253 splitName[splitName.size()-1] = ext;
254 return splitName.join(
".");
266 return findConfigPath(
"", pathRelativeToConfigRoot, alternativeAbsolutePath);
271 QFileInfo filePath(
findConfigFilePath(fileName, pathRelativeToConfigRoot, alternativeAbsolutePath));
272 return filePath.absolutePath() +
"/";
280 QString path = root +
"/" + pathRelativeToConfigRoot +
"/" + fileName;
282 if (QFileInfo(path).exists())
286 QString path = QString(alternativeAbsolutePath +
"/" + fileName);
288 if (QFileInfo(path).exists())
291 reportWarning(
"DataLocations::findConfigFile. Error: Can't find " + fileName +
" in any of\n" + paths.join(
" \n"));
295 QString DataLocations::checkExecutableExist(QString path, QString filename)
298 path = QDir::cleanPath(path);
299 if (QDir(path).exists(filename))
314 result = DataLocations::checkExecutableExist(qApp->applicationDirPath(), filename);
315 if (!result.isEmpty())
323 mWebsiteUrl = websiteUrl;
333 return QString(
"http://custusx.org/uploads");
338 QString version(CustusX_VERSION_STRING);
339 if (version.contains(
"dev"))
341 QString url = QString(
"%1/user_doc/%2")
349 if(!mBuildFolderChecked)
354 QString pathToConfigFile = bundlePath +
"/../source/resource/core/settings/cxConfig.h";
355 if (QFile(pathToConfigFile).exists())
357 std::cout <<
"Using paths from build folder" << std::endl;
358 mRunFromBuildFolder =
true;
361 mRunFromBuildFolder =
false;
362 mBuildFolderChecked =
true;
365 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()