35 #include <QApplication>
48 bool DataLocations::mTestMode =
false;
49 bool DataLocations::mRunFromBuildFolder =
false;
50 bool DataLocations::mBuildFolderChecked =
false;
62 QString dataRootConfigFile = settingsPath +
"/data_root_location.txt";
63 if (QFileInfo(dataRootConfigFile).exists())
65 return readTestDataPathFromFile(dataRootConfigFile);
76 QString dataRootConfigFile = settingsPath +
"/large_data_root_location.txt";
77 if (QFileInfo(dataRootConfigFile).exists())
79 return readTestDataPathFromFile(dataRootConfigFile);
83 return CX_LARGE_DATA_ROOT;
91 path = QString(
"%1/%2/%3").arg(
getTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
92 if (QFileInfo(path).exists())
95 path = QString(
"%1/%2/%3").arg(
getLargeTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
96 if (QFileInfo(path).exists())
102 QString DataLocations::readTestDataPathFromFile(QString filename)
104 QFile file(filename);
105 file.open(QFile::ReadOnly);
106 QString cxDataRoot(file.readAll());
112 QString homepath = QDir::homePath() +
"/cx_settings";
124 QString path(qApp->applicationDirPath()+
"/../../..");
125 QString bundle = QDir(qApp->applicationDirPath()+
"/../..").canonicalPath();
126 if (QFileInfo(bundle).isBundle())
129 return qApp->applicationDirPath();
131 QString path(qApp->applicationDirPath());
142 QString appPath(qApp->applicationDirPath());
144 QString installLocation = appPath;
146 installLocation = appPath +
"/plugins";
148 if (QFile(installLocation).exists())
149 retval << installLocation;
151 QString fallbackInstallLocation = appPath;
152 if (QFile(fallbackInstallLocation).exists())
153 retval << fallbackInstallLocation; }
158 QString buildLocation = bundlePath;
160 buildLocation = bundlePath +
"/plugins";
162 if (QFile(buildLocation).exists())
163 retval << buildLocation;
174 return paths.front();
181 QString path =
getBundlePath() +
"/" + CX_CONFIG_ROOT_RELATIVE_INSTALLED;
182 if (QDir(path).exists())
183 return QStringList() << QDir(path).canonicalPath();
186 std::cout <<
"DataLocations::getRootConfigPaths(): Cannot find config root path: " << path << std::endl;
187 return QStringList();
192 if (QDir(CX_CONFIG_ROOT).exists())
193 retval << QDir(CX_CONFIG_ROOT).canonicalPath();
194 if (QDir(CX_OPTIONAL_CONFIG_ROOT).exists())
195 retval << QDir(CX_OPTIONAL_CONFIG_ROOT).canonicalPath();
204 QString path =
getBundlePath() +
"/" + CX_DOC_ROOT_RELATIVE_INSTALLED;
205 if (QDir(path).exists())
206 return QDir(path).canonicalPath();
209 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << path;
214 if (QDir(CX_DOC_ROOT).exists())
215 return QDir(CX_DOC_ROOT).canonicalPath();
218 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << CX_DOC_ROOT;
226 for (
int i=0; i<root.size(); ++i)
227 retval << root[i] + suffix;
235 QStringList splitName = name.split(
".");
236 splitName[splitName.size()-1] = ext;
237 return splitName.join(
".");
249 return findConfigPath(
"", pathRelativeToConfigRoot, alternativeAbsolutePath);
254 QFileInfo filePath(
findConfigFilePath(fileName, pathRelativeToConfigRoot, alternativeAbsolutePath));
255 return filePath.absolutePath() +
"/";
263 QString path = root +
"/" + pathRelativeToConfigRoot +
"/" + fileName;
265 if (QFileInfo(path).exists())
269 QString path = QString(alternativeAbsolutePath +
"/" + fileName);
271 if (QFileInfo(path).exists())
274 reportWarning(
"DataLocations::findConfigFile. Error: Can't find " + fileName +
" in any of\n" + paths.join(
" \n"));
278 QString DataLocations::checkExecutableExist(QString path, QString filename)
281 path = QDir::cleanPath(path);
282 if (QDir(path).exists(filename))
292 result = DataLocations::checkExecutableExist(qApp->applicationDirPath(), filename);
293 if (!result.isEmpty())
298 if (!result.isEmpty())
306 QString url(
"http://custusx.org");
313 QString version(CustusX_VERSION_STRING);
314 if (version.contains(
"dev"))
316 QString url = QString(
"%1/uploads/user_doc/%2")
324 if(!mBuildFolderChecked)
329 QString pathToConfigFile = bundlePath +
"/../source/resource/core/settings/cxConfig.h";
330 if (QFile(pathToConfigFile).exists())
332 std::cout <<
"Using paths from build folder" << std::endl;
333 mRunFromBuildFolder =
true;
336 mRunFromBuildFolder =
false;
337 mBuildFolderChecked =
true;
340 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 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.