36 #include <sys/types.h> 41 #include "YSettings.h" 42 #include "Libyui_config.h" 44 #define YUILogComponent "ui" 53 yuiDebug() <<
"Given filename: " << filename << endl;
55 bool isThemeDir = ! directory.compare ( THEMEDIR );
58 string themeSubDir =
"/current";
59 size_t splitPos = fullPath.rfind(
"/" );
60 bool hasProgSubDir = progSubDir.compare (
"" );
61 bool hasSubDirPrepend = ( splitPos != string::npos );
62 string filenameNoPrepend = filename.substr ( splitPos + 1, string::npos );
63 string subDirPrepend =
"";
64 vector<string> dirList;
66 if ( hasSubDirPrepend )
67 subDirPrepend = filename.substr ( 0, splitPos );
69 yuiDebug() <<
"Preferring subdir: " << progSubDir << endl;
70 yuiDebug() <<
"Subdir given with filename: " << subDirPrepend << endl;
71 yuiDebug() <<
"Looking for: " << filenameNoPrepend << endl;
73 if ( hasSubDirPrepend )
78 dirList.push_back( directory +
"/" + progSubDir + themeSubDir +
"/" + subDirPrepend );
80 dirList.push_back( directory + themeSubDir +
"/" + subDirPrepend );
83 dirList.push_back( directory +
"/" + progSubDir +
"/" + subDirPrepend );
85 dirList.push_back( directory +
"/" + subDirPrepend );
91 dirList.push_back( directory +
"/" + progSubDir + themeSubDir );
93 dirList.push_back( directory + themeSubDir );
98 dirList.push_back( directory +
"/" + progSubDir );
100 dirList.push_back ( directory );
102 for ( vector<string>::const_iterator x = dirList.begin ();
103 x != dirList.end () && fullPath.compare (
"" ) == 0 ;
106 vector<string> fileList = lsDir( *x );
108 for ( vector<string>::const_iterator i = fileList.begin ();
109 i != fileList.end () && fullPath.compare (
"" ) == 0 ;
112 if ( *i !=
"." && *i !=
".." )
114 fullname = directory +
"/" + *i;
115 if ( *i == filenameNoPrepend )
119 fullPath = lookRecursive ( fullname, filenameNoPrepend );
125 if( fullPath.compare(
"" ) != 0 )
126 yuiDebug() <<
"Found " << filenameNoPrepend <<
" in " <<
dir() << endl;
129 yuiDebug() <<
"Could NOT find " << filename <<
" by looking recursive inside " << directory << endl;
140 vector<string> YPath::lsDir(
const string & directory )
142 vector<string> fileList;
146 if ( (
dir = opendir( directory.c_str () ) ) != NULL )
148 yuiDebug() <<
"Looking in " << directory << endl;
150 while ( ( ent = readdir(
dir ) ) != NULL )
151 fileList.push_back( ent -> d_name );
160 string YPath::lookRecursive(
const string & directory,
const string & filename )
162 vector<string> fileList = lsDir( directory );
166 for ( vector<string>::const_iterator i = fileList.begin();
167 i != fileList.end() && file.compare (
"" ) == 0;
170 if ( *i !=
"." && *i !=
".." )
172 fullname = directory +
"/" + ( *i );
174 if ( *i == filename )
178 file = lookRecursive ( fullname, filename );
195 return fullPath.substr ( 0, fullPath.rfind(
"/" ) );
std::string path()
Returns the full path of the file if found; if not found just the filename given in constructor...
static std::string progDir()
Returns the value of your program's subdir.
YPath(const std::string &directory, const std::string &filename)
Constructor.
std::string dir()
Returns the directory where the file is found; if not found just the subdir part (if there's any) of ...