Skip to content

Commit a593adf

Browse files
Merge branch 'cinder:master' into master
2 parents 12532f0 + b6f8277 commit a593adf

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

include/cinder/Utilities.h

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ CI_API fs::path getDocumentsDirectory();
4747
//! Removes all files beyond maxFileCount.
4848
CI_API void limitDirectoryFileCount( const fs::path& directoryPath, size_t maxFileCount, std::function<bool(const fs::path&, const fs::path&)> sortFn = []( const fs::path& p1, const fs::path& p2 ) -> bool { return fs::last_write_time( p1 ) > fs::last_write_time( p2 ); } );
4949

50+
//! Searches upwards from \a start (file or directory) for an ancestor directory where \a relativeSearch exists, up to \a maxDepth levels; returns absolute path if found, otherwise empty path.
51+
CI_API fs::path findAncestorDir( const fs::path& start, const fs::path& relativeSearch, int maxDepth = 10 );
52+
//! Searches upwards from \a start (file or directory) for an ancestor file where \a relativeSearch exists, up to \a maxDepth levels; returns absolute path if found, otherwise empty path.
53+
CI_API fs::path findAncestorFile( const fs::path& start, const fs::path& relativeSearch, int maxDepth = 10 );
54+
5055
//! Launches a path in a web browser
5156
CI_API void launchWebBrowser( const Url &url );
5257

proj/cmake/modules/FindMPG123.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
set( MPG123_FOUND false )
1010

11-
set( MPG123_INCLUDE_DIRS /opt/local/include /usr/local/include /usr/include )
11+
set( MPG123_INCLUDE_DIRS /opt/local/include /usr/local/include /usr/include /usr/include/x86_64-linux-gnu )
1212
set( MPG123_LIBRARY_DIRS /opt/local/lib /usr/local/lib /usr/lib )
1313

1414
set( MPG123_LIB_SUFFIXES lib x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu )

src/cinder/Utilities.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ void limitDirectoryFileCount( const fs::path& directoryPath, size_t maxFileCount
7878
}
7979
}
8080

81+
fs::path findAncestorFile( const fs::path& start, const fs::path& relativeSearch, int maxDepth )
82+
{
83+
size_t parentCt = 0;
84+
for( fs::path curPath = start; curPath.has_parent_path() && parentCt <= maxDepth; curPath = curPath.parent_path(), ++parentCt ) {
85+
const fs::path testDir = curPath / relativeSearch;
86+
if( fs::exists( testDir ) && fs::is_regular_file( testDir ) )
87+
return testDir;
88+
}
89+
90+
return fs::path();
91+
}
92+
93+
fs::path findAncestorDir( const fs::path& start, const fs::path& relativeSearch, int maxDepth )
94+
{
95+
size_t parentCt = 0;
96+
for( fs::path curPath = start; curPath.has_parent_path() && parentCt <= maxDepth; curPath = curPath.parent_path(), ++parentCt ) {
97+
const fs::path testDir = curPath / relativeSearch;
98+
if( fs::exists( testDir ) && fs::is_directory( testDir ) )
99+
return testDir;
100+
}
101+
102+
return fs::path();
103+
}
104+
81105
void launchWebBrowser( const Url &url )
82106
{
83107
app::Platform::get()->launchWebBrowser( url );

src/cinder/app/Platform.cpp

+4-14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "cinder/app/Platform.h"
2525
#include "cinder/CinderAssert.h"
26+
#include "cinder/Utilities.h"
2627

2728
#if defined( CINDER_COCOA )
2829
#include "cinder/app/cocoa/PlatformCocoa.h"
@@ -145,20 +146,9 @@ const vector<fs::path>& Platform::getAssetDirectories() const
145146

146147
void Platform::findAndAddDefaultAssetPath()
147148
{
148-
// first search the local directory, then its parent, up to ASSET_SEARCH_DEPTH levels up
149-
// check at least the app path, even if it has no parent directory
150-
auto execPath = getExecutablePath();
151-
size_t parentCt = 0;
152-
for( fs::path curPath = execPath; curPath.has_parent_path() || ( curPath == execPath ); curPath = curPath.parent_path(), ++parentCt ) {
153-
if( parentCt >= ASSET_SEARCH_DEPTH )
154-
break;
155-
156-
const fs::path curAssetDir = curPath / fs::path( "assets" );
157-
if( fs::exists( curAssetDir ) && fs::is_directory( curAssetDir ) ) {
158-
addAssetDirectory( curAssetDir );
159-
break;
160-
}
161-
}
149+
fs::path assetDir = findAncestorDir( getExecutablePath(), "assets", ASSET_SEARCH_DEPTH );
150+
if( ! assetDir.empty() )
151+
addAssetDirectory( assetDir );
162152
}
163153

164154
std::ostream& Platform::console()

0 commit comments

Comments
 (0)