Recovering password lists (gpg files)

This commit is contained in:
Zeapo 2014-07-27 19:30:14 +01:00
parent a0b8301a49
commit 639d9642c2
4 changed files with 22 additions and 20 deletions

View file

@ -47,7 +47,7 @@ public class PasswordFragment extends Fragment implements AbsListView.OnItemClic
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new PasswordAdapter(getActivity(), new ArrayList<String>());
mAdapter = new PasswordAdapter(getActivity(), PasswordRepository.getFilesList());
}
@Override

View file

@ -1,5 +1,7 @@
package com.zeapo.pwdstore;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.Repository;
@ -8,15 +10,14 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by zeapo on 7/27/14.
*/
public class GitRepo {
public class PasswordRepository {
private static Repository repository;
protected GitRepo(){ }
protected PasswordRepository(){ }
public static Repository getRepository(File localDir) {
if (repository == null) {
@ -38,4 +39,17 @@ public class GitRepo {
public static void closeRepository() {
repository.close();
}
public static ArrayList<String> getFilesList(){
return getFilesList(repository.getWorkTree());
}
public static ArrayList<String> getFilesList(File path){
List<File> files = (List<File>) FileUtils.listFiles(path, new String[] {"gpg"}, true);
ArrayList<String> filePaths = new ArrayList<String>();
for (File file : files) {
filePaths.add(file.getAbsolutePath().replace(repository.getWorkTree().getAbsolutePath(), ""));
}
return filePaths;
}
}

View file

@ -48,9 +48,10 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
super.onResume();
// re-check that there was no change with the repository state
checkLocalRepository();
Repository repository = PasswordRepository.getRepository(new File(getFilesDir() + "/store/.git"));
PasswordRepository.getFilesList();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
@ -115,12 +116,4 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
}
}
public void addItem(View view) {
ListView l = (ListView) findViewById(R.id.pass_list);
PasswordAdapter pad = (PasswordAdapter) l.getAdapter();
pad.add("Something");
}
}

View file

@ -11,10 +11,5 @@
android:layout_height="match_parent"
android:dividerHeight="8dp"
android:divider="@android:color/transparent"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add!"
android:onClick="addItem"/>
</FrameLayout>