forked from akanyan/STARTLINER
feat: use sets etc.
This commit is contained in:
941
rust/Cargo.lock
generated
941
rust/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -147,16 +147,50 @@ pub async fn init_profile(
|
||||
Ok(new_profile)
|
||||
}
|
||||
|
||||
// #[tauri::command]
|
||||
// pub async fn profile_dir(
|
||||
// state: State<'_, Mutex<AppData>>
|
||||
// ) -> Result<PathBuf, &str> {
|
||||
// let appd = state.lock().await;
|
||||
|
||||
// if let Some(p) = &appd.profile {
|
||||
// Ok(p.dir())
|
||||
// } else {
|
||||
// Err("No profile loaded")
|
||||
// }
|
||||
// }
|
||||
|
||||
// the tauri fs plugin doesn't fucking work
|
||||
#[tauri::command]
|
||||
pub async fn profile_dir(
|
||||
state: State<'_, Mutex<AppData>>
|
||||
) -> Result<PathBuf, &str> {
|
||||
pub async fn read_profile_data(
|
||||
state: State<'_, Mutex<AppData>>,
|
||||
path: PathBuf
|
||||
) -> Result<String, String> {
|
||||
let appd = state.lock().await;
|
||||
|
||||
if let Some(p) = &appd.profile {
|
||||
let res = fs::read_to_string(p.dir().join(&path)).await
|
||||
.map_err(|e| format!("Unable to open {:?}: {}", path, e))?;
|
||||
Ok(res)
|
||||
} else {
|
||||
Err("No profile loaded".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn write_profile_data(
|
||||
state: State<'_, Mutex<AppData>>,
|
||||
path: PathBuf,
|
||||
content: String
|
||||
) -> Result<(), String> {
|
||||
let appd = state.lock().await;
|
||||
|
||||
if let Some(p) = &appd.profile {
|
||||
Ok(p.dir())
|
||||
fs::write(p.dir().join(&path), content).await
|
||||
.map_err(|e| format!("Unable to write to {:?}: {}", path, e))?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err("No profile loaded")
|
||||
Err("No profile loaded".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,8 @@ pub async fn run(_args: Vec<String>) {
|
||||
cmd::get_current_profile,
|
||||
cmd::init_profile,
|
||||
cmd::save_profile,
|
||||
cmd::profile_dir,
|
||||
cmd::read_profile_data,
|
||||
cmd::write_profile_data,
|
||||
cmd::startline,
|
||||
cmd::kill,
|
||||
cmd::set_cfg,
|
||||
|
@ -1,4 +1,3 @@
|
||||
use tokio::task::JoinSet;
|
||||
use anyhow::{Result, anyhow};
|
||||
use tokio::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
@ -18,6 +17,14 @@ async fn symlink(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Resul
|
||||
}
|
||||
|
||||
pub async fn line_up(p: &Profile, pkg_hash: String) -> Result<()> {
|
||||
let dir_out = p.dir();
|
||||
|
||||
if dir_out.join("option").exists() {
|
||||
fs::remove_dir_all(dir_out.join("option")).await?;
|
||||
}
|
||||
|
||||
fs::create_dir_all(dir_out.join("option")).await?;
|
||||
|
||||
let hash_path = p.dir().join(".sl-state");
|
||||
let prev_hash = fs::read_to_string(&hash_path).await.unwrap_or_default();
|
||||
if prev_hash != pkg_hash {
|
||||
@ -35,21 +42,14 @@ pub async fn line_up(p: &Profile, pkg_hash: String) -> Result<()> {
|
||||
async fn prepare_packages(p: &Profile) -> Result<()> {
|
||||
let dir_out = p.dir();
|
||||
|
||||
let mut futures = JoinSet::new();
|
||||
if dir_out.join("BepInEx").exists() {
|
||||
futures.spawn(fs::remove_dir_all(dir_out.join("BepInEx")));
|
||||
fs::remove_dir_all(dir_out.join("BepInEx")).await?;
|
||||
}
|
||||
if dir_out.join("option").exists() {
|
||||
futures.spawn(fs::remove_dir_all(dir_out.join("option")));
|
||||
}
|
||||
while let Some(_) = futures.join_next().await {}
|
||||
|
||||
fs::create_dir_all(dir_out.join("option")).await?;
|
||||
|
||||
for m in &p.mods {
|
||||
log::debug!("Preparing {}", m);
|
||||
let (namespace, name) = m.0.split_at(m.0.find("-").expect("Invalid mod definition"));
|
||||
let bpx_dir = util::pkg_dir_of(namespace, &name[1..])
|
||||
let bpx_dir = util::pkg_dir_of(namespace, &name[1..]) // cut the hyphen
|
||||
.join("app")
|
||||
.join("BepInEx");
|
||||
if bpx_dir.exists() {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::collections::BTreeSet;
|
||||
use serde::Deserialize;
|
||||
use crate::pkg::PkgKeyVersion;
|
||||
|
||||
@ -9,5 +10,5 @@ pub struct PackageManifest {
|
||||
pub name: String,
|
||||
pub version_number: String,
|
||||
pub description: String,
|
||||
pub dependencies: Vec<PkgKeyVersion>
|
||||
pub dependencies: BTreeSet<PkgKeyVersion>
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::collections::BTreeSet;
|
||||
use serde::Deserialize;
|
||||
use crate::pkg::PkgKeyVersion;
|
||||
|
||||
@ -19,6 +20,6 @@ pub struct V1Version {
|
||||
pub description: String,
|
||||
pub version_number: String,
|
||||
pub icon: String,
|
||||
pub dependencies: Vec<PkgKeyVersion>,
|
||||
pub dependencies: BTreeSet<PkgKeyVersion>,
|
||||
pub download_url: String,
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
use anyhow::{Result, anyhow, bail};
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{collections::BTreeSet, path::{Path, PathBuf}};
|
||||
use tokio::fs;
|
||||
use crate::{model::{local, rainy}, util};
|
||||
|
||||
@ -10,7 +10,7 @@ use crate::{model::{local, rainy}, util};
|
||||
pub struct PkgKey(pub String);
|
||||
|
||||
// {namespace}-{name}-{version}
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Eq, Hash, PartialEq, PartialOrd, Ord, Clone, Serialize, Deserialize, Display)]
|
||||
pub struct PkgKeyVersion(String);
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
@ -36,7 +36,7 @@ pub enum Kind {
|
||||
pub struct Local {
|
||||
pub version: String,
|
||||
pub path: PathBuf,
|
||||
pub dependencies: Vec<PkgKey>,
|
||||
pub dependencies: BTreeSet<PkgKey>,
|
||||
pub kind: Kind
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ pub struct Remote {
|
||||
pub package_url: String,
|
||||
pub download_url: String,
|
||||
pub deprecated: bool,
|
||||
pub dependencies: Vec<PkgKey>
|
||||
pub dependencies: BTreeSet<PkgKey>
|
||||
}
|
||||
|
||||
impl Package {
|
||||
@ -154,16 +154,16 @@ impl Package {
|
||||
}
|
||||
}
|
||||
|
||||
fn sanitize_deps(mut deps: Vec<PkgKeyVersion>) -> Vec<PkgKey> {
|
||||
fn sanitize_deps(src: BTreeSet<PkgKeyVersion>) -> BTreeSet<PkgKey> {
|
||||
let regex = regex::Regex::new(r"([A-Za-z0-9_]+)-([A-Za-z0-9_]+)-[0-9\.]+$")
|
||||
.expect("Invalid regex");
|
||||
let mut res = BTreeSet::<PkgKey>::new();
|
||||
|
||||
for i in 0..deps.len() {
|
||||
let caps = regex.captures(&deps[i].0)
|
||||
for dep in src {
|
||||
let caps = regex.captures(&dep.0)
|
||||
.expect("Invalid dependency");
|
||||
deps[i] = PkgKeyVersion(format!("{}-{}", caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str()));
|
||||
res.insert(PkgKey(format!("{}-{}", caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str())));
|
||||
}
|
||||
let rv: Vec<PkgKey> = unsafe { std::mem::transmute(deps) };
|
||||
rv
|
||||
res
|
||||
}
|
||||
}
|
@ -73,6 +73,7 @@ impl Profile {
|
||||
log::info!("Written to {}", path.to_string_lossy());
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_cfg(&self, key: &str) -> Result<&serde_json::Value> {
|
||||
self.cfg.get(key)
|
||||
.ok_or_else(|| anyhow::anyhow!("Invalid config entry {}", key))
|
||||
|
Reference in New Issue
Block a user