Repository navigation
Feat/GetServerCustomResources #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ce8c6ea
9b51e29
2ec7636
e6e760d
3ae9f84
ad41b0b
62947a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| use std::fs; | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
|
||
| use super::select_option_path; | ||
| use super::{option_override, option_target, select_option_path, set_option_override, VfsConfig}; | ||
|
|
||
| #[test] | ||
| fn configured_option_directory_wins_when_non_empty() { | ||
|
|
@@ -56,6 +56,71 @@ fn missing_candidates_keep_configured_option_path() { | |
| remove_test_tree(&root); | ||
| } | ||
|
|
||
| #[test] | ||
| fn option_override_redirects_only_the_mounted_subtree() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: 新增测试只直接调用 Prompt for AI agents |
||
| // Given: 一个注册了重定向的自定义 option 根。 | ||
| let config = test_config("override-only-mounted"); | ||
| set_option_override("a9z1", "D:\\cache\\ServerResources.d\\A9Z1"); | ||
|
|
||
| // Then: 该子树的任何路径都指向解压目录——无论游戏走源路径 | ||
| // (`c:\mount\option\...`) 还是 mount 根 (`<option>\...`) 拼路径。 | ||
| let mounted = |rest: &str| { | ||
| std::path::PathBuf::from(format!("D:\\cache\\ServerResources.d\\A9Z1\\{rest}")) | ||
| }; | ||
| assert_eq!( | ||
| option_target(&config, "a9z1\\music\\*"), | ||
| mounted("music\\*") | ||
| ); | ||
| assert_eq!( | ||
| option_target(&config, "a9z1\\data.conf"), | ||
| mounted("data.conf") | ||
| ); | ||
| assert_eq!( | ||
| option_override(&config, "d:\\game\\option\\a9z1\\music"), | ||
| Some(mounted("music")) | ||
| ); | ||
|
|
||
| // 其他 option、option 根本身,以及未挂载的选项,行为完全不变。 | ||
| assert_eq!( | ||
| option_target(&config, "a001\\music"), | ||
| std::path::PathBuf::from("D:\\game\\option\\a001\\music") | ||
| ); | ||
| assert_eq!( | ||
| option_target(&config, ""), | ||
| std::path::PathBuf::from(&config.option) | ||
| ); | ||
| assert_eq!(option_override(&config, "d:\\game\\option\\a001"), None); | ||
| assert_eq!(option_override(&config, "d:\\game\\option"), None); | ||
|
|
||
| set_option_override("a9z1", ""); | ||
| } | ||
|
|
||
| #[test] | ||
| fn clearing_an_override_restores_the_plain_option_root() { | ||
| // Given: 先注册再注销同名重定向。 | ||
| let config = test_config("override-clear"); | ||
| set_option_override("a9z2", "D:\\cache\\A9Z2"); | ||
| set_option_override("a9z2", ""); | ||
|
|
||
| // Then: 完全回到配置的 option 根,行为与没有覆盖时一致。 | ||
| assert_eq!( | ||
| option_target(&config, "a9z2\\*"), | ||
| std::path::PathBuf::from("D:\\game\\option\\a9z2\\*") | ||
| ); | ||
| assert_eq!(option_override(&config, "d:\\game\\option\\a9z2"), None); | ||
| } | ||
|
|
||
| /// 测试用的最小 VFS 配置(`option` 指向游戏目录下的 option) | ||
| fn test_config(_case: &str) -> VfsConfig { | ||
| VfsConfig { | ||
| amfs: "D:\\game\\amfs\\".to_owned(), | ||
| option: "D:\\game\\option\\".to_owned(), | ||
| appdata: "D:\\game\\appdata\\".to_owned(), | ||
| nthome: "C:\\Users\\Default\\".to_owned(), | ||
| allow_amfs_downloads: false, | ||
| } | ||
| } | ||
|
|
||
| fn temporary_directory(case: &str) -> std::path::PathBuf { | ||
| let nonce = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3:
option_source_prefix()返回String,每次调用都会对编译期常量VFS_OPTION(&'static str)做一次堆分配。两个调用点option_root_glob和package_key位于FindFirstFileW/CreateFileW的 IAT detour 路径上,游戏每个文件操作都会走到这里,只为取一个常量而反复分配不值当。返回&'static str即可,调用方的trim_end_matches/format!用法都不受影响。Prompt for AI agents