Downloading and accessing separate assets

Because we now have so many different devices, our apps are getting bloated and bigger because we are including three different sets of graphic assets for the different resolutions (i.e. title.png, title@2x.png, title@3x.png).  Thankfully, Corona smartly pulls the highest resolution image file when you specify “title.png,” but  what I wanted to do is only include the low-resolution assets in the initial binary, then give the user the ability to download the higher resolution artwork as a separate download.

While the above part is relatively easy, has anyone created some streamlined code that will look for the larger asset files in the system.DocumentsDirectory folder before pulling the file from system.ResourceDirectory?  Basically, I want to perform the well-known below line with minimal changes to automate the pulling of the correct file if it exists.  Anytime I request any graphic asset, it has to check for a downloaded higher-res version and fall back to the original lower-res version if there’s a problem.

local image = display.newImageRect( [parentGroup,] filename, [baseDir,] width, height )

On a side note, there could be two approaches to downloading the larger assets:

  • Download an archive file from a remote server, extract to system.DocumentsDirectory folder, then restart the app (you can even offer it as an in-App Purchase)
  • On the first launch, it will realize there’s only the the lower-resolution asset, use it in the meantime while downloading the higher-resolution asset in the background.  Upon the next call for that file, it will use the higher-resolution asset.