Compare commits
2 Commits
17e8bda099
...
45cbcaf95f
Author | SHA1 | Date | |
---|---|---|---|
|
45cbcaf95f | ||
|
8fab1a2c74 |
9
src-tauri/Cargo.lock
generated
9
src-tauri/Cargo.lock
generated
|
@ -335,6 +335,7 @@ dependencies = [
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"mountpoints",
|
"mountpoints",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
|
@ -2285,9 +2286,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.7.1"
|
version = "1.7.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
|
checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -2305,9 +2306,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.6.28"
|
version = "0.6.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rfd"
|
name = "rfd"
|
||||||
|
|
|
@ -28,6 +28,7 @@ mountpoints = "0.2.1"
|
||||||
md-5 = "0.10.5"
|
md-5 = "0.10.5"
|
||||||
urlencoding = "2.1.2"
|
urlencoding = "2.1.2"
|
||||||
mime_guess = "2.0.4"
|
mime_guess = "2.0.4"
|
||||||
|
regex = "1.7.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||||
|
|
|
@ -4,12 +4,21 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use mountpoints::mountinfos;
|
use mountpoints::mountinfos;
|
||||||
|
use regex::Regex;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tauri::Runtime;
|
use tauri::Runtime;
|
||||||
|
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
fn compute_all_digits(text: &str) -> usize {
|
||||||
|
let re = Regex::new(r#"\d+"#).unwrap();
|
||||||
|
re.find_iter(&["a", text, "0"].join(" "))
|
||||||
|
.map(|b| b.as_str())
|
||||||
|
.map(|b| usize::from_str_radix(b, 10).unwrap_or(0))
|
||||||
|
.sum::<usize>()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||||
pub struct FileItem {
|
pub struct FileItem {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
|
@ -18,7 +27,19 @@ pub struct FileItem {
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
impl PartialOrd for FileItem {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
let this_digit = compute_all_digits(&self.filename);
|
||||||
|
let other_digit = compute_all_digits(&other.filename);
|
||||||
|
if this_digit == other_digit {
|
||||||
|
self.filename.partial_cmp(&other.filename)
|
||||||
|
} else {
|
||||||
|
this_digit.partial_cmp(&other_digit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||||
pub struct DirItem {
|
pub struct DirItem {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub dirname: String,
|
pub dirname: String,
|
||||||
|
@ -26,6 +47,18 @@ pub struct DirItem {
|
||||||
pub root: bool,
|
pub root: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for DirItem {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
let this_digit = compute_all_digits(&self.dirname);
|
||||||
|
let other_digit = compute_all_digits(&other.dirname);
|
||||||
|
if this_digit == other_digit {
|
||||||
|
self.dirname.partial_cmp(&other.dirname)
|
||||||
|
} else {
|
||||||
|
this_digit.partial_cmp(&other_digit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn is_hidden(entry: &DirEntry) -> bool {
|
fn is_hidden(entry: &DirEntry) -> bool {
|
||||||
entry
|
entry
|
||||||
.file_name()
|
.file_name()
|
||||||
|
@ -92,7 +125,7 @@ pub async fn scan_directory(target: String) -> Result<Vec<FileItem>, String> {
|
||||||
width,
|
width,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
file_items.sort_by(|a, b| a.filename.partial_cmp(&b.filename).unwrap());
|
file_items.sort_by(|a, b| a.partial_cmp(&b).unwrap());
|
||||||
|
|
||||||
Ok(file_items)
|
Ok(file_items)
|
||||||
}
|
}
|
||||||
|
@ -193,7 +226,7 @@ pub async fn scan_for_child_dirs<R: Runtime>(
|
||||||
root: false,
|
root: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
child_dirs.sort_by(|a, b| a.dirname.partial_cmp(&b.dirname).unwrap());
|
child_dirs.sort_by(|a, b| a.partial_cmp(&b).unwrap());
|
||||||
Ok(child_dirs)
|
Ok(child_dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user