Can I store .zip files in the system.ResourceDirectory

Currently I have .lua files that contain nothing but tables of large amounts of data that is called at various times throughout the app.  For app size reasons, I’m wanting to store these as .zip files that will contain .txt files of the data instead.  When needed, I would unzip the files and extract the data.  

Is it possible to store these .zip files in the system.ResourceDirectory?  

If not, is it possible to include .zip files as part of the core app in any other way?  

Or does anyone have any other advice on the situation?

Yes.

You will need to extract it to the system.documents folder and then access all the files from there.

Thanks for the reply roaminggamer. Would the files have to be directly in the system.ResourceDirectory or could I place them in their own folders? If they could be in their own folders, what would the .zip function syntax look like for choosing them?

Also, when I extracted the .txt files from the .zip to the system.documents folder and was finished with them, would I need to delete the .txt files with code?

  1. Sure, you could make a sub-folder

  2. If you wanted to make the files transient, you could put them in the system.CachesDirectory, but if you’re using the files every time you run the game that isn’t a great idea, because then the user has the pay the unzip (time-) penalty ever time

So I’m having trouble getting it to work when trying to use subfolders.  It works fine though, when not using subfolders and using “zipBaseDir = system.ResourceDirectory”.  The documentation says the “zipBaseDir” must be a constant.  So I’m having trouble figuring out how to change the “zipBaseDir” to a subfolder.  Here’s my code that works:

[lua]

local zipOptions =

   {

   zipFile = zipSelect,

   zipBaseDir = system.ResourceDirectory,

   dstBaseDir = system.DocumentsDirectory,

   files = { “1.txt”,“2.txt”,“3.txt” },

   listener = zipListener

   }

zip.uncompress( zipOptions )

[/lua]

But I really need for the “zipBaseDir” to be something like “zipBaseDir = system.ResourceDirectory/levels/1”

Any help would be appreciated.

  1. The zip tools is pretty limited in this respect.  You can only unzip directly to the root of these system folders (I may have mislead you a little by accident here):
  • system.CachesDirectory
  • system.DocumentDirectory
  • system.ResourceDirectory
  1.  basedir is simply one of the above constants.

  2. Don’t use the files option.  Just unzip the whole contents.

    local zipOptions = { zipFile = zipSelect, zipBaseDir = system.ResourceDirectory, dstBaseDir = system.DocumentsDirectory, – files = { “1.txt”,“2.txt”,“3.txt” }, listener = zipListener } zip.uncompress( zipOptions )

4a. I handle subfolders by including them in the zip file structure:

  • zip contents with subfolders already present
  • unzip the entire zip file which automatically creates folder structure as it was zipped.

Download this file and use zip to uncompress it to system.DocumentDirectory in order to see what I mean: https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/tools/eat_free/sources.zip

(From EAT Free: https://github.com/roaminggamer/RG_FreeStuff/tree/master/SSK2/tools))

– OR –

4b. In advanced case, I may then re-arrange content using the SSK2 Files Library.

Thanks again for the help.  Having to write directly to the system.SocumentsDirectory isn’t a problem at all… but having to write directly from the system.ResourceDirectory is a bit of a problem.  I think I’ll be able to find something that works with your input, but it will have to be a bit different than what I was originally envisioning.

Yes.

You will need to extract it to the system.documents folder and then access all the files from there.

Thanks for the reply roaminggamer. Would the files have to be directly in the system.ResourceDirectory or could I place them in their own folders? If they could be in their own folders, what would the .zip function syntax look like for choosing them?

Also, when I extracted the .txt files from the .zip to the system.documents folder and was finished with them, would I need to delete the .txt files with code?

  1. Sure, you could make a sub-folder

  2. If you wanted to make the files transient, you could put them in the system.CachesDirectory, but if you’re using the files every time you run the game that isn’t a great idea, because then the user has the pay the unzip (time-) penalty ever time

So I’m having trouble getting it to work when trying to use subfolders.  It works fine though, when not using subfolders and using “zipBaseDir = system.ResourceDirectory”.  The documentation says the “zipBaseDir” must be a constant.  So I’m having trouble figuring out how to change the “zipBaseDir” to a subfolder.  Here’s my code that works:

[lua]

local zipOptions =

   {

   zipFile = zipSelect,

   zipBaseDir = system.ResourceDirectory,

   dstBaseDir = system.DocumentsDirectory,

   files = { “1.txt”,“2.txt”,“3.txt” },

   listener = zipListener

   }

zip.uncompress( zipOptions )

[/lua]

But I really need for the “zipBaseDir” to be something like “zipBaseDir = system.ResourceDirectory/levels/1”

Any help would be appreciated.

  1. The zip tools is pretty limited in this respect.  You can only unzip directly to the root of these system folders (I may have mislead you a little by accident here):
  • system.CachesDirectory
  • system.DocumentDirectory
  • system.ResourceDirectory
  1.  basedir is simply one of the above constants.

  2. Don’t use the files option.  Just unzip the whole contents.

    local zipOptions = { zipFile = zipSelect, zipBaseDir = system.ResourceDirectory, dstBaseDir = system.DocumentsDirectory, – files = { “1.txt”,“2.txt”,“3.txt” }, listener = zipListener } zip.uncompress( zipOptions )

4a. I handle subfolders by including them in the zip file structure:

  • zip contents with subfolders already present
  • unzip the entire zip file which automatically creates folder structure as it was zipped.

Download this file and use zip to uncompress it to system.DocumentDirectory in order to see what I mean: https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/tools/eat_free/sources.zip

(From EAT Free: https://github.com/roaminggamer/RG_FreeStuff/tree/master/SSK2/tools))

– OR –

4b. In advanced case, I may then re-arrange content using the SSK2 Files Library.

Thanks again for the help.  Having to write directly to the system.SocumentsDirectory isn’t a problem at all… but having to write directly from the system.ResourceDirectory is a bit of a problem.  I think I’ll be able to find something that works with your input, but it will have to be a bit different than what I was originally envisioning.