-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
441 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/org/cryptomator/domain/exception/IllegalFileNameException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.cryptomator.domain.exception; | ||
|
||
public class IllegalFileNameException extends BackendException { | ||
|
||
public IllegalFileNameException() { | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
domain/src/main/java/org/cryptomator/domain/usecases/CalculateFileHash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.cryptomator.domain.usecases; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
|
||
import org.cryptomator.domain.exception.BackendException; | ||
import org.cryptomator.domain.exception.FatalBackendException; | ||
import org.cryptomator.generator.Parameter; | ||
import org.cryptomator.generator.UseCase; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.security.DigestInputStream; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
@UseCase | ||
public class CalculateFileHash { | ||
|
||
private final Context context; | ||
private final Uri uri; | ||
|
||
CalculateFileHash(final Context context, @Parameter Uri uri) { | ||
this.context = context; | ||
this.uri = uri; | ||
} | ||
|
||
public byte[] execute() throws BackendException, FileNotFoundException { | ||
try { | ||
MessageDigest digest = MessageDigest.getInstance("MD5"); | ||
try (InputStream inputStream = context.getContentResolver().openInputStream(uri); // | ||
DigestInputStream dis = new DigestInputStream(inputStream, digest)) { | ||
byte[] buffer = new byte[4096]; | ||
while (dis.read(buffer) != -1) { | ||
} | ||
return digest.digest(); | ||
} catch (IOException e) { | ||
throw new FatalBackendException(e); | ||
} | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
domain/src/main/java/org/cryptomator/domain/usecases/PrepareDownloadFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.cryptomator.domain.usecases; | ||
|
||
import android.content.ContentResolver; | ||
import android.content.Context; | ||
import android.net.Uri; | ||
import android.provider.DocumentsContract; | ||
|
||
import org.cryptomator.domain.CloudFile; | ||
import org.cryptomator.domain.exception.BackendException; | ||
import org.cryptomator.domain.exception.FatalBackendException; | ||
import org.cryptomator.domain.exception.IllegalFileNameException; | ||
import org.cryptomator.domain.exception.NoSuchCloudFileException; | ||
import org.cryptomator.generator.Parameter; | ||
import org.cryptomator.generator.UseCase; | ||
import org.cryptomator.util.file.MimeType; | ||
import org.cryptomator.util.file.MimeTypes; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@UseCase | ||
public class PrepareDownloadFiles { | ||
|
||
private final Context context; | ||
private final MimeTypes mimeTypes; | ||
private final List<CloudFile> filesToExport; | ||
private final Uri parentUri; | ||
private final ContentResolver contentResolver; | ||
private final CloudNodeRecursiveListing cloudNodeRecursiveListing; | ||
|
||
private List<DownloadFile> downloadFiles = new ArrayList<>(); | ||
|
||
PrepareDownloadFiles(Context context, MimeTypes mimeTypes, @Parameter List<CloudFile> filesToExport, @Parameter Uri parentUri, @Parameter CloudNodeRecursiveListing cloudNodeRecursiveListing) { | ||
this.context = context; | ||
this.mimeTypes = mimeTypes; | ||
this.filesToExport = filesToExport; | ||
this.parentUri = parentUri; | ||
this.contentResolver = context.getContentResolver(); | ||
this.cloudNodeRecursiveListing = cloudNodeRecursiveListing; | ||
} | ||
|
||
List<DownloadFile> execute() throws BackendException, FileNotFoundException { | ||
downloadFiles = prepareFilesForExport(filesToExport, parentUri); | ||
for (CloudFolderRecursiveListing folderRecursiveListing : cloudNodeRecursiveListing.getFoldersContent()) { | ||
prepareFolderContentForExport(folderRecursiveListing, parentUri); | ||
} | ||
return downloadFiles; | ||
} | ||
|
||
private List<DownloadFile> prepareFilesForExport(List<CloudFile> filesToExport, Uri parentUri) throws NoSuchCloudFileException, FileNotFoundException, IllegalFileNameException { | ||
List<DownloadFile> downloadFiles = new ArrayList<>(); | ||
for (CloudFile cloudFile : filesToExport) { | ||
DownloadFile downloadFile = createDownloadFile(cloudFile, parentUri); | ||
downloadFiles.add(downloadFile); | ||
} | ||
return downloadFiles; | ||
} | ||
|
||
private void prepareFolderContentForExport(CloudFolderRecursiveListing folderRecursiveListing, Uri parentUri) throws FileNotFoundException, NoSuchCloudFileException, IllegalFileNameException { | ||
Uri createdFolder = createFolder(parentUri, folderRecursiveListing.getParent().getName()); | ||
if (createdFolder != null) { | ||
downloadFiles.addAll(prepareFilesForExport(folderRecursiveListing.getFiles(), createdFolder)); | ||
for (CloudFolderRecursiveListing childFolder : folderRecursiveListing.getFolders()) { | ||
prepareFolderContentForExport(childFolder, createdFolder); | ||
} | ||
} else { | ||
throw new FatalBackendException("Failed to create parent folder for export"); | ||
} | ||
} | ||
|
||
private Uri createFolder(Uri parentUri, String folderName) throws NoSuchCloudFileException { | ||
try { | ||
return DocumentsContract.createDocument(contentResolver, parentUri, DocumentsContract.Document.MIME_TYPE_DIR, folderName); | ||
} catch (FileNotFoundException e) { | ||
throw new NoSuchCloudFileException("Creating folder failed"); | ||
} | ||
} | ||
|
||
private DownloadFile createDownloadFile(CloudFile file, Uri documentUri) throws NoSuchCloudFileException, IllegalFileNameException { | ||
try { | ||
return new DownloadFile.Builder().setDownloadFile(file).setDataSink(contentResolver.openOutputStream(createNewDocumentUri(documentUri, file.getName()))).build(); | ||
} catch (FileNotFoundException e) { | ||
throw new NoSuchCloudFileException(file.getName()); | ||
} | ||
} | ||
|
||
private Uri createNewDocumentUri(Uri parentUri, String fileName) throws IllegalFileNameException, NoSuchCloudFileException { | ||
MimeType mimeType = mimeTypes.fromFilename(fileName); | ||
if (mimeType == null) { | ||
mimeType = MimeType.APPLICATION_OCTET_STREAM; | ||
} | ||
try { | ||
Uri documentUri = DocumentsContract.createDocument(context.getContentResolver(), parentUri, mimeType.toString(), fileName); | ||
if (documentUri == null) { | ||
throw new IllegalFileNameException(); | ||
} | ||
return documentUri; | ||
} catch (FileNotFoundException e) { | ||
throw new NoSuchCloudFileException(fileName); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
- Hub-Unterstützung hinzugefügt | ||
- Cryptomator Hub erhält nun die Geräte-ID während der Tresorschlüsselabfrage | ||
- Potenzieller Absturz beim Öffnen großer Dateien und Exportieren großer Ordner behoben |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
- Add Hub support | ||
- Cryptomator Hub now receives the Device ID during vault key retrieval | ||
- Fixed potential crash when handling large files and exporting large folders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<ul> | ||
<li>Add Hub support</li> | ||
<li>Cryptomator Hub now receives the Device ID during vault key retrieval</li> | ||
<li>Fixed potential crash when handling large files and exporting large folders</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
...entation/src/main/java/org/cryptomator/presentation/exception/IllegalFileNameException.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.