From 55c7ea778be2f3ce44d88440607ac8d4117e31d2 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Wed, 11 Mar 2026 22:52:11 +0800 Subject: Add dependencies and constants for vault system --- Cargo.lock | 6 ++++ systems/_constants/src/lib.rs | 5 +-- systems/_framework/src/space.rs | 4 +-- systems/_framework/src/space/error.rs | 3 ++ systems/sheet/Cargo.toml | 2 +- systems/sheet/src/sheet.rs | 58 ++++++++++++++++++++++++++++++++++- 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a45ec3..99f68cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2025,8 +2025,13 @@ dependencies = [ name = "vault_system" version = "0.1.0" dependencies = [ + "asset_system", + "config_system", "constants", "framework", + "serde", + "thiserror", + "tokio", ] [[package]] @@ -2598,6 +2603,7 @@ dependencies = [ "constants", "framework", "serde", + "thiserror", "tokio", ] diff --git a/systems/_constants/src/lib.rs b/systems/_constants/src/lib.rs index 1fac6f8..bea8fa8 100644 --- a/systems/_constants/src/lib.rs +++ b/systems/_constants/src/lib.rs @@ -50,8 +50,8 @@ pub mod vault { /// Others #[constants_macros::constants("vault_value")] pub mod values { - c! { INDEX_FILE_SUFFIX = "index" } - c! { INDEX_FILE_SUFFIX_DOT = ".index" } + c! { INDEX_FILE_SUFFIX = "bidx" } + c! { INDEX_FILE_SUFFIX_DOT = ".bidx" } c! { SHEET_FILE_SUFFIX = "sheet" } c! { SHEET_FILE_SUFFIX_DOT = ".sheet" } @@ -95,6 +95,7 @@ pub mod vault { #[constants_macros::constants("vault_dir")] pub mod dirs { c! { REFSHEETS = "ref/" } + c! { MEMBER_ROOT = "_member/" } c! { MEMBER = "_member/{member_name}/" } c! { MEMBER_SHEET_BACKUPS = "_member/{member_name}/backups/" } c! { IGNORE_RULES = "rules/ignore/" } diff --git a/systems/_framework/src/space.rs b/systems/_framework/src/space.rs index c57fa26..79c9b37 100644 --- a/systems/_framework/src/space.rs +++ b/systems/_framework/src/space.rs @@ -1,5 +1,5 @@ use crate::space::error::SpaceError; -use just_fmt::fmt_path::{PathFormatConfig, PathFormatError, fmt_path, fmt_path_custom}; +use just_fmt::fmt_path::{PathFormatConfig, fmt_path, fmt_path_custom}; use std::{ cell::Cell, env::current_dir, @@ -114,7 +114,7 @@ impl Space { /// Set the current directory explicitly. /// /// This clears any cached space directory. - pub fn set_current_dir(&mut self, path: PathBuf) -> Result<(), PathFormatError> { + pub fn set_current_dir(&mut self, path: PathBuf) -> Result<(), SpaceError> { self.update_space_dir(None); self.current_dir = Some(fmt_path(path)?); Ok(()) diff --git a/systems/_framework/src/space/error.rs b/systems/_framework/src/space/error.rs index 50e673f..33ee6e4 100644 --- a/systems/_framework/src/space/error.rs +++ b/systems/_framework/src/space/error.rs @@ -8,6 +8,9 @@ pub enum SpaceError { #[error("IO error: {0}")] Io(#[from] std::io::Error), + + #[error("Other: {0}")] + Other(String), } impl PartialEq for SpaceError { diff --git a/systems/sheet/Cargo.toml b/systems/sheet/Cargo.toml index 5296bf8..7a20b47 100644 --- a/systems/sheet/Cargo.toml +++ b/systems/sheet/Cargo.toml @@ -6,9 +6,9 @@ version.workspace = true [dependencies] hex_display = { path = "../../utils/hex_display" } +asset_system = { path = "../_asset" } constants = { path = "../_constants" } sheet_system_macros = { path = "macros" } -asset_system = { path = "../_asset" } serde.workspace = true tokio.workspace = true diff --git a/systems/sheet/src/sheet.rs b/systems/sheet/src/sheet.rs index e7a130d..5ee2db7 100644 --- a/systems/sheet/src/sheet.rs +++ b/systems/sheet/src/sheet.rs @@ -5,6 +5,7 @@ use std::{ path::{Path, PathBuf}, }; +use asset_system::{RWDataTest, rw::RWData}; use memmap2::Mmap; use serde::{Deserialize, Serialize}; use tokio::fs; @@ -41,7 +42,7 @@ pub struct Sheet { /// Full Sheet information /// /// Used to wrap as a Sheet object for editing and persistence -#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, RWDataTest)] pub struct SheetData { /// All local mappings mappings: HashSet, @@ -549,3 +550,58 @@ impl TryFrom<&[u8]> for SheetData { read_sheet_data(value) } } + +impl RWData for SheetData { + type DataType = SheetData; + + async fn read(path: &PathBuf) -> Result { + let read_data = SheetData::full_read(&mut SheetData::empty(), path).await; + match read_data { + Ok(_) => { + let data = SheetData::full_read(&mut SheetData::empty(), path).await; + match data { + Ok(_) => Ok(SheetData::empty()), + Err(e) => Err(asset_system::error::DataReadError::IoError( + std::io::Error::new(std::io::ErrorKind::Other, e.to_string()), + )), + } + } + Err(e) => Err(asset_system::error::DataReadError::IoError( + std::io::Error::new(std::io::ErrorKind::Other, e.to_string()), + )), + } + } + + async fn write( + data: Self::DataType, + path: &PathBuf, + ) -> Result<(), asset_system::error::DataWriteError> { + let write_data = tokio::fs::write(path, data.as_bytes()).await; + match write_data { + Ok(_) => Ok(()), + Err(e) => Err(asset_system::error::DataWriteError::IoError( + std::io::Error::new(std::io::ErrorKind::Other, e.to_string()), + )), + } + } + + fn test_data() -> Self::DataType { + let sheet = SheetData::empty().pack("sheet"); + let mut sheet = sheet; + sheet + .insert_mapping( + LocalMapping::new( + vec!["Test".to_string(), "File1.png".to_string()], + IndexSource::new(true, 1u32, 1u16), + LocalMappingForward::Version { version: 2u16 }, + ) + .unwrap(), + ) + .unwrap(); + sheet.unpack() + } + + fn verify_data(data_a: Self::DataType, data_b: Self::DataType) -> bool { + data_a == data_b + } +} -- cgit