Skip to content

Commit

Permalink
improved handling of windows style linked attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
mickstar committed Jul 7, 2020
1 parent fe1723a commit de107cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,13 @@ class AttachmentStorageManager @Inject constructor(
// if it doesn't, return to the root path, and repeat for the next item in the list.


val itemPath = item.data["path"] ?: ""
var itemPath = item.data["path"] ?: ""
// do some transformations for windows style paths
// e.g C:\\Users\\michael\\file.txt -> C:/Users/michael/file.txt
itemPath = itemPath.replace("\\", "/")
val directories = itemPath.split("/")
if (storageMode == StorageMode.CUSTOM) {
for ((index, path) in directories.withIndex()) {
for (index in directories.indices) {
val location = preferenceManager.getCustomAttachmentStorageLocation()
var documentFile = DocumentFile.fromTreeUri(context, Uri.parse(location))
var i = index
Expand All @@ -423,7 +426,7 @@ class AttachmentStorageManager @Inject constructor(
}
} else if (storageMode == StorageMode.EXTERNAL_CACHE) {
// logic using File api is much simpler
for (i in 0..directories.size){
for (i in directories.indices){
var path = directories.slice(i..directories.size-1).joinToString("/")
if (path.first() == '/'){
path = path.slice(1..path.length-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ class Item : Parcelable {

// I probably should have just used file extensions from the beginning...
if (extension == "UNKNOWN") {
return this.data["filename"]?.split(".")?.last() ?: "UNKNOWN"
val filename = if(this.data.containsKey("filename")){
this.data["filename"]
} else {
this.data["title"]
}
return filename?.split(".")?.last() ?: "UNKNOWN"
}
return extension
}
Expand Down

0 comments on commit de107cc

Please sign in to comment.