Existing files deleted on APK install?

148 views
Skip to first unread message

Richard Jones

unread,
Jan 31, 2013, 3:31:09 AM1/31/13
to python-...@googlegroups.com
Hi all,

I'm transitioning an app over from the pygame subset for android (pgs4a) to Kivy and in doing so the default location for file storage has changed. In my app I save the game state using:

    with open('save.state', 'wb') as f:
        marshal.dump(state, f)

Under pgs4a this is saved in /data/data/net.mechanicalcat.match3/files/save.state but under the latest python-for-android that Kivy uses it's saved under /storage/emulated/0/net.mechanicalcat.match3/save.state.

That's not necessarily a problem *except* that I can't seem to retain existing players' game state when I upgrade from pgs4a to python-for-android. The save.state file under the old files directory appears to be deleted when the new APK is installed. The file is *not* deleted when I install an APK that represents a new version of the pgs4a game.

They have the same install key, and I'm using "adb install -r" in both cases.


      Richard

Richard Jones

unread,
Feb 8, 2013, 6:51:45 AM2/8/13
to python-...@googlegroups.com
On Thursday, January 31, 2013 7:31:09 PM UTC+11, Richard Jones wrote:
I'm transitioning an app over from the pygame subset for android (pgs4a) to Kivy and in doing so the default location for file storage has changed. In my app I save the game state using:

    with open('save.state', 'wb') as f:
        marshal.dump(state, f)

Under pgs4a this is saved in /data/data/net.mechanicalcat.match3/files/save.state but under the latest python-for-android that Kivy uses it's saved under /storage/emulated/0/net.mechanicalcat.match3/save.state.

That's not necessarily a problem *except* that I can't seem to retain existing players' game state when I upgrade from pgs4a to python-for-android. The save.state file under the old files directory appears to be deleted when the new APK is installed. The file is *not* deleted when I install an APK that represents a new version of the pgs4a game.

I have discovered the cause of the problem. Both use the renpy Java runtime.

pgs4a bundles all of the application data into the private.mp3 archive. This is installed into /data/data/net.mechanicalcat.match3/files/.

python-for-android bundles some of the application into private.mp3 and some into public.mp3. The private data goes into the directory above. The public data goes into the directory defined by getExternalStorageDirectory() which is /storage/emulated/0/net.mechanicalcat.match3/. I'm *still* hazy on the details here but I *believe* that's just an alias for /data/data/net.mechanicalcat.match3/.

The problem is that in both cases the target directory is recursively deleted first - that public data storage is forcefully cleaned. Save games, whatever, are lost.

It's late here, so I've not trawled through the logs to try to determine why the public.mp3 is used: does anyone know? And would you object if I submitted a change to undo it?


      Richard

Richard Jones

unread,
Feb 9, 2013, 7:13:20 AM2/9/13
to python-...@googlegroups.com

On Friday, 8 February 2013 22:51:45 UTC+11, Richard Jones wrote:
I have discovered the cause of the problem. Both use the renpy Java runtime.

pgs4a bundles all of the application data into the private.mp3 archive. This is installed into /data/data/net.mechanicalcat.match3/files/.

python-for-android bundles some of the application into private.mp3 and some into public.mp3. The private data goes into the directory above. The public data goes into the directory defined by getExternalStorageDirectory() which is /storage/emulated/0/net.mechanicalcat.match3/. I'm *still* hazy on the details here but I *believe* that's just an alias for /data/data/net.mechanicalcat.match3/.

The problem is that in both cases the target directory is recursively deleted first - that public data storage is forcefully cleaned. Save games, whatever, are lost.

OK, to continue the conversation with myself...

I still haven't solved this problem. I found the --private switch in build.py so used that to ensure all the game data was included in the private.mp3 file, just like the pgs4a version of the game.

The save game data is still wiped between upgrades though. I'm going to have to look even deeper to see what it is that's different between the renpy implementation in each framework...


     Richard
 
 

Richard Jones

unread,
Feb 12, 2013, 10:16:49 PM2/12/13
to python-...@googlegroups.com
Hi all,

The cause of the deletions on upgrade or reinstall are that python-for-android modified renpy's PythonActivity so the installation directory is recursiveDelete()'ed before installation.

I would like to propose that either:

1. the behaviour be optional and defaulted to off, or
2. the behaviour be limited to only some subdirectory (or directories) of the app's folder so that other contents are not deleted.

The current python-for-android behaviour makes retaining information that is not stored in Shared Preferences very difficult (as I believe sqlite databases created by the Android API are also stored in the application folder.) The only other option I know of involves storing information in the "external" directory - and that is problematic as that files are not deleted on application uninstall.


     Richard

mori b

unread,
Aug 24, 2014, 8:35:17 AM8/24/14
to python-...@googlegroups.com
Hello Richard,
I'll be glad to know if there was an improvement ? or if using the Shared Preferences a valid work-around ?

qua non

unread,
Apr 9, 2015, 3:46:56 PM4/9/15
to python-...@googlegroups.com
Hey folks,

Extremely sorry for having missed this thread all together, this is a valid issue and should be opened on github if it isn't already. @richard there definitely should be a option, that provides you the option to not delete.

--
You received this message because you are subscribed to the Google Groups "Python For Android" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-androi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages