1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use serde::{Deserialize, Serialize};
use std::io::Read;
const KIT_PROJECT_FILE: &str = ".kit";
#[derive(Serialize, Deserialize, Debug)]
struct KitModule {
source: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct KitProject {
name: Option<String>,
modules: Option<std::collections::HashMap<String, KitModule>>,
}
impl KitProject {
pub fn new() -> KitProject {
KitProject {
name: None,
modules: None,
}
}
pub fn load_from_file(&mut self) {
let path = std::path::Path::new(KIT_PROJECT_FILE);
if path.exists() {
let mut file = std::fs::File::open(path).unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
let data: KitProject = serde_json::from_str(&contents).unwrap();
self.name = data.name;
self.modules = data.modules;
}
}
pub fn directory_has_project(directory: &std::path::Path) -> bool {
return directory
.join(std::path::Path::new(KIT_PROJECT_FILE))
.exists();
}
}