Warning

This wiki is very out of date, and only exists for historical reasons. For more modern information, see the new documentation and cookbook forum.

renpy/doc/cookbook/Unarchiving files from rpa

From Ren'Py Visual Novel Engine

Jump to: navigation, search

Unarchiving files from rpa

With this script you are able to unarchive files from your rpa (as to give them to players as bonus presents etc...)

Example

init python:
    def unarchive(original_filename, new_filename):
        # original_filename is the name the file has when stored in the archive, including any 
        # leading paths.

        # new_filename is the name the file will have when extracted, relative to the base directory.
        
        import os
        import os.path

        new_filename = config.basedir + "/" + new_filename
        dirname = os.path.dirname(new_filename)
        
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        orig = renpy.file(original_filename)
        new = open(new_filename, "wb")

        from shutil import copyfileobj
        copyfileobj(orig, new)

        new.close()
        orig.close()
        
            
label start:
    # We have Track01.mp3 in archive and images/photo.png in archive too
    
    # This will unarchive Track01.mp3 from archive basedir/extracted path
    $ unarchive("Track01.mp3", "extracted/Track01.mp3")
    
    # This will unarchive photo.png as xxx.png from archive to basedir/extracted path
    $ unarchive("images/photo.png", "extracted/xxx.png")
Personal tools