Skip to content

Commit

Permalink
Added hacks so that AmazeFilesystem subclasses actually load
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelMess committed Feb 19, 2022
1 parent c0df86a commit d230597
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.amaze.filemanager.filesystem

import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFile
import com.amaze.filemanager.file_operations.filesystem.filetypes.smb.SmbAmazeFilesystem
import com.amaze.filemanager.filesystem.files.FileAmazeFilesystem
import com.amaze.filemanager.filesystem.otg.OtgAmazeFilesystem
import com.amaze.filemanager.filesystem.ssh.SshAmazeFilesystem

/**
* TODO remove this by moving all Filesystem subclasses to file_operations
*/
object FilesystemLoader {
init {
AmazeFile //Loads all of the file_operations Filesystem subclasses
FileAmazeFilesystem
OtgAmazeFilesystem
SmbAmazeFilesystem
SshAmazeFilesystem.INSTANCE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public class HybridFile {

private final DataUtils dataUtils = DataUtils.getInstance();

static {
FilesystemLoader.INSTANCE.toString(); // HACK forces the class to load
}

public HybridFile(OpenMode mode, String path) {
this.path = path;
this.mode = mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ package com.amaze.filemanager.file_operations.filesystem.filetypes

import android.os.Parcel
import android.util.Log
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.box.BoxAmazeFilesystem
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.dropbox.DropboxAmazeFilesystem
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.gdrive.GoogledriveAmazeFilesystem
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.onedrive.OnedriveAmazeFilesystem
import com.amaze.filemanager.file_operations.filesystem.filetypes.smb.SmbAmazeFilesystem
import kotlinx.parcelize.Parceler
import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -117,14 +122,25 @@ import java.util.*
*/
class AmazeFile : Comparable<AmazeFile?> {
companion object {
@JvmStatic
val TAG = AmazeFile::class.java.simpleName
@JvmStatic
private val filesystems: MutableList<AmazeFilesystem> = ArrayList()

@JvmStatic
fun addFilesystem(amazeFilesystem: AmazeFilesystem) {
filesystems.add(amazeFilesystem)
}

init {
BoxAmazeFilesystem
DropboxAmazeFilesystem
GoogledriveAmazeFilesystem
OnedriveAmazeFilesystem

SmbAmazeFilesystem
}

private fun slashify(path: String, isDirectory: Boolean): String {
var p = path
if (File.separatorChar != '/') p = p.replace(File.separatorChar, '/')
Expand Down Expand Up @@ -325,11 +341,18 @@ class AmazeFile : Comparable<AmazeFile?> {
}

private fun loadFilesystem(path: String) {
var loadedAFs = false

for (filesystem in filesystems) {
if (filesystem.isPathOfThisFilesystem(path)) {
fs = filesystem
loadedAFs = true
}
}

if(!loadedAFs) {
Log.e(TAG, "Failed to load a filesystem, did you forget to add the class to the [AmazeFile]'s companion object initialization block?")
}
}
/* -- Path-component accessors -- */
/**
Expand Down

0 comments on commit d230597

Please sign in to comment.