Amaze File Manager:一款基于 Material Design 的开源安卓文件管理器

Amaze File Manager

Amaze File Manager 是一款遵循 Material Design 设计规范的 Android 开源文件管理器。它设计简约、运行流畅,并提供了从基础文件操作到高级网络存储支持的全方位功能。

功能特性

  • 全面的文件操作:支持复制、剪切、粘贴、删除、重命名、创建文件夹等所有基础文件管理操作。
  • 多协议远程支持:无缝集成 FTP、FTPS、SFTP、SMB 等多种网络文件传输协议,方便管理远程服务器文件。
  • 主流云存储集成:支持连接 Google Drive、Dropbox、OneDrive、Box 等主流云存储服务,统一管理云端文件。
  • Material Design 3 界面:采用现代化的 Material You(Material Design 3)设计语言,提供美观且符合直觉的用户体验。
  • 高级文件处理
    • 文件加密/解密:使用 AES 加密算法对文件进行安全加密保护。
    • 压缩包处理:支持查看和提取多种压缩格式(如 ZIP, RAR, 7z, TAR, GZIP, BZIP2 等)的内容。
  • 内置实用工具
    • FTP 服务器:可将您的设备变为一个 FTP 服务器,方便在局域网内共享文件。
    • Root 权限支持:在已获得 Root 权限的设备上,可访问和管理系统目录及文件。
    • 应用管理:查看已安装应用列表,并管理 APK 文件。
  • 可定制化体验:支持多种主题配色、视图模式(列表/网格)以及文件排序规则,满足个性化需求。

安装指南

从 GitHub Releases 安装

  1. 访问本项目的 GitHub Releases 页面。
  2. 下载最新版本的 APK 文件。
  3. 在您的 Android 设备上启用“从未知来源安装应用”的选项。
  4. 使用文件管理器找到下载的 APK 文件并点击安装。

系统要求

  • Amaze v3.8.5:支持 Android 4.0 (Ice Cream Sandwich) 及以上版本。
  • Amaze v4.x.x:仅支持 Android 4.4 (KitKat) 及以上版本。

注意:对于运行 Android 4.4 以下版本的设备,最后的兼容版本是 v3.8.5

使用说明

Amaze File Manager 的核心是提供一个统一且强大的界面来浏览和操作不同来源的文件。

基础文件浏览

启动应用后,您将看到本地存储的目录结构。您可以像使用任何其他文件管理器一样:

  • 点击文件夹进入。
  • 长按文件或文件夹以选择,然后使用底部操作栏进行复制、移动、删除等操作。

添加远程或云存储位置

  1. 点击侧边栏(抽屉菜单)或主界面上的“添加存储”按钮。
  2. 选择您想要添加的存储类型(例如:FTP、SFTP、SMB、Google Drive 等)。
  3. 根据提示输入连接所需的详细信息(如服务器地址、用户名、密码等)。
  4. 连接成功后,新的存储位置将出现在您的侧边栏中,您可以像访问本地文件一样访问它。

使用文件操作

Amaze 支持跨不同存储位置的文件操作。例如,您可以将一个文件从 Google Drive 复制到设备的本地下载文件夹,或者将一个压缩包从 FTP 服务器解压到 SD 卡。

示例:使用 Paste 操作

// 核心操作逻辑封装在 Paste、CopyTask 等类中
// 以下代码片段展示了核心操作的调用思路
val sourcePaths = arrayOf("/storage/emulated/0/Download/myfile.txt")
val operationData = OperationData(
    UtilsHandler.Operation.COPY,
    sourcePaths,
    destinationPath
)
// 将操作数据传递给后台任务执行
utilsHandler.saveToDatabase(operationData)

安全与加密

您可以使用内置的加密功能保护敏感文件。加密后的文件扩展名为 .aze,需要密码才能解密和访问。

核心代码解析

Amaze File Manager 采用模块化设计,代码结构清晰。以下是几个关键模块的简要说明:

1. 文件系统抽象层 (HybridFile, HybridFileParcelable)

这是项目的核心,为本地文件、云文件、远程文件(FTP/SMB)提供了一个统一的抽象接口。

关键类:HybridFileParcelable

/*
 * 代表一个可序列化的文件对象,封装了文件路径、类型、权限、大小和修改日期等信息。
 * 实现了 Parcelable 接口,便于在 Android 组件间传递。
 */
public class HybridFileParcelable extends HybridFile implements Parcelable, ComparableParcelable {
    private long date, size;
    private boolean isDirectory;
    private String permission; // 例如 "rwx"

    public HybridFileParcelable(String path, String permission, long date, long size, boolean isDirectory) {
        super(OpenMode.FILE, path); // 调用父类构造函数
        this.permission = permission;
        this.date = date;
        this.size = size;
        this.isDirectory = isDirectory;
    }

    // Parcelable 实现,用于跨进程/组件传递
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(getPath());
        dest.writeString(permission);
        dest.writeLong(date);
        dest.writeLong(size);
        dest.writeByte((byte) (isDirectory ? 1 : 0));
    }

    // 从 Parcel 重建对象
    protected HybridFileParcelable(Parcel in) {
        super(OpenMode.FILE, in.readString());
        permission = in.readString();
        date = in.readLong();
        size = in.readLong();
        isDirectory = in.readByte() != 0;
    }

    public static final Creator<HybridFileParcelable> CREATOR = new Creator<HybridFileParcelable>() {
        @Override
        public HybridFileParcelable createFromParcel(Parcel in) {
            return new HybridFileParcelable(in);
        }
        @Override
        public HybridFileParcelable[] newArray(int size) {
            return new HybridFileParcelable[size];
        }
    };
}

2. 数据库与数据管理

项目使用 Room 持久化库管理书签、历史记录、远程服务器连接信息等。

工具类数据库操作 (UtilsHandler)

/*
 * 处理应用工具相关的数据库操作,如书签、历史记录、SFTP/SMB连接等。
 */
public class UtilsHandler {
    private UtilitiesDatabase utilitiesDatabase;
    private Context context;

    // 保存一项操作数据到数据库
    public void saveToDatabase(OperationData operationData) {
        switch (operationData.type) {
            case Operation.BOOKMARKS:
                // 将书签数据插入 Room 数据库
                Bookmark bookmark = new Bookmark(operationData.name, operationData.path);
                utilitiesDatabase.bookmarkEntryDao().insert(bookmark);
                break;
            case Operation.SFTP:
                // 保存SFTP服务器连接信息,路径可能经过加密
                SftpEntry sftpEntry = new SftpEntry(
                    operationData.name,
                    operationData.path, // 可能是加密后的URI
                    operationData.hostKey,
                    operationData.sshKeyName,
                    operationData.sshKey
                );
                utilitiesDatabase.sftpEntryDao().insert(sftpEntry);
                break;
            // ... 处理其他操作类型
        }
    }

    // 从数据库获取书签列表
    public List<String[]> getBookmarksList() {
        List<Bookmark> bookmarks = utilitiesDatabase.bookmarkEntryDao().list().blockingGet();
        List<String[]> result = new ArrayList<>();
        for (Bookmark b : bookmarks) {
            result.add(new String[]{b.name, b.path});
        }
        return result;
    }
}

3. 文件复制与移动 (GenericCopyUtil)

这个工具类负责处理跨不同文件源(本地、FTP、云存储)的文件复制操作,使用通道和缓冲区进行高效数据传输。

核心复制方法

/*
 * 提供通用的文件复制功能,支持多种数据源和目标。
 */
public class GenericCopyUtil {
    public static final int DEFAULT_BUFFER_SIZE = 8192;

    // 使用 NIO 通道进行高效复制
    public void doCopy(ReadableByteChannel in, WritableByteChannel out, UpdatePosition updatePosition)
            throws IOException {
        final ByteBuffer buffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE);
        long progress = 0;
        while (in.read(buffer) != -1) {
            buffer.flip();
            out.write(buffer);
            progress += buffer.position();
            updatePosition.updatePosition(progress); // 更新进度回调
            buffer.clear();
        }
    }

    // 使用缓冲流进行复制(适用于非通道接口)
    public void copyFile(BufferedInputStream in, BufferedOutputStream out, UpdatePosition updatePosition)
            throws IOException {
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        long progress = 0;
        int len;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
            progress += len;
            updatePosition.updatePosition(progress); // 更新进度回调
        }
    }
}

4. 压缩文件处理 (Extractor 及其子类)

项目通过一个抽象的 Extractor 类和一系列针对不同压缩格式的实现类(如 ZipExtractor, RarExtractor, SevenZipExtractor, TarGzExtractor 等)来处理压缩文件。

抽象提取器基类

/*
 * 压缩文件内容提取器的抽象基类。
 * 定义了提取流程和与进度监听器的交互接口。
 */
public abstract class Extractor {
    protected Context context;
    protected String filePath, outputPath;
    protected OnUpdate listener;
    protected UpdatePosition updatePosition;

    public Extractor(@NonNull Context context, @NonNull String filePath,
                    @NonNull String outputPath, @NonNull OnUpdate listener,
                    @NonNull UpdatePosition updatePosition) {
        this.context = context;
        this.filePath = filePath;
        this.outputPath = outputPath;
        this.listener = listener;
        this.updatePosition = updatePosition;
    }

    // 提取所有文件
    public void extractEverything() throws IOException {
        extractWithFilter((relativePath, isDir) -> true); // 过滤器允许所有文件
    }

    // 提取特定文件
    public void extractFiles(String[] files) throws IOException {
        HashSet<String> filesToExtract = new HashSet<>(Arrays.asList(files));
        extractWithFilter((relativePath, isDir) -> {
            // 过滤器逻辑:只提取在目标列表中的文件或其父目录
            if (filesToExtract.contains(relativePath)) {
                if (!isDir) filesToExtract.remove(relativePath);
                return true;
            }
            for (String path : filesToExtract) {
                if (relativePath.startsWith(path)) {
                    return true;
                }
            }
            return false;
        });
    }

    // 子类必须实现的具体提取逻辑
    protected abstract void extractWithFilter(@NonNull Filter filter) throws IOException;

    // 进度更新回调接口
    public interface OnUpdate {
        void onStart(long totalBytes, String firstEntryName);
        void onUpdate(String entryPath);
        void onFinish();
        boolean isCancelled();
    }

    // 文件过滤器接口
    protected interface Filter {
        boolean shouldExtract(String relativePath, boolean isDirectory);
    }
}

uADtARBV6Bfrq4LaOaKJxRrZSd7QwVq6oQm5qXuOAc8=
更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
对网络安全、黑客技术感兴趣的朋友可以关注我的安全公众号(网络安全技术点滴分享)

公众号二维码

公众号二维码

posted @ 2025-12-30 23:33  qife  阅读(4)  评论(0)    收藏  举报