I'm not sure how IFileList works, but it looks like it can only find items one folder from the "current" folder.
The following code is the basic look up. It first searches the path I've added to my searchPaths ( which is basically just an array of irr::io::path ).
The first folder to search in is "asset/". If the image is in this folder, all goes well. t is set to the loaded texture.
If that failes the "findInPath" kicks in:
Code: Select all
irr::video::ITexture * t = NULL;
irr::io::IFileList * filelist = device->getFileSystem()->createFileList();
for (unsigned int i = 0; i < pathCount ; i++)
{
//WORKS if image is in "asset/"
if(filelist->findFile(searchPaths[i] + filename, false) != -1)
{
t = driver->getTexture(searchPaths[i] + filename);
return t;
}
// Doesn't work
else if((t = findInPath(searchPaths[i],filename,filelist))){
return t;
}
}
Code: Select all
irr::video::ITexture * TextureManager::findInPath(irr::io::path path,irr::io::path filename, irr::io::IFileList * filelist){
irr::video::ITexture * t = NULL;
irr::io::path dir(path);
WIN32_FIND_DATA file;
dir.append("*");
HANDLE search_handle=FindFirstFile(LPCTSTR(dir.c_str()),&file);
if (search_handle)
{
do
{
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
//Skip any reference to current or parent folder. Else inf-loop imminent
if(file.cFileName[0] == '.'){
continue;
}
irr::io::path resultPath = path + file.cFileName + "/" + filename;
std::cout << resultPath.c_str() << "\n";
if(filelist->findFile(resultPath, false) != -1)
{
return t;
}
else
{
t = findInPath(path+file.cFileName + "/",filename,filelist);
if(t) return t;
}
}
}while(FindNextFile(search_handle,&file));
FindClose(search_handle);
}
return t;
};
I print out the "resultpath" with the following result:
Now the the path seems to be ok.
It just fails at if(filelist->findFile(resultPath, false) != -1)
Been stuck on this for hours now.
Does anyone know why this goes wrong?
-Sidar