Skip to content

Commit 5fc8763

Browse files
committed
Cleaning up file handling and relaying messages to the user
I added in some better handling of older files. Now instead of failing, it will show the version for v4 and older files. It will also populate a note with information on the older versions. V4 files can be unlocked and the program allows this, but I need to prevent it from allowing a V3 file to try and be unlocked as this currently doesn't function. I also want to add a bit of a progress bar to the slide over as the timer ticks down. I've also upgraded to the latest version of Slint.
1 parent 4c7bd1a commit 5fc8763

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build = "build.rs"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
slint = "1.1"
11+
slint = "1.2.1"
1212
ab_versions = {git = "https://github.com/Vadoola/ab_versions_rs.git"}
1313
clap = { version = "4.3", features = ["derive"] }
1414
rayon = "1.5"
@@ -18,7 +18,7 @@ log = "0.4.20"
1818
simplelog = "0.12.1"
1919

2020
[build-dependencies]
21-
slint-build = "1.1"
21+
slint-build = "1.2.1"
2222

2323
[profile.release]
2424
#https://github.com/johnthagen/min-sized-rust

src/main.rs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use ab_versions::{get_version, is_protected, strip_protection};
99
use clap::Parser;
10-
use log::error;
10+
use log::{error, Record};
1111
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
1212
use rfd::FileDialog;
1313
use simplelog::{CombinedLogger, Config, LevelFilter, SimpleLogger, WriteLogger};
@@ -100,7 +100,6 @@ fn main() -> Result<(), slint::PlatformError> {
100100
});
101101

102102
let info_file_model_start = file_model.clone();
103-
//let info_timer = vec![Timer::default(); file_model.row_count()];
104103
let mut info_timers: Vec<Timer> = (0..file_model.row_count()).map(|_i|Timer::default()).collect();
105104
ui.on_slide_over(move |idx| {
106105
let idx = idx as usize;
@@ -113,7 +112,7 @@ fn main() -> Result<(), slint::PlatformError> {
113112
fi.note_vis = true;
114113
info_file_model_start.set_row_data(idx, fi);
115114
}
116-
info_timers[idx].start(TimerMode::SingleShot, std::time::Duration::from_secs(3), move || {
115+
info_timers[idx].start(TimerMode::SingleShot, std::time::Duration::from_secs(10), move || {
117116
let info_file_model_stop = info_file_model_stop.clone();
118117
let info_file_model_stop = info_file_model_stop.as_ref();
119118
if let Some(mut fi) = info_file_model_stop.row_data(idx) {
@@ -149,7 +148,50 @@ fn get_file_info(files: &HashMap<String, PathBuf>) -> Vec<file_info> {
149148
.par_iter()
150149
//need to do this differently....what if the version is older than 5 there the is_protected
151150
//would return an error...but I still want to display the version
152-
.filter_map(|(name, file)| match is_protected(&file) {
151+
.filter_map(|(name, file)| match get_version(&file) {
152+
Ok(ver) => {
153+
let note = if ver.is_old() {
154+
if ver.is_restorable() {
155+
"As an old MER some features may not restore correctly."
156+
} else {
157+
"Restoring a file this old is currently unsupported."
158+
}
159+
} else {
160+
""
161+
};
162+
163+
let lckd = if ver.is_restorable() {
164+
match is_protected(&file) {
165+
Ok(prot) => prot,
166+
Err(e) => {
167+
error!(
168+
"Unable to get file protected status from {}. Reason: {e}",
169+
file.display()
170+
);
171+
true
172+
}
173+
}
174+
} else {
175+
true
176+
};
177+
178+
Some(file_info {
179+
locked: lckd,
180+
file_name: name.into(),
181+
file_ver: ver.to_string().into(),
182+
note: note.into(),
183+
note_vis: false,
184+
})
185+
}
186+
Err(e) => {
187+
error!(
188+
"Unable to get file version from {}, file may not be a valid MER/APA file. Reason: {e}",
189+
file.display()
190+
);
191+
None
192+
}
193+
})
194+
/*.filter_map(|(name, file)| match is_protected(&file) {
153195
Ok(lckd) => match get_version(&file) {
154196
Ok(ver) => Some(file_info {
155197
locked: lckd,
@@ -180,6 +222,6 @@ fn get_file_info(files: &HashMap<String, PathBuf>) -> Vec<file_info> {
180222
note_vis: false,
181223
})
182224
}
183-
})
225+
})*/
184226
.collect()
185227
}

ui/appwindow.slint

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ component SlideOver inherits Rectangle {
2424
Rectangle {
2525
height: 2%;
2626
width: 100%;
27-
background: yellow;
27+
background: #F7630C;
2828
}
2929
}
3030
}
@@ -76,9 +76,9 @@ component FileInfo inherits HorizontalLayout {
7676
}
7777
info-icon := Image {
7878
//this circle question icon is a temporary one while I'm offline, I just had it on my machine
79-
source: @image-url("../assets/icons/circle-question.svg");
80-
colorize: yellow;
81-
height: 100%;
79+
source: @image-url("../assets/icons/info.svg");
80+
colorize: #F7630C;
81+
height: 80%;
8282
width: self.height;
8383
visible: info.note != "";
8484
info-ta := TouchArea {

0 commit comments

Comments
 (0)