src/lib/src/functions.cpp
/**
 * Return the path to a specified file in the config folder (since program files is not writable).
 * @param	file	The file.
 * @param	exists	If the file must already exist beforehand.
 * @return			The absolute path to the file.
 */
Return the path to a specified file in the config folder (since program files is not writable).
@param       file    The file.
@param       exists  If the file must already exist beforehand.
@return                      The absolute path to the file.
Return the path to a specified file in the config folder ( since program files is not writable ) . @param file The file . @param exists If the file must already exist beforehand . @return The absolute path to the file .
QString savePath(const QString &file, bool exists, bool writable)
{
	const QString &check = exists ? file : QStringLiteral("settings.ini");
	if (isTestModeEnabled()) {
		if (QDir(QDir::currentPath() + "/tests/resources/").exists()) {
			return QDir::toNativeSeparators(QDir::currentPath() + "/tests/resources/" + file);
		}
	}
	if (validSavePath(qApp->applicationDirPath() + "/" + check, writable)) {
		return QDir::toNativeSeparators(qApp->applicationDirPath() + "/" + file);
	}
	if (validSavePath(QDir::currentPath() + "/" + check, writable)) {
		return QDir::toNativeSeparators(QDir::currentPath() + "/" + file);
	}
	if (validSavePath(QDir::homePath() + "/Grabber/" + check, writable)) {
		return QDir::toNativeSeparators(QDir::homePath() + "/Grabber/" + file);
	}
	#if defined(Q_OS_ANDROID)
		const QString &appData = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
		if (validSavePath(appData + "/" + check, writable)) {
			return QDir::toNativeSeparators(appData + "/" + file);
		}
		if (validSavePath("assets:/" + check, writable)) {
			return QDir::toNativeSeparators("assets:/" + file);
		}
	#endif
	#ifdef __linux__
		if (validSavePath(QDir::homePath() + "/.Grabber/" + check, writable)) {
			return QDir::toNativeSeparators(QDir::homePath() + "/.Grabber/" + file);
		}
		if (validSavePath(qApp->applicationDirPath() + "/../share/Grabber/" + check, writable)) {
			return QDir::toNativeSeparators(qApp->applicationDirPath() + "/../share/Grabber/" + file);
		}
		if (validSavePath(QString(PREFIX) + "/share/Grabber/" + check, writable)) {
			return QDir::toNativeSeparators(QString(PREFIX) + "/share/Grabber/" + file);
		}
	#endif
	QString dir;
	#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
		#if defined(Q_OS_ANDROID)
			dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
		#else
			dir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
		#endif
	#else
		dir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
		#ifdef __linux__
			dir += QLatin1Char('/') + QCoreApplication::organizationName();
			dir += QLatin1Char('/') + QCoreApplication::applicationName();
		#endif
	#endif
	return QDir::toNativeSeparators(dir + QLatin1Char('/') + file);
}
QString savePath ( const QString & file , bool exists , bool writable ) { const QString & check = exists ? file : QStringLiteral ( " " ) ; if ( isTestModeEnabled ( ) ) { if ( QDir ( QDir :: currentPath ( ) + " " ) . exists ( ) ) { return QDir :: toNativeSeparators ( QDir :: currentPath ( ) + " " + file ) ; } } if ( validSavePath ( qApp -> applicationDirPath ( ) + " " + check , writable ) ) { return QDir :: toNativeSeparators ( qApp -> applicationDirPath ( ) + " " + file ) ; } if ( validSavePath ( QDir :: currentPath ( ) + " " + check , writable ) ) { return QDir :: toNativeSeparators ( QDir :: currentPath ( ) + " " + file ) ; } if ( validSavePath ( QDir :: homePath ( ) + " " + check , writable ) ) { return QDir :: toNativeSeparators ( QDir :: homePath ( ) + " " + file ) ; } #if defined ( Q_OS_ANDROID ) const QString & appData = QStandardPaths :: writableLocation ( QStandardPaths :: AppDataLocation ) ; if ( validSavePath ( appData + " " + check , writable ) ) { return QDir :: toNativeSeparators ( appData + " " + file ) ; } if ( validSavePath ( " " + check , writable ) ) { return QDir :: toNativeSeparators ( " " + file ) ; } #endif #ifdef __linux__ if ( validSavePath ( QDir :: homePath ( ) + " " + check , writable ) ) { return QDir :: toNativeSeparators ( QDir :: homePath ( ) + " " + file ) ; } if ( validSavePath ( qApp -> applicationDirPath ( ) + " " + check , writable ) ) { return QDir :: toNativeSeparators ( qApp -> applicationDirPath ( ) + " " + file ) ; } if ( validSavePath ( QString ( PREFIX ) + " " + check , writable ) ) { return QDir :: toNativeSeparators ( QString ( PREFIX ) + " " + file ) ; } #endif QString dir ; #if ( QT_VERSION >= QT_VERSION_CHECK ( 5 , 4 , 0 ) ) #if defined ( Q_OS_ANDROID ) dir = QStandardPaths :: writableLocation ( QStandardPaths :: AppDataLocation ) ; #else dir = QStandardPaths :: writableLocation ( QStandardPaths :: AppConfigLocation ) ; #endif #else dir = QStandardPaths :: writableLocation ( QStandardPaths :: ConfigLocation ) ; #ifdef __linux__ dir += QLatin1Char ( ' ' ) + QCoreApplication :: organizationName ( ) ; dir += QLatin1Char ( ' ' ) + QCoreApplication :: applicationName ( ) ; #endif #endif return QDir :: toNativeSeparators ( dir + QLatin1Char ( ' ' ) + file ) ; }
Return the path to a specified file in the config folder (since program files is not writable).
Return the path to a specified file in the config folder ( since program files is not writable ) .