Skip to main content

FileService

Struct FileService 

Source
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

Source

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.
Source

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

Source

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:

  1. file_name is sanitized (no path traversal, .wav extension required).
  2. file_bytes are validated as a well-formed WAV containing an audible impulse via FileLoaderTrait::validate_ir_wav_bytes.
  3. 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.

Source

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_name fails sanitization (invalid characters or extension).
  • The file does not exist in the custom IR directory.
  • The filesystem deletion fails.
Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,