2026-05-16 21:10:50 +02:00
|
|
|
// <Kira Installer - universal Linux installer.>
|
|
|
|
|
// Copyright (C) <2026> <Kira Foundation>
|
2026-04-18 19:02:46 +02:00
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
2026-04-18 19:02:46 +02:00
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
2026-04-18 19:02:46 +02:00
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2026-04-18 19:02:46 +02:00
|
|
|
|
|
|
|
|
/*
|
2026-05-16 21:10:50 +02:00
|
|
|
This file contains basic enums and structs to be used with stages.
|
|
|
|
|
*/
|
2026-04-16 00:29:43 +02:00
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum ConfigValue {
|
|
|
|
|
String(String),
|
|
|
|
|
I64(i64),
|
|
|
|
|
U64(u64),
|
|
|
|
|
F64(f64),
|
|
|
|
|
Bool(bool),
|
|
|
|
|
Vector(Vec<ConfigValue>),
|
2026-05-16 21:10:50 +02:00
|
|
|
Dictionary(HashMap<String, ConfigValue>),
|
2026-04-16 00:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct StageResult {
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub config: Option<HashMap<String, ConfigValue>>,
|
2026-05-16 21:10:50 +02:00
|
|
|
pub error: Option<String>,
|
2026-04-16 00:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
impl StageResult {
|
|
|
|
|
pub fn new(name: &str) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
name: name.into(),
|
|
|
|
|
config: None,
|
|
|
|
|
error: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-16 00:29:43 +02:00
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
pub fn add_error(mut self, ex: String) -> Self {
|
|
|
|
|
self.error = Some(ex);
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn add_val(mut self, val_name: &str, conf_val: ConfigValue) -> Self {
|
|
|
|
|
match &mut self.config {
|
|
|
|
|
Some(c) => {
|
|
|
|
|
c.insert(val_name.into(), conf_val);
|
|
|
|
|
}
|
|
|
|
|
None => {
|
|
|
|
|
self.config = Some(HashMap::from([(val_name.into(), conf_val)]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn add_val_string(self, val_name: &str, v: String) -> Self {
|
|
|
|
|
self.add_val(val_name, ConfigValue::String(v))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn add_val_bool(self, val_name: &str, v: bool) -> Self {
|
|
|
|
|
self.add_val(val_name, ConfigValue::Bool(v))
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 00:43:31 +02:00
|
|
|
pub fn add_val_u64(self, val_name: &str, v: u64) -> Self {
|
|
|
|
|
self.add_val(val_name, ConfigValue::U64(v))
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
pub fn get_val(&self, val_name: &str) -> Option<ConfigValue> {
|
|
|
|
|
let v = self
|
|
|
|
|
.config
|
|
|
|
|
.as_ref()
|
|
|
|
|
.and_then(|hm| hm.get(val_name).cloned());
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_val_str(&self, val_name: &str) -> Option<String> {
|
|
|
|
|
match self.get_val(val_name) {
|
|
|
|
|
Some(ConfigValue::String(v)) => Some(v),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_val_bool(&self, val_name: &str) -> Option<bool> {
|
|
|
|
|
match self.get_val(val_name) {
|
|
|
|
|
Some(ConfigValue::Bool(v)) => Some(v),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-16 00:29:43 +02:00
|
|
|
|
|
|
|
|
pub struct KiraConfig {
|
|
|
|
|
pub config_trail: Vec<StageResult>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
impl Default for KiraConfig {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
config_trail: Vec::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 00:56:20 +02:00
|
|
|
impl KiraConfig {
|
|
|
|
|
pub fn get_stage(&self, name: &str) -> Option<StageResult> {
|
2026-05-16 21:10:50 +02:00
|
|
|
self.config_trail
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|v| v.name == name)
|
|
|
|
|
.and_then(|v| Some(v.clone()))
|
|
|
|
|
}
|
|
|
|
|
pub fn pop_last(&mut self) -> Option<StageResult> {
|
|
|
|
|
self.config_trail.pop()
|
|
|
|
|
}
|
|
|
|
|
pub fn push(&mut self, stage_result: StageResult) {
|
|
|
|
|
self.config_trail.push(stage_result);
|
2026-05-03 00:56:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-16 00:29:43 +02:00
|
|
|
|
2026-05-16 21:10:50 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum StageAction {
|
|
|
|
|
Back,
|
|
|
|
|
None,
|
|
|
|
|
Next(StageResult),
|
|
|
|
|
Abort,
|
|
|
|
|
}
|