3 个版本 (破坏性更新)
0.3.0 | 2024年1月27日 |
---|---|
0.2.0 | 2024年1月24日 |
0.1.0 | 2024年1月17日 |
#99 in Windows API
每月 26 次下载
39KB
642 代码行
Windows File Info - Windows 实体检查器
此 crate 用于以开发者友好的方式收集关于 Windows 实体(存档、目录或重解析点/符号链接)的有用信息。
此 crate 是 linux-file-info crate 的并行 crate,我为其开发了在 Linux 上处理相同功能的功能。如果您需要 Linux 的实体检查器,请查看该 crate。
虽然 Windows 和 Linux 很不同,但这个 crate 以不同的方式做了同样的事情,并且代码量更多。还添加了一些专门为 Windows 内核添加的功能。
当前情况:根据我的测试,在当前情况下,如果没有许多实体要搜索和索引,最重要的函数 current_folder_info()
、other_folder_info()
和 entity_info()
的运行速度大约为 500 毫秒。对于 entity_info()
函数始终如此,而对于 current_folder_info()
函数大多数时候如此。如果有大约 50-60 个实体,函数的运行速度减半。
您可以通过运行单个测试来检查它,我为这三个函数添加了计时器。
关于未来:为了优化这个crate:可能我们需要更广泛地分布逻辑,或者用不同的语言(如zig或C++)编写并创建Rust绑定。我的第一个计划是用lifetimes来优化这个crate,如果还不够,我的备用计划是用zig重写这个crate,在此之前,请谨慎使用这个crate,它可能会消耗过多的内存并运行缓慢。
如果您喜欢这个crate,请在该github仓库给它一个star。
当您使用这个crate时,它会返回这种类型的结构体。
#[cfg(target_os = "windows")]
#[derive(Debug, Clone)]
pub struct WindowsEntity {
pub mode: Vec<String>, // which permissions that entity has
pub types: Vec<String>, // which types that entity has, in windows, an entity can be archive, directory and reparse point or symlink in the same time
pub owner: String, // owning user of that entity
pub last_write_time: String,
pub name: String, // name of that entity
pub creation_time: String,
pub attributes: String,
pub last_access_time: String,
pub size: i32, // as bytes
pub absolute_path: String
}
示例用法
use win_file_info::*;
fn main(){
// get your current user:
let current_user = get_current_user();
// get entities of you current working folder:
let current_folder = current_folder_info();
// get your user folder's entities:
let format_user_path = format!("C:\\Users\\{}", current_user);
let your_user_folder = other_folder_info(&format_user_path).unwrap();
// get the info of "cargo.exe" entity:
let cargo_path = format!("C:\\Users\\{}\\.cargo\\bin\\cargo.exe", current_user);
let get_cargo_exe_entity = entity_info(&cargo_path).unwrap();
// assuming you have a windows path with only one backslash on every level and you want to format it to make
// 2 backslash at every path level. if it returns from a variable, you can use it directly but if you want to
// give it via hardcoding, you have to write it with two backslash, because rust understands one backslash as
// escape sequence. Also because of that if you have that path already it's pointless to use that function, but
// for example, if you used "std::env::current_dir" function it returns windows paths with only one backslash,
// you can use it:
let current_directory_path = std::env::current_dir().unwrap();
let current_directory_path = current_directory_path.as_path().to_str().unwrap();
let format_the_windows_path = windows_path_two_backslash(current_directory_path);
// or if you want to have a path with only one backslash and you have a path that has two backslash, you can use that function:
let format_desktop_path = format!("C:\\\\Users\\\\{}\\\\Desktop", current_user);
let format_the_windows_path = windows_path_one_backslash(&format_desktop_path);
// checking the entity type:
let is_users_folder_a_directory = is_directory("C:\\Users");
let is_users_folder_a_archive = is_archive("C:\\Users");
let is_users_folder_a_reparse_point_or_symlink = is_reparse_point_or_symlink("C:\\Users");
// in windows, entities can be both directory, archive or reparse point or symlink, because of that we have
// functions which checks all situations. And since, "OneDrive" folder has all 3 of that types, we use it as
// example:
let format_one_drive_path = format!("C:\\\\Users\\\\{}\\\\OneDrive", current_user);
let mixed_types_one = is_directory_and_archive(&format_one_drive_path);
let mixed_types_two = is_directory_and_reparse_point_or_symlink(&format_one_drive_path);
let mixed_types_three = is_archive_and_reparse_point_or_symlink(&format_one_drive_path);
let mixed_types_four = is_directory_and_archive_and_reparse_point_or_symlink(&format_one_drive_path);
}