Skip to content

Commit

Permalink
Cleaning up file handling and relaying messages to the user
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vadoola committed Oct 6, 2023
1 parent 4c7bd1a commit 5fc8763
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

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

[build-dependencies]
slint-build = "1.1"
slint-build = "1.2.1"

[profile.release]
#https://github.com/johnthagen/min-sized-rust
Expand Down
52 changes: 47 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use ab_versions::{get_version, is_protected, strip_protection};
use clap::Parser;
use log::error;
use log::{error, Record};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use rfd::FileDialog;
use simplelog::{CombinedLogger, Config, LevelFilter, SimpleLogger, WriteLogger};
Expand Down Expand Up @@ -100,7 +100,6 @@ fn main() -> Result<(), slint::PlatformError> {
});

let info_file_model_start = file_model.clone();
//let info_timer = vec![Timer::default(); file_model.row_count()];
let mut info_timers: Vec<Timer> = (0..file_model.row_count()).map(|_i|Timer::default()).collect();
ui.on_slide_over(move |idx| {
let idx = idx as usize;
Expand All @@ -113,7 +112,7 @@ fn main() -> Result<(), slint::PlatformError> {
fi.note_vis = true;
info_file_model_start.set_row_data(idx, fi);
}
info_timers[idx].start(TimerMode::SingleShot, std::time::Duration::from_secs(3), move || {
info_timers[idx].start(TimerMode::SingleShot, std::time::Duration::from_secs(10), move || {
let info_file_model_stop = info_file_model_stop.clone();
let info_file_model_stop = info_file_model_stop.as_ref();
if let Some(mut fi) = info_file_model_stop.row_data(idx) {
Expand Down Expand Up @@ -149,7 +148,50 @@ fn get_file_info(files: &HashMap<String, PathBuf>) -> Vec<file_info> {
.par_iter()
//need to do this differently....what if the version is older than 5 there the is_protected
//would return an error...but I still want to display the version
.filter_map(|(name, file)| match is_protected(&file) {
.filter_map(|(name, file)| match get_version(&file) {
Ok(ver) => {
let note = if ver.is_old() {
if ver.is_restorable() {
"As an old MER some features may not restore correctly."
} else {
"Restoring a file this old is currently unsupported."
}
} else {
""
};

let lckd = if ver.is_restorable() {
match is_protected(&file) {
Ok(prot) => prot,
Err(e) => {
error!(
"Unable to get file protected status from {}. Reason: {e}",
file.display()
);
true
}
}
} else {
true
};

Some(file_info {
locked: lckd,
file_name: name.into(),
file_ver: ver.to_string().into(),
note: note.into(),
note_vis: false,
})
}
Err(e) => {
error!(
"Unable to get file version from {}, file may not be a valid MER/APA file. Reason: {e}",
file.display()
);
None
}
})
/*.filter_map(|(name, file)| match is_protected(&file) {
Ok(lckd) => match get_version(&file) {
Ok(ver) => Some(file_info {
locked: lckd,
Expand Down Expand Up @@ -180,6 +222,6 @@ fn get_file_info(files: &HashMap<String, PathBuf>) -> Vec<file_info> {
note_vis: false,
})
}
})
})*/
.collect()
}
8 changes: 4 additions & 4 deletions ui/appwindow.slint
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ component SlideOver inherits Rectangle {
Rectangle {
height: 2%;
width: 100%;
background: yellow;
background: #F7630C;
}
}
}
Expand Down Expand Up @@ -76,9 +76,9 @@ component FileInfo inherits HorizontalLayout {
}
info-icon := Image {
//this circle question icon is a temporary one while I'm offline, I just had it on my machine
source: @image-url("../assets/icons/circle-question.svg");
colorize: yellow;
height: 100%;
source: @image-url("../assets/icons/info.svg");
colorize: #F7630C;
height: 80%;
width: self.height;
visible: info.note != "";
info-ta := TouchArea {
Expand Down

0 comments on commit 5fc8763

Please sign in to comment.