Fix crashes in gui and core
This commit is contained in:
parent
355761e8a4
commit
61ce6aa987
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -341,9 +341,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.2.11"
|
||||
version = "3.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d646c7ade5eb07c4aa20e907a922750df0c448892513714fd3e4acbc7130829f"
|
||||
checksum = "ab8b79fe3946ceb4a0b1c080b4018992b8d27e9ff363644c1c9b6387c854614d"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
|
@ -2505,9 +2505,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.3"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d"
|
||||
checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
]
|
||||
|
|
|
@ -10,7 +10,7 @@ homepage = "https://github.com/qarmin/czkawka"
|
|||
repository = "https://github.com/qarmin/czkawka"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.2.11", features = ["derive"] }
|
||||
clap = { version = "3.2.12", features = ["derive"] }
|
||||
|
||||
# For enum types
|
||||
image_hasher = "1.0.0"
|
||||
|
|
|
@ -732,7 +732,8 @@ impl SimilarImages {
|
|||
}
|
||||
|
||||
let number_of_processors = num_cpus::get();
|
||||
let chunks: Vec<_> = all_hashes.chunks(all_hashes.len() / number_of_processors).collect();
|
||||
let chunk_size = all_hashes.len() / number_of_processors;
|
||||
let chunks: Vec<_> = if chunk_size > 0 { all_hashes.chunks(chunk_size).collect() } else { vec![&all_hashes] };
|
||||
|
||||
let parts: Vec<_> = chunks
|
||||
.into_par_iter()
|
||||
|
|
|
@ -608,14 +608,23 @@ pub fn resize_pixbuf_dimension(pixbuf: Pixbuf, requested_size: (i32, i32), inter
|
|||
|
||||
pub fn get_max_file_name(file_name: &str, max_length: usize) -> String {
|
||||
assert!(max_length > 10); // Maybe in future will be supported lower values
|
||||
if file_name.len() > max_length {
|
||||
let difference = file_name.len() - max_length;
|
||||
let characters_in_filename = file_name.chars().count();
|
||||
if characters_in_filename > max_length {
|
||||
let start_characters = 10;
|
||||
let difference = characters_in_filename - max_length;
|
||||
let second_part_start = start_characters + difference;
|
||||
let mut string_pre = "".to_string();
|
||||
let mut string_after = "".to_string();
|
||||
|
||||
let mut string = "".to_string();
|
||||
string += &file_name[0..10];
|
||||
string += " ... ";
|
||||
string += &file_name[10 + difference..];
|
||||
string
|
||||
for (index, character) in file_name.chars().enumerate() {
|
||||
if index < start_characters {
|
||||
string_pre.push(character);
|
||||
} else if index >= second_part_start {
|
||||
string_after.push(character);
|
||||
}
|
||||
}
|
||||
|
||||
format!("{string_pre} ... {string_after}")
|
||||
} else {
|
||||
file_name.to_string()
|
||||
}
|
||||
|
@ -714,3 +723,13 @@ pub fn get_pixbuf_from_dynamic_image(dynamic_image: &DynamicImage) -> Result<Pix
|
|||
}
|
||||
Pixbuf::from_read(arra)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_file_name_shortener() {
|
||||
let name_to_check = "/home/rafal/czkawek/romek/atomek.txt";
|
||||
assert_eq!(get_max_file_name(name_to_check, 20), "/home/rafa ... atomek.txt".to_string());
|
||||
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... /atomek.txt".to_string());
|
||||
let name_to_check = "/home/rafal/czkawek/romek/czekistan/atomek.txt";
|
||||
assert_eq!(get_max_file_name(name_to_check, 21), "/home/rafa ... /atomek.txt".to_string());
|
||||
assert_eq!(get_max_file_name(name_to_check, 80), name_to_check.to_string());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue