1use std::path::PathBuf;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum OperationType{
5 Rename,
6 Move,
7 Copy,
8 Delete
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum SequenceExistence{
13 False, Partial, True
14}
15
16#[derive(Debug, Clone, Default, PartialEq)]
18pub struct Components{
19 pub prefix: Option<String>,
20 pub delimiter: Option<String>,
21 pub padding: Option<usize>,
22 pub suffix: Option<String>,
23 pub frame_number: Option<isize>,
24}
25
26impl Components{
27 pub fn new() -> Self{
28 Self::default()
29 }
30}
31
32#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
33pub struct Item {
34 pub prefix: String,
35 pub frame_string: String,
36 pub extention: String,
37 pub delimiter: Option<String>,
38 pub suffix: Option<String>,
39 pub directory: Option<PathBuf>
40}
41
42impl Item{
43 pub fn frame_number(&self) -> isize{
44 self.frame_string.parse().unwrap_or(0)
45 }
46
47 pub fn path(&self) -> PathBuf{
48 let name = self.filename();
49 match &self.directory{
50 Some(dir) => dir.join(name),
51 None => PathBuf::from(name),
52 }
53 }
54
55 pub fn filename(&self) -> String{
56 let delim = self.delimiter.as_deref().unwrap_or("");
57 let suff = self.suffix.as_deref().unwrap_or("");
58 format!("{}{}{}{}.{}", self.prefix, delim, self.frame_string, suff, self.extention)
59 }
60}
61
62#[derive(Debug, Clone)]
63pub struct FileSequence{
64 items: Vec<Item>,
65}
66
67impl FileSequence{
68
69 pub fn new(items: Vec<Item>) -> Self{
70 let mut sorted_items = items;
71 sorted_items.sort();
72 Self { items: sorted_items}
73 }
74
75 pub fn len(&self) -> usize{
76 self.items.len()
77 }
78
79 pub fn is_empty(&self) -> bool {
80 self.items.is_empty()
81 }
82}
83
84
85
86
87#[derive(Debug, Clone, PartialEq)]
88pub struct FileOperation{
89 pub operation: OperationType,
90 pub source: PathBuf,
91 pub destination: Option<PathBuf>,
92}
93
94#[derive(Debug, Clone)]
95pub struct OperationPlan{
96 pub operations: Vec<FileOperation>,
97}
98
99impl OperationPlan{
100 pub fn empty() -> Self{
101 Self { operations: vec![]}
102 }
103
104 pub fn has_conflicts(&self) -> bool{
105 self.operations.iter().any(|op| {
106 if let Some(dest) = &op.destination{
107 dest.exists()
108 } else {
109 false
110 }
111 })
112 }
113}
114
115