35 #include <QApplication> 48 bool DataLocations::mTestMode =
false;
49 bool DataLocations::mRunFromBuildFolder =
false;
50 bool DataLocations::mBuildFolderChecked =
false;
51 QString DataLocations::mWebsiteUrl =
"";
64 QString dataRootConfigFile = settingsPath +
"/data_root_location.txt";
65 if (QFileInfo(dataRootConfigFile).exists())
67 return readTestDataPathFromFile(dataRootConfigFile);
78 QString dataRootConfigFile = settingsPath +
"/large_data_root_location.txt";
79 if (QFileInfo(dataRootConfigFile).exists())
81 return readTestDataPathFromFile(dataRootConfigFile);
85 return CX_LARGE_DATA_ROOT;
93 path = QString(
"%1/%2/%3").arg(
getTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
94 if (QFileInfo(path).exists())
97 path = QString(
"%1/%2/%3").arg(
getLargeTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
98 if (QFileInfo(path).exists())
104 QString DataLocations::readTestDataPathFromFile(QString filename)
106 QFile file(filename);
107 file.open(QFile::ReadOnly);
108 QString cxDataRoot(file.readAll());
114 QString homepath = QDir::homePath() +
"/" + CX_SYSTEM_BASE_NAME +
"_settings";
117 homepath = homepath +
"/temp";
125 QDir dir(pathToDelete);
126 CX_LOG_INFO() <<
"Going to delete:" << dir.absolutePath();
127 dir.removeRecursively();
140 QString path(qApp->applicationDirPath()+
"/../../..");
141 QString bundle = QDir(qApp->applicationDirPath()+
"/../..").canonicalPath();
142 if (QFileInfo(bundle).isBundle())
143 return QDir(path).canonicalPath();
145 return qApp->applicationDirPath();
147 QString path(qApp->applicationDirPath());
158 QString appPath(qApp->applicationDirPath());
160 QString installLocation = appPath;
162 installLocation = appPath +
"/plugins";
164 if (QFile(installLocation).exists())
165 retval << installLocation;
167 QString fallbackInstallLocation = appPath;
168 if (QFile(fallbackInstallLocation).exists())
169 retval << fallbackInstallLocation; }
174 QString buildLocation = bundlePath;
176 buildLocation = bundlePath +
"/plugins";
178 if (QFile(buildLocation).exists())
179 retval << buildLocation;
200 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_CONFIG_ROOT_RELATIVE_INSTALLED);
201 if (QDir(path).exists())
202 return QStringList() << QDir(path).canonicalPath();
205 std::cout <<
"DataLocations::getRootConfigPaths(): Cannot find config root path: " << path << std::endl;
206 return QStringList();
213 if (QDir(CX_OPTIONAL_CONFIG_ROOT).exists())
214 retval << QDir(CX_OPTIONAL_CONFIG_ROOT).canonicalPath();
215 if (QDir(CX_CONFIG_ROOT).exists())
216 retval << QDir(CX_CONFIG_ROOT).canonicalPath();
225 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_DOC_ROOT_RELATIVE_INSTALLED);
227 if (QDir(path).exists())
228 return QDir(path).canonicalPath();
231 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << path;
236 if (QDir(CX_DOC_ROOT).exists())
237 return QDir(CX_DOC_ROOT).canonicalPath();
240 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << CX_DOC_ROOT;
248 for (
int i=0; i<root.size(); ++i)
249 retval << root[i] + suffix;
257 QStringList splitName = name.split(
".");
258 splitName[splitName.size()-1] = ext;
259 return splitName.join(
".");
271 return findConfigPath(
"", pathRelativeToConfigRoot, alternativeAbsolutePath);
276 QFileInfo filePath(
findConfigFilePath(fileName, pathRelativeToConfigRoot, alternativeAbsolutePath));
277 return filePath.absolutePath() +
"/";
285 QString path = root +
"/" + pathRelativeToConfigRoot +
"/" + fileName;
287 if (QFileInfo(path).exists())
291 QString path = QString(alternativeAbsolutePath +
"/" + fileName);
293 if (QFileInfo(path).exists())
296 reportWarning(
"DataLocations::findConfigFile. Error: Can't find " + fileName +
" in any of\n" + paths.join(
" \n"));
300 QString DataLocations::checkExecutableExist(QString path, QString filename)
303 path = QDir::cleanPath(path);
304 if (QDir(path).exists(filename))
319 result = DataLocations::checkExecutableExist(qApp->applicationDirPath(), filename);
320 if (!result.isEmpty())
328 mWebsiteUrl = websiteUrl;
338 return QString(
"http://custusx.org/uploads");
343 QString version(CustusX_VERSION_STRING);
344 if (version.contains(
"dev"))
346 QString url = QString(
"%1/user_doc/%2")
354 if(!mBuildFolderChecked)
359 QString pathToConfigFile = bundlePath +
"/../source/resource/core/settings/cxConfig.h";
360 if (QFile(pathToConfigFile).exists())
362 std::cout <<
"Using paths from build folder" << std::endl;
363 mRunFromBuildFolder =
true;
366 mRunFromBuildFolder =
false;
367 mBuildFolderChecked =
true;
370 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.