Make factory samples relative (#3510)
* Make factory samples relative Fixes #3491 Related #1719
This commit is contained in:
committed by
Lukas W
parent
6a5255e379
commit
7e3ee14cf1
@@ -63,7 +63,12 @@ ConfigManager::ConfigManager() :
|
||||
|
||||
// If we're in development (lmms is not installed) let's get the source and
|
||||
// binary directories by reading the CMake Cache
|
||||
QFile cmakeCache(qApp->applicationDirPath() + "/CMakeCache.txt");
|
||||
QDir appPath = qApp->applicationDirPath();
|
||||
// If in tests, get parent directory
|
||||
if (appPath.dirName() == "tests") {
|
||||
appPath.cdUp();
|
||||
}
|
||||
QFile cmakeCache(appPath.absoluteFilePath("CMakeCache.txt"));
|
||||
if (cmakeCache.exists()) {
|
||||
cmakeCache.open(QFile::ReadOnly);
|
||||
QTextStream stream(&cmakeCache);
|
||||
|
||||
@@ -1411,25 +1411,35 @@ void SampleBuffer::setReversed( bool _on )
|
||||
|
||||
|
||||
|
||||
QString SampleBuffer::tryToMakeRelative( const QString & _file )
|
||||
QString SampleBuffer::tryToMakeRelative( const QString & file )
|
||||
{
|
||||
if( QFileInfo( _file ).isRelative() == false )
|
||||
if( QFileInfo( file ).isRelative() == false )
|
||||
{
|
||||
QString f = QString( _file ).replace( QDir::separator(), '/' );
|
||||
QString fsd = ConfigManager::inst()->factorySamplesDir();
|
||||
QString usd = ConfigManager::inst()->userSamplesDir();
|
||||
fsd.replace( QDir::separator(), '/' );
|
||||
usd.replace( QDir::separator(), '/' );
|
||||
if( f.startsWith( fsd ) )
|
||||
QString f = QString( file ).replace( QDir::separator(), '/' );
|
||||
|
||||
// First, look in factory samples
|
||||
// Isolate "samples/" from "data:/samples/"
|
||||
QString samplesSuffix = ConfigManager::inst()->factorySamplesDir().mid( ConfigManager::inst()->dataDir().length() );
|
||||
|
||||
// Iterate over all valid "data:/" searchPaths
|
||||
for ( const QString & path : QDir::searchPaths( "data" ) )
|
||||
{
|
||||
return QString( f ).mid( fsd.length() );
|
||||
QString samplesPath = QString( path + samplesSuffix ).replace( QDir::separator(), '/' );
|
||||
if ( f.startsWith( samplesPath ) )
|
||||
{
|
||||
return QString( f ).mid( samplesPath.length() );
|
||||
}
|
||||
}
|
||||
else if( f.startsWith( usd ) )
|
||||
|
||||
// Next, look in user samples
|
||||
QString usd = ConfigManager::inst()->userSamplesDir();
|
||||
usd.replace( QDir::separator(), '/' );
|
||||
if( f.startsWith( usd ) )
|
||||
{
|
||||
return QString( f ).mid( usd.length() );
|
||||
}
|
||||
}
|
||||
return _file;
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user