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";
131 QString path(qApp->applicationDirPath()+
"/../../..");
132 QString bundle = QDir(qApp->applicationDirPath()+
"/../..").canonicalPath();
133 if (QFileInfo(bundle).isBundle())
134 return QDir(path).canonicalPath();
136 return qApp->applicationDirPath();
138 QString path(qApp->applicationDirPath());
149 QString appPath(qApp->applicationDirPath());
151 QString installLocation = appPath;
153 installLocation = appPath +
"/plugins";
155 if (QFile(installLocation).exists())
156 retval << installLocation;
158 QString fallbackInstallLocation = appPath;
159 if (QFile(fallbackInstallLocation).exists())
160 retval << fallbackInstallLocation; }
165 QString buildLocation = bundlePath;
167 buildLocation = bundlePath +
"/plugins";
169 if (QFile(buildLocation).exists())
170 retval << buildLocation;
191 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_CONFIG_ROOT_RELATIVE_INSTALLED);
192 if (QDir(path).exists())
193 return QStringList() << QDir(path).canonicalPath();
196 std::cout <<
"DataLocations::getRootConfigPaths(): Cannot find config root path: " << path << std::endl;
197 return QStringList();
204 if (QDir(CX_OPTIONAL_CONFIG_ROOT).exists())
205 retval << QDir(CX_OPTIONAL_CONFIG_ROOT).canonicalPath();
206 if (QDir(CX_CONFIG_ROOT).exists())
207 retval << QDir(CX_CONFIG_ROOT).canonicalPath();
216 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_DOC_ROOT_RELATIVE_INSTALLED);
218 if (QDir(path).exists())
219 return QDir(path).canonicalPath();
222 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << path;
227 if (QDir(CX_DOC_ROOT).exists())
228 return QDir(CX_DOC_ROOT).canonicalPath();
231 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << CX_DOC_ROOT;
239 for (
int i=0; i<root.size(); ++i)
240 retval << root[i] + suffix;
248 QStringList splitName = name.split(
".");
249 splitName[splitName.size()-1] = ext;
250 return splitName.join(
".");
262 return findConfigPath(
"", pathRelativeToConfigRoot, alternativeAbsolutePath);
267 QFileInfo filePath(
findConfigFilePath(fileName, pathRelativeToConfigRoot, alternativeAbsolutePath));
268 return filePath.absolutePath() +
"/";
276 QString path = root +
"/" + pathRelativeToConfigRoot +
"/" + fileName;
278 if (QFileInfo(path).exists())
282 QString path = QString(alternativeAbsolutePath +
"/" + fileName);
284 if (QFileInfo(path).exists())
287 reportWarning(
"DataLocations::findConfigFile. Error: Can't find " + fileName +
" in any of\n" + paths.join(
" \n"));
291 QString DataLocations::checkExecutableExist(QString path, QString filename)
294 path = QDir::cleanPath(path);
295 if (QDir(path).exists(filename))
310 result = DataLocations::checkExecutableExist(qApp->applicationDirPath(), filename);
311 if (!result.isEmpty())
319 mWebsiteUrl = websiteUrl;
329 return QString(
"http://custusx.org/uploads");
334 QString version(CustusX_VERSION_STRING);
335 if (version.contains(
"dev"))
337 QString url = QString(
"%1/user_doc/%2")
345 if(!mBuildFolderChecked)
350 QString pathToConfigFile = bundlePath +
"/../source/resource/core/settings/cxConfig.h";
351 if (QFile(pathToConfigFile).exists())
353 std::cout <<
"Using paths from build folder" << std::endl;
354 mRunFromBuildFolder =
true;
357 mRunFromBuildFolder =
false;
358 mBuildFolderChecked =
true;
361 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 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()