v0.6.4: implemented backup functionality for ADB and auto backups
This commit is contained in:
@@ -24,7 +24,9 @@
|
|||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||||
android:allowBackup="false">
|
android:allowBackup="true"
|
||||||
|
android:fullBackupOnly="true"
|
||||||
|
android:backupAgent=".BackupHandler">
|
||||||
<activity
|
<activity
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:name=".ShatteredPixelDungeon"
|
android:name=".ShatteredPixelDungeon"
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Pixel Dungeon
|
||||||
|
* Copyright (C) 2012-2015 Oleg Dolya
|
||||||
|
*
|
||||||
|
* Shattered Pixel Dungeon
|
||||||
|
* Copyright (C) 2014-2017 Evan Debenham
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.shatteredpixel.shatteredpixeldungeon;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.backup.BackupAgent;
|
||||||
|
import android.app.backup.BackupDataInput;
|
||||||
|
import android.app.backup.BackupDataOutput;
|
||||||
|
import android.app.backup.FullBackupDataOutput;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
|
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.journal.Journal;
|
||||||
|
import com.watabou.utils.FileUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
//a handler for android backup requests
|
||||||
|
public class BackupHandler extends BackupAgent {
|
||||||
|
|
||||||
|
//Both of these do nothing. This handler is here to support use of android 4.0+ ADB backup
|
||||||
|
//and android 6.0+ auto-backup. It does not support android 2.2+ key-value backup
|
||||||
|
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {}
|
||||||
|
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@TargetApi(14)
|
||||||
|
public void onFullBackup(FullBackupDataOutput data) {
|
||||||
|
//fully overrides super.onFullBackup, meaning only files specified here are backed up
|
||||||
|
|
||||||
|
//does not backup runs in progress, to prevent cheating.
|
||||||
|
|
||||||
|
//store shared preferences
|
||||||
|
fullBackupFile(new File(getFilesDir().getParent() + "/shared_prefs/"+ ShatteredPixelDungeon.class.getCanonicalName() + ".xml"), data);
|
||||||
|
|
||||||
|
//store game data
|
||||||
|
fullBackupFile(FileUtils.getFile( getFilesDir(), Rankings.RANKINGS_FILE ), data);
|
||||||
|
fullBackupFile(FileUtils.getFile( getFilesDir(), Badges.BADGES_FILE ), data);
|
||||||
|
fullBackupFile(FileUtils.getFile( getFilesDir(), Journal.JOURNAL_FILE ), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -181,7 +181,7 @@ public class Badges {
|
|||||||
loadGlobal();
|
loadGlobal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String BADGES_FILE = "badges.dat";
|
public static final String BADGES_FILE = "badges.dat";
|
||||||
private static final String BADGES = "badges";
|
private static final String BADGES = "badges";
|
||||||
|
|
||||||
private static HashSet<Badge> restore( Bundle bundle ) {
|
private static HashSet<Badge> restore( Bundle bundle ) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class Journal {
|
public class Journal {
|
||||||
|
|
||||||
private static final String JOURNAL_FILE = "journal.dat";
|
public static final String JOURNAL_FILE = "journal.dat";
|
||||||
|
|
||||||
private static boolean loaded = false;
|
private static boolean loaded = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user