Jump to content

How access directories or files in a script inside an ung archive ?


photo

Recommended Posts

Hi, 

 

Since I've archived a script folder into a ung archive, I get problem accessing directories in this same archive :

 

 

Extract of a script that works unarchived and fails archived :

string dirName = engine.getDataPath() + "my_directory";
Dir dir = new Dir();
dir.open(dirName); // returns 0 when the script is archived !

Could you please tell me why it doesn't work ? and if is there another way to do that inside a ung archive ?

 
Thx, 
 

Best regards,

Philippe

Link to comment

Hi Philippe­,

 

There are no directories in ung archive, only files with paths. If you need to open file, just use File::open(engine.getDataPath() + "my_directory/my_file"). If you need to get list of files, located in the current directory that is in archive,  you need to do something like this:

string dir_name = "packagefolder/otherfolder/"; // name of the directory in the package
string package_name = "package"; // name of the package file

// find package num
int package_num = -1;
forloop(int i = 0; engine.filesystem.getNumPackages())
{
  if(package_name != engine.filesystem.getPackageName()) continue;
  package_num = i;
  break;
}

if(package_num == -1)
{
  // package not found
  return;
}

// get package files
string files[0];
engine.filesystem.getPackageFileNames(package_num,files);

// iterate over package files and take needed ones
string needed_files[0];
foreach(string file; files)
{
  if(strncmp(dir_name,file,strlen(dir_name))) continue;
  needed_files.append(file);
}

Also note, that if archive isn't loaded, you need to load it first by engine.filesystem.loadPackage.

Link to comment

Thanks a lot for your answer,

 

I've tried like in your example and it worked.

For information, the archive wasn't loaded, I needed to load it first with engine.filesystem.loadPackage like you said.

Link to comment
×
×
  • Create New...