use std::path::Path;
use std::collections::HashMap;
use crate::command::CommandQueue;
use crate::command::InitCommand;
use crate::command::InstallCommand;
use crate::builder::InstallerBuilder;
#[derive(Clone)]
pub struct Component
{
pub name: String,
pub version: Option<String>,
pub license: Option<String>,
pub readme: Option<String>
}
pub trait Installer : Send
{
fn init(&mut self, commands: &mut CommandQueue<InitCommand>);
fn get_components(&mut self, cache: &Path) -> Vec<Component>;
fn install_component(&mut self, component: &str, commands: &mut CommandQueue<InstallCommand>);
}
#[derive(Clone, Copy)]
pub enum InstallMethod
{
UserInstall,
SystemInstall
}
pub trait PostInstall : Send
{
fn post_install(&mut self, cache: &Path, content_dir: &Path, bin_dir: &Path);
}
pub trait PostUninstall : Send
{
fn post_uninstall(&mut self, cache: &Path, content_dir: &Path, bin_dir: &Path);
}
pub trait Interface
{
type ErrorType;
fn welcome(&mut self, installer_name: &'static str, installer_version: &'static str, installer_author: &'static str) -> Result<(), Self::ErrorType>;
fn get_install_method(&mut self) -> Result<InstallMethod, Self::ErrorType>;
fn should_uninstall(&self) -> Result<bool, Self::ErrorType>;
fn run_install(&mut self, install: &mut dyn Installer, install_dir: &Path, method: InstallMethod, resources: &HashMap<&'static str, &'static [u8]>) -> Result<(), Self::ErrorType>;
fn run_post_install(&mut self, post_install: &mut dyn PostInstall, install_dir: &Path) -> Result<(), Self::ErrorType>;
fn run_uninstall(&mut self, install: &mut dyn Installer, install_dir: &Path, method: InstallMethod, resources: &HashMap<&'static str, &'static [u8]>) -> Result<(), Self::ErrorType>;
fn run_post_uninstall(&mut self, post_uninstall: &mut dyn PostUninstall, install_dir: &Path) -> Result<(), Self::ErrorType>;
fn error(&mut self, err: Self::ErrorType) -> i32;
fn finish(&mut self) -> i32;
}
pub trait ConstructibleInterface<'a>
{
fn run(builder: InstallerBuilder<'a>) -> i32;
}