mirror of https://github.com/M66B/FairEmail.git
Simplification
This commit is contained in:
parent
8482338f2b
commit
125a47efd8
|
@ -566,7 +566,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
if (TextUtils.isEmpty(fname))
|
||||
return uri;
|
||||
|
||||
File dir = Helper.ensureExists(new File(getFilesDir(), "shared"));
|
||||
File dir = Helper.ensureExists(getFilesDir(), "shared");
|
||||
File file = new File(dir, fname);
|
||||
|
||||
Log.i("Copying shared file to " + file);
|
||||
|
|
|
@ -183,7 +183,7 @@ public class ActivityEML extends ActivityBase {
|
|||
if (uri == null)
|
||||
throw new FileNotFoundException();
|
||||
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "shared"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "shared");
|
||||
File file = new File(dir, "email.eml");
|
||||
|
||||
Helper.copy(context, uri, file);
|
||||
|
|
|
@ -132,7 +132,7 @@ public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.
|
|||
if (certificate == null)
|
||||
return null;
|
||||
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "shared"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "shared");
|
||||
String name = Helper.sanitizeFilename(certificate.email);
|
||||
File file = new File(dir, name + ".pem");
|
||||
Helper.writeText(file, certificate.getPem());
|
||||
|
|
|
@ -4105,7 +4105,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
response.setMethod(Method.REPLY);
|
||||
response.addEvent(ev);
|
||||
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "calendar"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "calendar");
|
||||
File ics = new File(dir, message.id + ".ics");
|
||||
response.write(ics);
|
||||
|
||||
|
@ -6389,7 +6389,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
|
||||
File source = EntityMessage.getFile(context, id);
|
||||
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "shared"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "shared");
|
||||
File target = new File(dir, id + ".html");
|
||||
|
||||
Helper.copy(source, target);
|
||||
|
|
|
@ -186,7 +186,7 @@ public class CloudSync {
|
|||
|
||||
private static Long updateSyncdata(Context context) throws IOException, JSONException {
|
||||
DB db = DB.getInstance(context);
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "syncdata"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "syncdata");
|
||||
|
||||
Long last = null;
|
||||
|
||||
|
@ -352,7 +352,7 @@ public class CloudSync {
|
|||
private static void receiveRemoteData(Context context, String user, String password, long lrevision, long rrevision, JSONObject jstatus)
|
||||
throws JSONException, GeneralSecurityException, IOException, InvalidCipherTextException {
|
||||
DB db = DB.getInstance(context);
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "syncdata"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "syncdata");
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean cloud_receive = prefs.getBoolean("cloud_receive", false);
|
||||
|
||||
|
|
|
@ -357,7 +357,7 @@ public class ContactInfo {
|
|||
|
||||
final String domain = d.toLowerCase(Locale.ROOT);
|
||||
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "favicons"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "favicons");
|
||||
|
||||
try {
|
||||
// check cache
|
||||
|
@ -548,7 +548,7 @@ public class ContactInfo {
|
|||
String tag = (TextUtils.isEmpty(info.email) ? name : info.email);
|
||||
String etag = (TextUtils.isEmpty(info.email) ? Helper.sanitizeFilename(name + "@name") : ekey);
|
||||
if (info.bitmap == null && generated && !TextUtils.isEmpty(tag)) {
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "generated"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "generated");
|
||||
File[] files = dir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
|
|
|
@ -172,7 +172,7 @@ public class EntityAttachment {
|
|||
}
|
||||
|
||||
static File getFile(Context context, long id, String name) {
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "attachments"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "attachments");
|
||||
String filename = Long.toString(id);
|
||||
if (!TextUtils.isEmpty(name))
|
||||
filename += "." + Helper.sanitizeFilename(name);
|
||||
|
|
|
@ -619,8 +619,8 @@ public class EntityMessage implements Serializable {
|
|||
}
|
||||
|
||||
static File getFile(Context context, Long id) {
|
||||
File root = Helper.ensureExists(new File(context.getFilesDir(), "messages"));
|
||||
File dir = Helper.ensureExists(new File(root, "D" + (id / 1000)));
|
||||
File root = Helper.ensureExists(context.getFilesDir(), "messages");
|
||||
File dir = Helper.ensureExists(root, "D" + (id / 1000));
|
||||
return new File(dir, id.toString());
|
||||
}
|
||||
|
||||
|
@ -644,12 +644,12 @@ public class EntityMessage implements Serializable {
|
|||
}
|
||||
|
||||
File getFile(Context context, int revision) {
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "revision"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "revision");
|
||||
return new File(dir, id + "." + revision);
|
||||
}
|
||||
|
||||
File getRefFile(Context context) {
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "references"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "references");
|
||||
return new File(dir, id.toString());
|
||||
}
|
||||
|
||||
|
@ -658,7 +658,7 @@ public class EntityMessage implements Serializable {
|
|||
}
|
||||
|
||||
static File getRawFile(Context context, Long id) {
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "raw"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "raw");
|
||||
return new File(dir, id + ".eml");
|
||||
}
|
||||
|
||||
|
|
|
@ -3562,7 +3562,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
});
|
||||
snackbar.show();
|
||||
} else {
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "photo"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "photo");
|
||||
File file = new File(dir, working + "_" + new Date().getTime() + ".jpg");
|
||||
try {
|
||||
photoURI = FileProviderEx.getUri(context, BuildConfig.APPLICATION_ID, file);
|
||||
|
@ -3874,7 +3874,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
throw new IllegalArgumentException(context.getString(R.string.title_from_missing));
|
||||
|
||||
// Create files
|
||||
File tmp = Helper.ensureExists(new File(context.getFilesDir(), "encryption"));
|
||||
File tmp = Helper.ensureExists(context.getFilesDir(), "encryption");
|
||||
File input = new File(tmp, draft.id + "_" + session + ".pgp_input");
|
||||
File output = new File(tmp, draft.id + "_" + session + ".pgp_output");
|
||||
|
||||
|
@ -4242,7 +4242,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean check_certificate = prefs.getBoolean("check_certificate", true);
|
||||
|
||||
File tmp = Helper.ensureExists(new File(context.getFilesDir(), "encryption"));
|
||||
File tmp = Helper.ensureExists(context.getFilesDir(), "encryption");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
|
|
|
@ -8828,7 +8828,7 @@ public class FragmentMessages extends FragmentBase
|
|||
OutputStream out = null;
|
||||
boolean inline = false;
|
||||
|
||||
File tmp = Helper.ensureExists(new File(context.getFilesDir(), "encryption"));
|
||||
File tmp = Helper.ensureExists(context.getFilesDir(), "encryption");
|
||||
File plain = new File(tmp, message.id + ".pgp_out");
|
||||
|
||||
// Find encrypted data
|
||||
|
|
|
@ -1839,7 +1839,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
|
|||
.remove("cloud_last_sync")
|
||||
.apply();
|
||||
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "syncdata"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "syncdata");
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null)
|
||||
for (File file : files) {
|
||||
|
|
|
@ -2641,17 +2641,18 @@ public class Helper {
|
|||
|
||||
private static final Map<File, Boolean> exists = new HashMap<>();
|
||||
|
||||
static File ensureExists(File dir) {
|
||||
static File ensureExists(File parent, String subdir) {
|
||||
parent.mkdir();
|
||||
|
||||
File dir = new File(parent, subdir);
|
||||
dir.mkdir();
|
||||
|
||||
synchronized (exists) {
|
||||
if (exists.containsKey(dir))
|
||||
return dir;
|
||||
exists.put(dir, true);
|
||||
}
|
||||
|
||||
// CASA: External storage as well
|
||||
if (!dir.exists() && Log.jni_safe_mkdirs(dir))
|
||||
throw new IllegalArgumentException("Failed to create directory");
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
|
|
@ -791,7 +791,7 @@ class ImageHelper {
|
|||
|
||||
@NonNull
|
||||
static File getCacheFile(Context context, long id, String source, String extension) {
|
||||
File dir = Helper.ensureExists(new File(context.getFilesDir(), "images"));
|
||||
File dir = Helper.ensureExists(context.getFilesDir(), "images");
|
||||
return new File(dir, id + "_" + Math.abs(source.hashCode()) + extension);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue