1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::fs;
4
5#[derive(Serialize, Deserialize, Debug)]
6pub struct ConduitLock {
7 pub version: i32,
8 pub locked_mods: HashMap<String, LockedMod>,
9}
10
11#[derive(Serialize, Deserialize, Debug)]
12pub struct LockedMod {
13 pub id: String,
14 pub version_id: String,
15 pub filename: String,
16 pub url: String,
17 pub hash: String,
18 pub dependencies: Vec<String>,
19}
20
21impl ConduitLock {
22 pub fn load() -> Self {
23 fs::read_to_string("conduit.lock")
24 .ok()
25 .and_then(|content| toml::from_str(&content).ok())
26 .unwrap_or_else(|| ConduitLock {
27 version: 1,
28 locked_mods: HashMap::new(),
29 })
30 }
31
32 #[rustfmt::skip]
33 pub fn save(&self) -> Result<(), Box<dyn std::error::Error>> {
34 let mut content = String::new();
35
36 content.push_str("# ---------------------------------------------------------------------------- #\n");
37 content.push_str("# #\n");
38 content.push_str("# THIS FILE IS AUTOMATICALLY GENERATED #\n");
39 content.push_str("# DO NOT EDIT THIS FILE MANUALLY #\n");
40 content.push_str("# #\n");
41 content.push_str("# ---------------------------------------------------------------------------- #\n");
42 content.push_str("# #\n");
43 content.push_str("# This file contains the precise reproduction information for the project's #\n");
44 content.push_str("# dependencies. Editing it could break your environment synchronization. #\n");
45 content.push_str("# #\n");
46 content.push_str("# ---------------------------------------------------------------------------- #\n\n");
47
48 content.push_str(&toml::to_string_pretty(self)?);
49
50 fs::write("conduit.lock", content)?;
51 Ok(())
52 }
53}