mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-18 11:45:04 -04:00
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
@@ -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