unity_hub/unity/hub/
module.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Deserialize, Serialize)]
4#[serde(rename_all = "camelCase")]
5pub struct Module {
6 #[serde(flatten)]
7 pub base: uvm_live_platform::Module,
8 #[serde(default)]
9 pub is_installed: bool,
10 #[serde(flatten)]
11 module_backwards_compatible: ModuleBackwardsCompatible,
12}
13
14impl Module {
15 pub fn id(&self) -> &str {
16 &self.base.id()
17 }
18}
19
20#[derive(Debug, Deserialize, Serialize)]
21#[serde(rename_all = "camelCase")]
22pub struct ModuleBackwardsCompatible {
23 rename_from: String,
24 rename_to: String,
25 sync: String,
26 parent: String,
27 visible: bool,
28 preselected: bool,
29 eula_url_1: String,
30 eula_label_1: String,
31 eula_message: String,
32}
33
34impl From<&uvm_live_platform::Module> for ModuleBackwardsCompatible {
35 fn from(value: &uvm_live_platform::Module) -> Self {
36 let (rename_from, rename_to) = value
37 .extracted_path_rename().as_ref()
38 .map(|e| {
39 (
40 e.from.to_path_buf().display().to_string(),
41 e.to.to_path_buf().display().to_string(),
42 )
43 })
44 .unwrap_or(("".to_string(), "".to_string()));
45 let visible = !value.hidden();
46 let preselected = value.pre_selected();
47
48 let (eula_url_1, eula_label_1, eula_message) = value.eula().first().map(|eula| {
49 (eula.release_file.url.to_owned(), eula.label.to_owned(), eula.message.to_owned())
50 }).unwrap_or(("".to_string(), "".to_string(), "".to_string()));
51
52
53 Self {
54 rename_from,
55 rename_to,
56 visible,
57 preselected,
58 sync: "".to_string(),
59 parent: "".to_string(),
60 eula_url_1,
61 eula_label_1,
62 eula_message,
63 }
64 }
65}
66
67impl From<uvm_live_platform::Module> for Module {
68 fn from(mut value: uvm_live_platform::Module) -> Self {
69 value.download_size.as_bytes_representation();
70 value.installed_size.as_bytes_representation();
71 let module_backwards_compatible = ModuleBackwardsCompatible::from(&value);
72 Self {
73 base: value,
74 is_installed: false,
75 module_backwards_compatible
76 }
77 }
78}