Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make factory samples relative #3510

Merged
merged 7 commits into from
May 6, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/core/SampleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
foreach ( const QString& path, QDir::searchPaths( "data" ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but foreach is a candidate for removal in Qt, quote:

Since Qt 5.7, the use of this macro is discouraged. It will be removed in a future version of Qt. Please use C++11 range-for, possibly with qAsConst(), as needed.

So this would be the preferred way:

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;
}


Expand Down