-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgmt.rs
77 lines (66 loc) · 1.88 KB
/
mgmt.rs
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
//! Profile and system management operations related to the actual downloading
//! and installing of mods and resources
mod cache;
mod download;
pub mod events;
mod lockfile;
mod modpack;
mod mods;
pub mod server;
mod version;
use std::sync::mpsc::{self, Sender};
use self::events::ProgressEvent;
// Used by client in crate-scoped update fn
pub(crate) use self::lockfile::LockedMod;
pub use self::{cache::CACHE_DIR, mods::update::UpdateInfo};
/// Handles the actual downloading, installing, updating, etc. of the contents
/// of a [`profile`](crate::config::Profile)
#[derive(Debug, Clone)]
pub struct ProfileManager {
channel: EventChannel,
/// Always install/overwrite files without checking if they are already
/// installed
pub force: bool,
/// Don't use cache and download files directly to profile
pub no_cache: bool,
}
impl ProfileManager {
/// Creates a `ProfileManager` that will send [`events`](ProgressEvent) to
/// `sender` during processing
#[inline]
pub fn with_channel(sender: Sender<ProgressEvent>) -> Self {
Self {
channel: EventChannel(sender),
force: false,
no_cache: false,
}
}
/// Creates a new [`ProfileManager`] with no connected
/// [`event`](ProgressEvent) channel
#[inline]
pub fn new() -> Self {
Self::with_channel(mpsc::channel().0)
}
}
impl events::EventSouce for ProfileManager {
#[inline]
fn send(&self, event: ProgressEvent) {
self.channel.send(event);
}
fn send_err(&self, err: crate::Error) {
self.send(ProgressEvent::Error(err));
}
}
impl Default for ProfileManager {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
struct EventChannel(Sender<ProgressEvent>);
impl EventChannel {
#[inline]
pub fn send(&self, event: ProgressEvent) {
let _ = self.0.send(event);
}
}