Game Development Community

Exploring outside the project root

by Dave Young · in Torque Game Engine · 06/01/2008 (6:13 am) · 5 replies

GetLoadFileName or getSaveFileName won't explore outside the project root. It looks like the resourcemanager tracks added mods and paths to make sure they are inside the current working folder.

Is there an easy way to explore outside the game working folder? ShowTool does it, kinda.

I implemented TGB's native dialogs, but they're windows only and I have to pretend the project will deploy on a mac later so am looking for a better approach.

#1
10/22/2009 (2:20 pm)
Hi Dave,

Were you able to get TGE to accept paths that were outside the working directory? I'm only interested in Windows for now.

Thanks,
John
#2
10/22/2009 (10:21 pm)
Yes, it involved lots of c++ changes, but mostly focused in that one area.
I dug in and did the research into the windows api to get the commands I needed, it wasn't that bad.
#3
10/22/2009 (11:26 pm)
That's great, any pointers you can give? I'm looking at the find function,but not sure exactly where to start:

ResourceObject *ResManager::find (const char *fileName)
{
if (!fileName)
return NULL;
StringTableEntry path, file;
getPaths (fileName, path, file);
ResourceObject *ret = dictionary.find (path, file);
if(!ret)
{
// Potentially dangerous behavior to have in shipping version but *very* useful
// in a production environment
//#ifndef TORQUE_SHIPPING
// If we couldn't find the file in the resource list (generated
// by setting the modPaths) then try to load it directly
if (Platform::isFile(fileName))
{
ret = createResource (path, file);
dictionary.pushBehind (ret, ResourceObject::File);

ret->flags = ResourceObject::File;
ret->fileOffset = 0;

S32 fileSize = Platform::getFileSize(fileName);
ret->fileSize = fileSize;
ret->compressedFileSize = fileSize;

return ret;
}
//#endif

fileIsMissing(fileName);
}
return ret;
}
#4
10/22/2009 (11:35 pm)
It's more than that, we have to tell the Platform layer how to access files outside of the execution environment to begin with. In it's path validation checks it will fail otherwise.

The changes were pretty extensive in winfileio.cc, but here is an example of a function I wrote to get the 'special folders'


const char *Platform::getUserSpecialDirectory(S32 which) 
{
  //CSIDL_COMMON_DESKTOPDIRECTORY
  //CSIDL_COMMON_DOCUMENTS
  //CSIDL_MYMUSIC
  //CSIDL_MYPICTURES
	int whichmode;

  char szBuffer[512];
  switch (which)
    {
    case 1:
        whichmode = CSIDL_COMMON_DESKTOPDIRECTORY;
        break;
    case 2:
		whichmode = CSIDL_COMMON_DOCUMENTS;
        break;
    case 3:
		whichmode = CSIDL_MYMUSIC;
        break;
    case 4:
		whichmode = CSIDL_MYPICTURES;
        break;
    default:
        whichmode = CSIDL_COMMON_DESKTOPDIRECTORY;
      }

  if(! SHGetSpecialFolderPathA( NULL, LPSTR( szBuffer ), whichmode, true ) )
     return "";

   return StringTable->insert(szBuffer);
}


I can't help much more than that, but to suggest looking at the win api and how to access the file system.
#5
10/23/2009 (12:15 am)
Thanks, can I email you directly? Mine's thuo AT hotmail DOT com. If it's acceptable could you walk me through it as a "paid project"...

I don't need to browse folders, I just need to access files in a predetermined folder outside the root folder.

With stock Torque, am able to to access files in game from: "~/data/pics/".

I want to access the same from say : "C:/mygame/pics1/"

I will then use "findFirstFile/findNextFile" etc once am able to access the new folder, and will not need to write.