36 #include <sys/types.h> 41 #include "YSettings.h" 42 #include "Libyui_config.h" 44 #define YUILogComponent "ui" 47 YPath::YPath (
const std::string & directory,
const std::string & filename )
49 yuiMilestone () <<
"Given filename: " << filename << std::endl;
51 bool isThemeDir = ! directory.compare ( THEMEDIR );
53 std::string fullname =
"";
54 std::string themeSubDir =
"/current";
55 size_t splitPos = fullPath.rfind(
"/" );
56 bool hasProgSubDir = progSubDir.compare (
"" );
57 bool hasSubDirPrepend = ( splitPos != std::string::npos );
58 std::string filenameNoPrepend = filename.substr ( splitPos + 1, std::string::npos );
59 std::string subDirPrepend =
"";
60 std::vector<std::string> dirList;
62 if ( hasSubDirPrepend )
63 subDirPrepend = filename.substr ( 0, splitPos );
65 yuiMilestone () <<
"Preferring subdir: " << progSubDir << std::endl;
66 yuiMilestone () <<
"Subdir given with filename: " << subDirPrepend << std::endl;
67 yuiMilestone () <<
"Looking for: " << filenameNoPrepend << std::endl;
69 if ( hasSubDirPrepend )
74 dirList.push_back ( directory +
"/" + progSubDir + themeSubDir +
"/" + subDirPrepend );
76 dirList.push_back ( directory + themeSubDir +
"/" + subDirPrepend );
79 dirList.push_back ( directory +
"/" + progSubDir +
"/" + subDirPrepend );
81 dirList.push_back ( directory +
"/" + subDirPrepend );
87 dirList.push_back ( directory +
"/" + progSubDir + themeSubDir );
89 dirList.push_back ( directory + themeSubDir );
94 dirList.push_back ( directory +
"/" + progSubDir );
96 dirList.push_back ( directory );
98 for ( std::vector<std::string>::const_iterator x = dirList.begin () ; x != dirList.end () && fullPath.compare (
"" ) == 0 ; ++x )
100 std::vector<std::string> fileList = lsDir( *x );
102 for ( std::vector<std::string>::const_iterator i = fileList.begin () ; i != fileList.end () && fullPath.compare (
"" ) == 0 ; ++i )
104 if ( *i !=
"." && *i !=
".." )
106 fullname = directory +
"/" + *i;
107 if ( *i == filenameNoPrepend )
111 fullPath = lookRecursive ( fullname, filenameNoPrepend );
117 if( fullPath.compare (
"" ) != 0 )
118 yuiMilestone() <<
"Found " << filenameNoPrepend <<
" in " <<
dir() << std::endl;
121 yuiMilestone() <<
"Could NOT find " << filename <<
" by looking recursive inside " << directory << std::endl;
130 std::vector<std::string> YPath::lsDir(
const std::string & directory )
132 std::vector<std::string> fileList;
136 if ( ( dir = opendir( directory.c_str () ) ) != NULL )
138 yuiMilestone() <<
"Looking in " << directory << std::endl;
140 while ( ( ent = readdir ( dir ) ) != NULL )
141 fileList.push_back ( ent -> d_name );
149 std::string YPath::lookRecursive(
const std::string & directory,
const std::string & filename )
151 std::vector<std::string> fileList = lsDir( directory );
152 std::string file =
"";
153 std::string fullname;
155 for ( std::vector<std::string>::const_iterator i = fileList.begin() ; i != fileList.end() && file.compare (
"" ) == 0 ; ++i )
157 if ( *i !=
"." && *i !=
".." )
159 fullname = directory +
"/" + ( *i );
160 if ( *i == filename )
164 file = lookRecursive ( fullname, filename );
178 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...
std::string dir()
Returns the directory where the file is found; if not found just the subdir part (if there's any) of ...
YPath(const std::string &directory, const std::string &filename)
Constructor.
static std::string progDir()
Returns the value of your program's subdir.