Update progress bar and message progress

This commit is contained in:
J-Jamet committed 2018-05-01 20:03:43 +02:00
1 parent 77614d0c4a
commit cf026e8eaa
14 files changed
+365 -115

No files matched your search

@@ -36,7 +36,7 @@ import com.kunzisoft.keepass.database.load.ImporterFactory;
import com.kunzisoft.keepass.database.save.PwDbOutput;
import com.kunzisoft.keepass.icons.IconDrawableFactory;
import com.kunzisoft.keepass.search.SearchDbHelper;
import com.kunzisoft.keepass.tasks.UpdateStatus;
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.UriUtil;
import java.io.BufferedInputStream;
@@ -99,19 +99,11 @@ public class Database {
loaded = true;
}
public void loadData(Context ctx, InputStream is, String password, InputStream keyInputStream) throws IOException, InvalidDBException {
loadData(ctx, is, password, keyInputStream, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException {
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
mUri = uri;
readOnly = false;
if (uri.getScheme().equals("file")) {
@@ -138,7 +130,7 @@ public class Database {
}
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
InputStream is, kfIs;
try {
is = UriUtil.getUriInputStream(ctx, uri);
@@ -157,14 +149,10 @@ public class Database {
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, new UpdateStatus(), debug);
loadData(ctx, is, password, kfIs, null, debug, 0);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, status, debug, 0);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug, long roundsFix) throws IOException, InvalidDBException {
private void loadData(Context ctx, InputStream is, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException {
BufferedInputStream bis = new BufferedInputStream(is);
if ( ! bis.markSupported() ) {
@@ -178,7 +166,7 @@ public class Database {
bis.reset(); // Return to the start
pm = imp.openDatabase(bis, password, kfIs, status, roundsFix);
pm = imp.openDatabase(bis, password, kfIs, progressTaskUpdater, roundsFix);
if ( pm != null ) {
try {
switch (pm.getVersion()) {
@@ -222,19 +210,23 @@ public class Database {
saveData(ctx, mUri);
}
public void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
if (uri.getScheme().equals("file")) {
String filename = uri.getPath();
File tempFile = new File(filename + ".tmp");
FileOutputStream fos = new FileOutputStream(tempFile);
//BufferedOutputStream bos = new BufferedOutputStream(fos);
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar());
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
pmo.output();
//bos.flush();
//bos.close();
fos.close();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tempFile);
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
if (pmo != null)
pmo.output();
} catch (Exception e) {
throw new IOException("Failed to store database.");
} finally {
if (fos != null)
fos.close();
}
// Force data to disk before continuing
try {
@@ -250,16 +242,18 @@ public class Database {
}
}
else {
OutputStream os;
OutputStream os = null;
try {
os = ctx.getContentResolver().openOutputStream(uri);
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
if (pmo != null)
pmo.output();
} catch (Exception e) {
throw new IOException("Failed to store database.");
} finally {
if (os != null)
os.close();
}
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
pmo.output();
os.close();
}
mUri = uri;
}