diff --git a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/AttachmentStorageManager.kt b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/AttachmentStorageManager.kt index 76672241..f035c11b 100644 --- a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/AttachmentStorageManager.kt +++ b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/AttachmentStorageManager.kt @@ -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 @@ -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) diff --git a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt index d9a96563..4d2f2ec4 100644 --- a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt +++ b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt @@ -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 }