14 #include <QApplication>
27 bool DataLocations::mTestMode =
false;
28 bool DataLocations::mRunFromBuildFolder =
false;
29 bool DataLocations::mBuildFolderChecked =
false;
30 QString DataLocations::mWebsiteUrl =
"";
48 QString dataRootConfigFile = settingsPath +
"/data_root_location.txt";
49 if (QFileInfo(dataRootConfigFile).exists())
51 return readTestDataPathFromFile(dataRootConfigFile);
62 QString dataRootConfigFile = settingsPath +
"/large_data_root_location.txt";
63 if (QFileInfo(dataRootConfigFile).exists())
65 return readTestDataPathFromFile(dataRootConfigFile);
69 return CX_LARGE_DATA_ROOT;
77 path = QString(
"%1/%2/%3").arg(
getTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
78 if (QFileInfo(path).exists())
81 path = QString(
"%1/%2/%3").arg(
getLargeTestDataPath()).arg(pathRelativeToTestDataRoot).arg(filename);
82 if (QFileInfo(path).exists())
88 QString DataLocations::readTestDataPathFromFile(QString filename)
91 file.open(QFile::ReadOnly);
92 QString cxDataRoot(file.readAll());
98 QString homepath = QDir::homePath() +
"/" + CX_SYSTEM_BASE_NAME +
"_settings";
101 homepath = homepath +
"/temp";
109 QDir dir(pathToDelete);
110 CX_LOG_INFO() <<
"Going to delete:" << dir.absolutePath();
111 dir.removeRecursively();
124 QString path(qApp->applicationDirPath()+
"/../../..");
125 QString bundle = QDir(qApp->applicationDirPath()+
"/../..").canonicalPath();
126 if (QFileInfo(bundle).isBundle())
127 return QDir(path).canonicalPath();
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;
184 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_CONFIG_ROOT_RELATIVE_INSTALLED);
185 if (QDir(path).exists())
186 return QStringList() << QDir(path).canonicalPath();
189 std::cout <<
"DataLocations::getRootConfigPaths(): Cannot find config root path: " << path << std::endl;
190 return QStringList();
197 if (QDir(CX_OPTIONAL_CONFIG_ROOT).exists())
198 retval << QDir(CX_OPTIONAL_CONFIG_ROOT).canonicalPath();
199 if (QDir(CX_CONFIG_ROOT).exists())
200 retval << QDir(CX_CONFIG_ROOT).canonicalPath();
209 QString path = QString(
"%1/%2").arg(qApp->applicationDirPath()).arg(CX_DOC_ROOT_RELATIVE_INSTALLED);
211 if (QDir(path).exists())
212 return QDir(path).canonicalPath();
215 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << path;
220 if (QDir(CX_DOC_ROOT).exists())
221 return QDir(CX_DOC_ROOT).canonicalPath();
224 CX_LOG_ERROR() << QString(
"Cannot find doc path: ") << CX_DOC_ROOT;
232 for (
int i=0; i<root.size(); ++i)
233 retval << root[i] + suffix;
241 QStringList splitName = name.split(
".");
242 splitName[splitName.size()-1] = ext;
243 return splitName.join(
".");
255 return findConfigPath(
"", pathRelativeToConfigRoot, alternativeAbsolutePath);
260 QFileInfo filePath(
findConfigFilePath(fileName, pathRelativeToConfigRoot, alternativeAbsolutePath));
261 return filePath.absolutePath() +
"/";
269 QString path = root +
"/" + pathRelativeToConfigRoot +
"/" + fileName;
271 if (QFileInfo(path).exists())
275 QString path = QString(alternativeAbsolutePath +
"/" + fileName);
277 if (QFileInfo(path).exists())
280 reportWarning(
"DataLocations::findConfigFile. Error: Can't find " + fileName +
" in any of\n" + paths.join(
" \n"));
284 QString DataLocations::checkExecutableExist(QString path, QString filename)
287 path = QDir::cleanPath(path);
288 if (QDir(path).exists(filename))
303 result = DataLocations::checkExecutableExist(qApp->applicationDirPath(), filename);
304 if (!result.isEmpty())
312 mWebsiteUrl = websiteUrl;
322 return QString(
"http://custusx.org/uploads");
327 QString version(CustusX_VERSION_STRING);
328 if (version.contains(
"dev"))
330 QString url = QString(
"%1/user_doc/%2")
338 if(!mBuildFolderChecked)
343 QString pathToConfigFile = bundlePath +
"/../source/resource/core/settings/cxConfig.h";
344 if (QFile(pathToConfigFile).exists())
346 std::cout <<
"Using paths from build folder" << std::endl;
347 mRunFromBuildFolder =
true;
350 mRunFromBuildFolder =
false;
351 mBuildFolderChecked =
true;
354 return mRunFromBuildFolder;