71 lines
1.8 KiB
Rust
71 lines
1.8 KiB
Rust
pub mod fs;
|
|
|
|
use std::{io::BufReader, path::PathBuf};
|
|
|
|
use flate2::read::GzDecoder;
|
|
|
|
use crate::{Data, error::Result};
|
|
|
|
pub trait StorageImpl {
|
|
fn get_revision_metadata(&self, app_state: Data) -> Result<usize>;
|
|
fn store_revision(&self, app_state: Data) -> Result<()>;
|
|
fn retrieve_revision(
|
|
&self,
|
|
app_state: Data,
|
|
revision: usize,
|
|
) -> Result<tar::Archive<GzDecoder<BufReader<std::fs::File>>>>;
|
|
fn unpack_revision(&self, app_state: Data, destination: PathBuf, revision: usize)
|
|
-> Result<()>;
|
|
}
|
|
|
|
pub enum Storage {
|
|
FS(fs::FSStorage),
|
|
}
|
|
|
|
pub const IGNORE_FILES: [&str; 6] = ["assets", "cache", "catpacks", "logs", "meta", "metacache"];
|
|
|
|
impl StorageImpl for Storage {
|
|
fn get_revision_metadata(&self, app_state: Data) -> Result<usize> {
|
|
match self {
|
|
Self::FS(storage) => storage.get_revision_metadata(app_state),
|
|
}
|
|
}
|
|
|
|
fn store_revision(&self, app_state: Data) -> Result<()> {
|
|
match self {
|
|
Self::FS(storage) => storage.store_revision(app_state),
|
|
}
|
|
}
|
|
|
|
fn retrieve_revision(
|
|
&self,
|
|
app_state: Data,
|
|
revision: usize,
|
|
) -> Result<tar::Archive<GzDecoder<BufReader<std::fs::File>>>> {
|
|
match self {
|
|
Self::FS(storage) => storage.retrieve_revision(app_state, revision),
|
|
}
|
|
}
|
|
|
|
fn unpack_revision(
|
|
&self,
|
|
app_state: Data,
|
|
destination: PathBuf,
|
|
revision: usize,
|
|
) -> Result<()> {
|
|
match self {
|
|
Self::FS(storage) => storage.unpack_revision(app_state, destination, revision),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn get_storage_from_env() -> Storage {
|
|
Storage::FS(fs::FSStorage)
|
|
}
|
|
|
|
pub fn base_path_prism() -> PathBuf {
|
|
dirs::data_local_dir()
|
|
.unwrap_or_else(|| PathBuf::from("."))
|
|
.join("PrismLauncher")
|
|
}
|