pub struct FileService { /* private fields */ }Expand description
Application service for IR profile discovery, upload, and removal.
FileService is the single authoritative source of truth for which IR
profiles the application knows about. It merges the read-only
default IR set (shipped inside the Tauri bundle) with the
user-managed custom IR set stored in a writable directory.
§Thread safety
FileService holds a Box<dyn FileLoaderTrait> which is Send + Sync,
making FileService itself safe to place in Tauri’s shared-state container.
Implementations§
Source§impl FileService
impl FileService
Sourcepub fn new(
file_loader: Box<dyn FileLoaderTrait>,
resource_root: PathBuf,
custom_ir_directory: PathBuf,
) -> Self
pub fn new( file_loader: Box<dyn FileLoaderTrait>, resource_root: PathBuf, custom_ir_directory: PathBuf, ) -> Self
Creates a new FileService.
file_loader– production or test-double implementation.resource_root– used in release builds to locate bundled resources.custom_ir_directory– path to the user’s custom IR storage folder.
Sourcepub fn get_all_ir_profiles(&self) -> Result<Vec<IrProfileDto>, String>
pub fn get_all_ir_profiles(&self) -> Result<Vec<IrProfileDto>, String>
Returns all available IR profiles, merging default and custom sets.
For each profile the IrProfileDto::is_in_use flag is not populated
here (it is always false). Callers that need accurate is_in_use values
must cross-reference against the running effect chains — this is done by the
[get_all_ir_profiles] Tauri command.
The returned list is sorted alphabetically by IrProfileDto::label.
§Errors
Propagates errors from FileLoaderTrait::list_ir_profile_file_names or
FileLoaderTrait::ensure_directory if the filesystem is inaccessible.
[get_all_ir_profiles]: crate::commands::effect_commands::cabinet_ir::get_all_ir_profiles
Sourcepub fn save_custom_ir_profile(
&self,
file_name: &str,
file_bytes: &[u8],
) -> Result<String, String>
pub fn save_custom_ir_profile( &self, file_name: &str, file_bytes: &[u8], ) -> Result<String, String>
Validates and persists a user-uploaded custom IR file. The following checks are applied before writing:
file_nameis sanitized (no path traversal,.wavextension required).file_bytesare validated as a well-formed WAV containing an audible impulse viaFileLoaderTrait::validate_ir_wav_bytes.- A file with the same name must not already exist in the default IR set — uploading a custom profile that would shadow a default one is rejected.
On success, the sanitized file name (which may differ from file_name only
in surrounding whitespace) is returned so the caller can display it.
§Errors
Returns Err if any validation step fails or the file cannot be written.
Sourcepub fn remove_custom_ir_profile(&self, file_name: &str) -> Result<(), String>
pub fn remove_custom_ir_profile(&self, file_name: &str) -> Result<(), String>
Removes a user-uploaded custom IR file from the custom IR directory.
file_name is sanitized before the path is constructed so that
path-traversal attempts are rejected.
§Errors
file_namefails sanitization (invalid characters or extension).- The file does not exist in the custom IR directory.
- The filesystem deletion fails.
Sourcepub fn default_ir_directory(&self) -> Result<PathBuf, String>
pub fn default_ir_directory(&self) -> Result<PathBuf, String>
Returns the resolved absolute path of the bundled default IR directory.
The resolution strategy differs between debug and release builds; see
resolve_default_ir_directory for details.
Sourcepub fn custom_ir_directory(&self) -> PathBuf
pub fn custom_ir_directory(&self) -> PathBuf
Returns the writable custom IR directory path.
The directory is not guaranteed to exist yet — call
FileLoaderTrait::ensure_directory before writing to it.