forked from kamiyaa/joshuto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_operation.rs
112 lines (98 loc) · 2.59 KB
/
file_operation.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#[derive(Clone, Copy, Debug)]
pub enum FileOperation {
Cut,
Copy,
Symlink { relative: bool },
Delete,
}
impl FileOperation {
pub fn actioning_str(&self) -> &'static str {
match *self {
Self::Cut => "Moving",
Self::Copy => "Copying",
Self::Symlink { .. } => "Symlinking",
Self::Delete => "Deleting",
}
}
pub fn actioned_str(&self) -> &'static str {
match *self {
Self::Cut => "moved",
Self::Copy => "copied",
Self::Symlink { .. } => "symlinked",
Self::Delete => "deleted",
}
}
}
impl std::fmt::Display for FileOperation {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Cut => write!(f, "Cut"),
Self::Copy => write!(f, "Copy"),
Self::Symlink { relative } => write!(f, "Symlink --relative={}", relative),
Self::Delete => write!(f, "Delete"),
}
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct FileOperationOptions {
// cut, copy
pub overwrite: bool,
pub skip_exist: bool,
// delete
pub permanently: bool,
}
impl std::fmt::Display for FileOperationOptions {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"overwrite={} skip_exist={}",
self.overwrite, self.skip_exist
)
}
}
#[derive(Clone, Debug)]
pub struct FileOperationProgress {
_kind: FileOperation,
_files_processed: usize,
_total_files: usize,
_bytes_processed: u64,
_total_bytes: u64,
}
impl FileOperationProgress {
pub fn new(
_kind: FileOperation,
_files_processed: usize,
_total_files: usize,
_bytes_processed: u64,
_total_bytes: u64,
) -> Self {
Self {
_kind,
_files_processed,
_total_files,
_bytes_processed,
_total_bytes,
}
}
pub fn kind(&self) -> FileOperation {
self._kind
}
pub fn files_processed(&self) -> usize {
self._files_processed
}
pub fn set_files_processed(&mut self, files_processed: usize) {
self._files_processed = files_processed;
}
pub fn total_files(&self) -> usize {
self._total_files
}
pub fn bytes_processed(&self) -> u64 {
self._bytes_processed
}
pub fn set_bytes_processed(&mut self, _bytes_processed: u64) {
self._bytes_processed = _bytes_processed;
}
pub fn total_bytes(&self) -> u64 {
self._total_bytes
}
}