diff options
| author | Mohamed Zenadi <mohamed@zenadi.com> | 2015-07-19 12:09:34 +0200 |
|---|---|---|
| committer | Mohamed Zenadi <mohamed@zenadi.com> | 2015-07-19 12:09:58 +0200 |
| commit | ea899faa074ee3162186769218c62d3d254ce4ae (patch) | |
| tree | fdf4979a94027f0b0305d7db0c0e81fccf2e727a /app/src/main/java/com/zeapo/pwdstore/utils | |
| parent | eb65c2283f8b67c98d0eff5891e24696e1533045 (diff) | |
| download | HardenedPass-ea899faa074ee3162186769218c62d3d254ce4ae.tar.gz HardenedPass-ea899faa074ee3162186769218c62d3d254ce4ae.zip | |
fix some issues where the password repository was not initialized
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java index 245d9604..4836c41d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java @@ -1,7 +1,13 @@ package com.zeapo.pwdstore.utils; +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.util.Log; +import com.zeapo.pwdstore.UserPreference; + import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import org.eclipse.jgit.api.Git; @@ -111,6 +117,38 @@ public class PasswordRepository { repository = null; } + public static void initialize(Activity callingActivity) { + File dir = null; + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(callingActivity.getApplicationContext()); + + if (settings.getBoolean("git_external", false)) { + if (settings.getString("git_external_repo", null) != null) { + dir = new File(settings.getString("git_external_repo", null)); + } + } else { + dir = new File(callingActivity.getFilesDir() + "/store"); + } + // temp for debug + if (dir == null) { + Intent intent = new Intent(callingActivity, UserPreference.class); + intent.putExtra("operation", "git_external"); + callingActivity.startActivity(intent); + return; + } + + // uninitialize the repo if the dir does not exist or is absolutely empty + if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) { + settings.edit().putBoolean("repository_initialized", false).apply(); + } + + if (!PasswordRepository.getPasswords(dir).isEmpty()) { + settings.edit().putBoolean("repository_initialized", true).apply(); + } + + // create the repository static variable in PasswordRepository + PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git")); + } + public static ArrayList<File> getFilesList(){ return getFilesList(repository.getWorkTree()); } |
