图库: 书库改文件管理器模型 + 关闭缩略图 + 根锁定/无卡容错(M18)

用户反馈四件事一起改:
- 「目录里有一张图就被当成最终目录」→ 取消「目录含图=一本书」全部链路
  (探测/页数/封面/续读角标/懒算 worker/sr2 补位),列表 = 目录 + 图片 +
  .cbz/.zip(目录优先、组内自然序)。点目录=进入(空目录也进),点图片=
  mr_reader_open_dir_at(当前目录, 图片自然序下标),点档案册=打开档案册。
- 「文件夹浏览特别卡」→ 删除缩略图线程/磁盘 bmp 缓存/LRU/解码路径与行内
  缩略图;首帧只做一次 opendir/readdir+lstat,副标题(类型·大小)扫描期
  生成一次,行合成/滚动/点击零 IO 零格式化;去掉逐行 snap(自由滚动手感)。
  2000 项目录扫描 ~2.8ms(opendir=1, lstat=2000),行合成 2.78ms/200 万次
  (宿主实测;旧实现 2000 项 entry 含 512B cover,内存 2.7MB→1.7MB)。
- 「不要访问 SD 卡上级目录」→ 浏览根锁定 MR_ROOT_DIR:删除越根的顶栏
  「上级」/library_go_parent,根隐藏顶栏返回,左缘返回到根=退出 App。
- 「没有 SD 卡不要报错」→ 根不可访问(未插卡/挂载失败/根是文件)时友好空态
  「未检测到 SD 卡」+ 顶栏刷新/重进页面重试;子目录不可读才弹提示横幅。

集成陷阱:书库图片下标与阅读器目录册共享同一套过滤器(隐藏项/图片扩展名/
普通文件/符号链接)与 mr_natural_cmp,test_browse_lazy 直接对比
mr_dir_book_init 顺序,test_open_book_host 断言「点 img10 就开 img10」。

reader 侧 M17 遗留:mr_reader_open_dir_at 在阅读页已激活时先 pop 再 push,
走完整 leave/enter(SDK 对同 view 重复 push 是 no-op 且会压重复 activity)。

回归:run_tests.sh / run_webtoon_tests.sh 全 PASS;交叉构建零警告。
This commit is contained in:
AskaEth committed 2026-11-05 20:26:40 +08:00
1 parent d07b99056f
commit 64336f95d9
16 files changed
+940 -1927

No files matched your search

+41 -26
View File
@@ -1,17 +1,16 @@
/* test_browse_nav.c — 浏览访问放开 / 上溯父目录 / 截断标注(纯 C,无 SDK)。
/* test_browse_nav.c — 浏览模型 / 进入目录 / 截断(纯 C,无 SDK)。
*
* 覆盖(M13 用户要求②):
* N1 访问放开:系统目录(MeowAPPs/MeowData/MeowOS/lost+found)不再隐藏,
* 空目录/无图目录都列出且可进入(scan 返回 0 而不是 -1);
* N2 隐藏项/普通文件/符号链接仍不列(防环、防噪声);
* N3 不可读目录/不存在/不是目录:scan 返回 -1,调用方据此提示并停留;
* N4 上溯父目录:mr_path_parent 可一路走到文件系统 "/"(不再以 TF 卡根为界);
* N5 单目录条目上限:达到 MR_LIB_SCAN_MAX 后截断并置 truncated(行合成给出提示行)。
* 覆盖(M18 文件管理器模型):
* N1 单层列表:目录 + 受支持图片 + 档案册(cbz/zip)都成行,目录优先+自然序;
* 系统目录/空目录/无图目录都列出且可进入;隐藏项/普通文件/符号链接不列;
* N2 不可读目录/不存在/不是目录:scan 返回 -1,调用方据此显示空态或提示;
* N3 父目录路径推导:mr_path_parent 是纯路径工具(可算到文件系统 "/";
* 浏览越界的限制在 UI 导航层,见 test_browse_ui_host 的根锁定用例);
* N4 单目录条目上限:达到 MR_LIB_SCAN_MAX 后截断并置 truncated(行合成给出提示行)。
*
* 编译(在 tuku/ 下):
* gcc -Wall -Wextra -O1 -I. -I../sdk -DMR_LIBRARY_TEST_HOOKS \
* test/test_browse_nav.c logic/library.c logic/reader.c test/settings_reader_stub.c \
* -pthread -o build/host/test_browse_nav
* test/test_browse_nav.c logic/library.c -pthread -o build/host/test_browse_nav
*/
#include "logic/library.h"
@@ -85,19 +84,20 @@ static const mr_library_entry *find_entry(const mr_library *lib, const char *nam
return NULL;
}
/* ---- N1/N2 ---- */
/* ---- N1 ---- */
static void test_open_access(const char *root)
{
mr_library lib;
memset(&lib, 0, sizeof lib);
int n = mr_library_scan(&lib, root, MR_LIB_MAX_DEPTH);
CHECK(n == 7, "root lists 7 dirs (got %d)", n);
CHECK(n == 9, "root lists 9 rows (got %d)", n);
CHECK(lib.truncated == 0, "root not truncated");
static const char *want[7] = {
"book", "empty", "lost+found", "MeowAPPs", "MeowData", "MeowOS", "noimg"
static const char *want[9] = {
"book", "empty", "lost+found", "MeowAPPs", "MeowData", "MeowOS", "noimg",
"album.cbz", "loose.png"
};
for (int i = 0; i < 7 && i < lib.count; i++)
for (int i = 0; i < 9 && i < lib.count; i++)
CHECK(strcmp(lib.items[i].name, want[i]) == 0,
"sort[%d]=%s got %s", i, want[i], lib.items[i].name);
@@ -105,11 +105,13 @@ static void test_open_access(const char *root)
CHECK(find_entry(&lib, want[i]) != NULL, "system/empty/noimg dir listed: %s", want[i]);
CHECK(find_entry(&lib, ".hidden") == NULL, "hidden dir excluded");
CHECK(find_entry(&lib, "linkdir") == NULL, "symlink dir excluded");
CHECK(find_entry(&lib, "loose.png") == NULL, "file excluded");
CHECK(find_entry(&lib, "loose.png") != NULL, "loose image listed (clickable)");
CHECK(find_entry(&lib, "album.cbz") != NULL, "archive listed");
CHECK(find_entry(&lib, "readme.txt") == NULL, "plain file excluded");
/* 可进入:每个列出的目录都能被 scan(0 项也算成功,不等于 -1)。 */
char p[MR_PATH_MAX];
for (int i = 0; i < lib.count; i++) {
if (lib.items[i].kind != MR_LIB_KIND_DIR) continue;
mr_library child;
memset(&child, 0, sizeof child);
CHECK(mr_library_scan(&child, lib.items[i].path, MR_LIB_MAX_DEPTH) >= 0,
@@ -117,11 +119,20 @@ static void test_open_access(const char *root)
mr_library_free(&child);
}
char p[MR_PATH_MAX];
joinp(p, sizeof p, root, "book");
mr_library book;
memset(&book, 0, sizeof book);
CHECK(mr_library_scan(&book, p, MR_LIB_MAX_DEPTH) == 1 &&
find_entry(&book, "001.png") != NULL, "dir with images lists the image");
mr_library_free(&book);
joinp(p, sizeof p, root, "MeowOS");
mr_library syslib;
memset(&syslib, 0, sizeof syslib);
CHECK(mr_library_scan(&syslib, p, MR_LIB_MAX_DEPTH) == 1 &&
find_entry(&syslib, "sub") != NULL, "system dir browsable");
CHECK(mr_library_scan(&syslib, p, MR_LIB_MAX_DEPTH) == 2 &&
find_entry(&syslib, "sub") != NULL &&
find_entry(&syslib, "001.png") != NULL, "system dir browsable");
mr_library_free(&syslib);
joinp(p, sizeof p, root, "empty");
@@ -133,13 +144,13 @@ static void test_open_access(const char *root)
mr_library_free(&lib);
}
/* ---- N3 ---- */
/* ---- N2 ---- */
static void test_unreadable(const char *root)
{
mr_library lib;
char p[MR_PATH_MAX];
memset(&lib, 0, sizeof lib);
CHECK(mr_library_scan(&lib, "/no/such/dir/m13", MR_LIB_MAX_DEPTH) == -1, "missing -> -1");
CHECK(mr_library_scan(&lib, "/no/such/dir/m18", MR_LIB_MAX_DEPTH) == -1, "missing -> -1");
CHECK(lib.count == 0 && lib.truncated == 0, "failed scan leaves empty lib");
mr_library_free(&lib);
@@ -160,8 +171,8 @@ static void test_unreadable(const char *root)
}
}
/* ---- N4 ---- */
static void test_up_to_root(void)
/* ---- N3 ---- */
static void test_parent_path(void)
{
char cur[MR_PATH_MAX];
snprintf(cur, sizeof cur, "/usr/data/mnt/sd_0/a/b/c");
@@ -183,10 +194,10 @@ static void test_up_to_root(void)
"root parent stays /");
CHECK(mr_path_parent("/usr/data/mnt/sd_0", up, (int)sizeof up) == 0 &&
strcmp(up, "/usr/data/mnt") == 0,
"TF root can go above mount point: %s", up);
"path helper is root-agnostic: %s", up);
}
/* ---- N5 ---- */
/* ---- N4 ---- */
static void test_truncation(void)
{
CHECK(MR_LIB_SCAN_MAX == 2000, "default cap is 2000 (got %d)", MR_LIB_SCAN_MAX);
@@ -241,6 +252,10 @@ int main(void)
touch_file(p);
joinp(p, sizeof p, root, "loose.png");
touch_file(p);
joinp(p, sizeof p, root, "album.cbz");
touch_file(p);
joinp(p, sizeof p, root, "readme.txt");
touch_file(p);
/* 符号链接目录不参与浏览(有权限才建;建不了不影响其余断言)。 */
char target[MR_PATH_MAX], link[MR_PATH_MAX];
joinp(target, sizeof target, root, "book");
@@ -249,7 +264,7 @@ int main(void)
test_open_access(root);
test_unreadable(root);
test_up_to_root();
test_parent_path();
rm_rf(root);
test_truncation();