Skip to content

Commit

Permalink
Fix preferences migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishiranu committed Jun 17, 2021
1 parent 6fe2826 commit 00c894f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/com/mishiranu/dashchan/content/Preferences.java
Expand Up @@ -44,20 +44,22 @@ public class Preferences {
static {
MainApplication application = MainApplication.getInstance();
if (application.isMainProcess()) {
// Rename preferences file
String oldName = application.getPackageName() + "_preferences";
File oldFile = getPreferencesFile(application, oldName);
File newFile = getPreferencesFile(application, PREFERENCES_NAME);
if (oldFile.exists()) {
File newBackupFile = new File(newFile.getParentFile(), newFile.getName() + ".bak");
if (!newFile.exists() && !newBackupFile.exists()) {
// Rename preferences file
File oldFile = getPreferencesFile(application, application.getPackageName() + "_preferences");
File oldBackupFile = new File(oldFile.getParentFile(), oldFile.getName() + ".bak");
if (oldBackupFile.exists()) {
File newBackupFile = new File(newFile.getParentFile(), newFile.getName() + ".bak");
oldBackupFile.renameTo(newBackupFile);
}
oldFile.renameTo(newFile);
if (oldFile.exists()) {
oldFile.renameTo(newFile);
}
}
File restoreFile = getPreferencesFile(application, PREFERENCES_RESTORE_NAME);
if (restoreFile.exists()) {
newBackupFile.delete();
restoreFile.renameTo(newFile);
}
PREFERENCES = new SharedPreferences(application, PREFERENCES_NAME);
Expand Down

0 comments on commit 00c894f

Please sign in to comment.