mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-04 16:45:09 -05:00
Get rid of StorageFormat
This commit is contained in:
parent
97f493c881
commit
f5c153b405
@ -66,7 +66,6 @@ import com.fsck.k9.mail.internet.MimeUtility;
|
||||
import com.fsck.k9.mail.store.StorageManager;
|
||||
import com.fsck.k9.view.ColorChip;
|
||||
import com.fsck.k9.preferences.StorageExporter;
|
||||
import com.fsck.k9.preferences.StorageFormat;
|
||||
|
||||
|
||||
public class Accounts extends K9ListActivity implements OnItemClickListener, OnClickListener {
|
||||
@ -1173,8 +1172,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
||||
dir.mkdirs();
|
||||
File file = Utility.createUniqueFile(dir, "settings.k9s");
|
||||
mFileName = file.getAbsolutePath();
|
||||
StorageExporter.exportPreferences(Accounts.this, StorageFormat.ENCRYPTED_XML_FILE,
|
||||
mIncludeGlobals, mAccountUuids, mFileName, mEncryptionKey);
|
||||
StorageExporter.exportPreferences(Accounts.this, mIncludeGlobals,
|
||||
mAccountUuids, mFileName, mEncryptionKey);
|
||||
} catch (Exception e) {
|
||||
Log.w(K9.LOG_TAG, "Exception during export", e);
|
||||
return false;
|
||||
|
@ -11,19 +11,15 @@ import android.app.Activity;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.R;
|
||||
|
||||
public class StorageExporter {
|
||||
private static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
||||
private static void exportPreferences(Activity activity, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
||||
try {
|
||||
IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat);
|
||||
if (storageExporter == null) {
|
||||
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null);
|
||||
}
|
||||
IStorageExporter storageExporter = new StorageExporterEncryptedXml();
|
||||
if (storageExporter.needsKey() && encryptionKey == null) {
|
||||
throw new StorageImportExportException("Encryption key required, but none supplied");
|
||||
} else {
|
||||
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey);
|
||||
finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
@ -32,11 +28,11 @@ public class StorageExporter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, String encryptionKey) throws StorageImportExportException {
|
||||
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey);
|
||||
public static void exportPreferences(Activity activity, boolean includeGlobals, Set<String> accountUuids, String fileName, String encryptionKey) throws StorageImportExportException {
|
||||
exportPreferences(activity, includeGlobals, accountUuids, fileName, null, encryptionKey);
|
||||
}
|
||||
|
||||
private static void finishExport(Activity activity, String storageFormat, IStorageExporter storageExporter, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
||||
private static void finishExport(Activity activity, IStorageExporter storageExporter, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
||||
boolean needToClose = false;
|
||||
try {
|
||||
// This needs to be after the password prompt. If the user cancels the password, we do not want
|
||||
@ -52,7 +48,7 @@ public class StorageExporter {
|
||||
PrintWriter pf = new PrintWriter(sw);
|
||||
pf.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
|
||||
pf.println("<k9settings version=\"" + storageFormat + "\">");
|
||||
pf.println("<k9settings version=\"" + 1 + "\">");
|
||||
pf.flush();
|
||||
|
||||
storageExporter.exportPreferences(activity, includeGlobals, accountUuids, os, encryptionKey);
|
||||
|
@ -1,50 +0,0 @@
|
||||
package com.fsck.k9.preferences;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class StorageFormat {
|
||||
// Never, ever re-use these numbers!
|
||||
public static final String ENCRYPTED_XML_FILE = "1";
|
||||
|
||||
public static Map<String, StorageFormat> storageFormatMap = new HashMap<String, StorageFormat>();
|
||||
static {
|
||||
storageFormatMap.put(ENCRYPTED_XML_FILE, new StorageFormat(StorageImporterEncryptedXml.class, StorageExporterEncryptedXml.class, true));
|
||||
}
|
||||
|
||||
public static IStorageImporter createImporter(String storageFormat) throws InstantiationException, IllegalAccessException {
|
||||
StorageFormat storageVersion = storageFormatMap.get(storageFormat);
|
||||
if (storageVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return storageVersion.importerClass.newInstance();
|
||||
}
|
||||
|
||||
public static IStorageExporter createExporter(String storageFormat) throws InstantiationException, IllegalAccessException {
|
||||
StorageFormat storageVersion = storageFormatMap.get(storageFormat);
|
||||
if (storageVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return storageVersion.exporterClass.newInstance();
|
||||
}
|
||||
|
||||
public static Boolean needsKey(String storageFormat) {
|
||||
StorageFormat storageVersion = storageFormatMap.get(storageFormat);
|
||||
if (storageVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return storageVersion.needsKey;
|
||||
}
|
||||
|
||||
|
||||
private final Class <? extends IStorageImporter > importerClass;
|
||||
private final Class <? extends IStorageExporter > exporterClass;
|
||||
private final boolean needsKey;
|
||||
|
||||
private StorageFormat(Class <? extends IStorageImporter > imclass, Class <? extends IStorageExporter > exclass, boolean nk) {
|
||||
importerClass = imclass;
|
||||
exporterClass = exclass;
|
||||
needsKey = nk;
|
||||
}
|
||||
}
|
@ -42,10 +42,7 @@ public class StorageImporter {
|
||||
String storageFormat = dataset.attributes.get("version");
|
||||
Log.i(K9.LOG_TAG, "Got settings file version " + storageFormat);
|
||||
|
||||
IStorageImporter storageImporter = StorageFormat.createImporter(storageFormat);
|
||||
if (storageImporter == null) {
|
||||
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat));
|
||||
}
|
||||
IStorageImporter storageImporter = new StorageImporterEncryptedXml();
|
||||
if (storageImporter.needsKey() && providedEncryptionKey == null) {
|
||||
gatherPassword(activity, storageImporter, dataset, listener);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user