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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![allow(dead_code)]
use crate::bson::ObjectId;
use crate::lowlevel::{FFISlice, FromFFI, ToFFI};
use std::fmt::Debug;

/// Represents a Unity Version on the PC
#[derive(Debug)]
pub struct UnityVersion {
    path: Box<str>,
    version: Option<Box<str>>,
    id: ObjectId,
    loaded_from_hub: bool,
}

impl UnityVersion {
    pub fn new(path: Box<str>, version: Box<str>, loaded_from_hub: bool) -> Self {
        Self {
            path,
            version: Some(version),
            loaded_from_hub,
            id: ObjectId::new(),
        }
    }

    pub fn id(&self) -> ObjectId {
        self.id
    }

    pub fn path(&self) -> &str {
        &self.path
    }

    pub fn version(&self) -> Option<&str> {
        self.version.as_deref()
    }

    pub fn loaded_from_hub(&self) -> bool {
        self.loaded_from_hub
    }

    pub fn set_loaded_from_hub(&mut self, loaded_from_hub: bool) {
        self.loaded_from_hub = loaded_from_hub;
    }
}

#[repr(C)]
pub(crate) struct UnityVersionFFI {
    path: FFISlice,
    version: FFISlice,
    id: ObjectId,
    loaded_from_hub: u8,
}

impl FromFFI for UnityVersion {
    type FFIType = UnityVersionFFI;

    unsafe fn from_ffi(ffi: UnityVersionFFI) -> Self {
        Self {
            path: FromFFI::from_ffi(ffi.path),
            version: FromFFI::from_ffi(ffi.version),
            id: ffi.id,
            loaded_from_hub: ffi.loaded_from_hub != 0,
        }
    }
}

impl ToFFI for UnityVersion {
    type FFIType = UnityVersionFFI;

    unsafe fn to_ffi(&self) -> Self::FFIType {
        UnityVersionFFI {
            path: self.path.to_ffi(),
            version: self.version.as_deref().to_ffi(),
            id: self.id,
            loaded_from_hub: self.loaded_from_hub as u8,
        }
    }
}