Change SystemTime to u64
This commit is contained in:
parent
679bbafbd6
commit
7a1a9ea9f6
|
@ -9,14 +9,13 @@ use std::collections::BTreeMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::{File, Metadata};
|
use std::fs::{File, Metadata};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::time::SystemTime;
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FileEntry {
|
pub struct FileEntry {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub created_date: SystemTime,
|
pub modified_date: u64,
|
||||||
pub modified_date: SystemTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Info struck with helpful information's about results
|
/// Info struck with helpful information's about results
|
||||||
|
@ -203,15 +202,8 @@ impl BigFile {
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
path: current_file_name.clone(),
|
path: current_file_name.clone(),
|
||||||
size: metadata.len(),
|
size: metadata.len(),
|
||||||
created_date: match metadata.created() {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(_) => {
|
|
||||||
self.text_messages.warnings.push("Unable to get creation date from file ".to_string() + current_file_name.as_str());
|
|
||||||
continue;
|
|
||||||
} // Permissions Denied
|
|
||||||
},
|
|
||||||
modified_date: match metadata.modified() {
|
modified_date: match metadata.modified() {
|
||||||
Ok(t) => t,
|
Ok(t) => t.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs(),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -35,8 +35,7 @@ pub enum DeleteMethod {
|
||||||
pub struct FileEntry {
|
pub struct FileEntry {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub created_date: SystemTime,
|
pub modified_date: u64,
|
||||||
pub modified_date: SystemTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Info struck with helpful information's about results
|
/// Info struck with helpful information's about results
|
||||||
|
@ -286,15 +285,8 @@ impl DuplicateFinder {
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
path: current_file_name.clone(),
|
path: current_file_name.clone(),
|
||||||
size: metadata.len(),
|
size: metadata.len(),
|
||||||
created_date: match metadata.created() {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(_) => {
|
|
||||||
self.text_messages.warnings.push("Unable to get creation date from file ".to_string() + current_file_name.as_str());
|
|
||||||
continue;
|
|
||||||
} // Permissions Denied
|
|
||||||
},
|
|
||||||
modified_date: match metadata.modified() {
|
modified_date: match metadata.modified() {
|
||||||
Ok(t) => t,
|
Ok(t) => t.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs(),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
||||||
continue;
|
continue;
|
||||||
|
@ -651,9 +643,8 @@ fn delete_files(vector: &[FileEntry], delete_method: &DeleteMethod, warnings: &m
|
||||||
match delete_method {
|
match delete_method {
|
||||||
DeleteMethod::OneOldest => {
|
DeleteMethod::OneOldest => {
|
||||||
for (index, file) in vector.iter().enumerate() {
|
for (index, file) in vector.iter().enumerate() {
|
||||||
let time_since_epoch = file.created_date.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs();
|
if q_time == 0 || q_time > file.modified_date {
|
||||||
if q_time == 0 || q_time > time_since_epoch {
|
q_time = file.modified_date;
|
||||||
q_time = time_since_epoch;
|
|
||||||
q_index = index;
|
q_index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -670,9 +661,8 @@ fn delete_files(vector: &[FileEntry], delete_method: &DeleteMethod, warnings: &m
|
||||||
}
|
}
|
||||||
DeleteMethod::OneNewest => {
|
DeleteMethod::OneNewest => {
|
||||||
for (index, file) in vector.iter().enumerate() {
|
for (index, file) in vector.iter().enumerate() {
|
||||||
let time_since_epoch = file.created_date.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs();
|
if q_time == 0 || q_time < file.modified_date {
|
||||||
if q_time == 0 || q_time < time_since_epoch {
|
q_time = file.modified_date;
|
||||||
q_time = time_since_epoch;
|
|
||||||
q_index = index;
|
q_index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -689,9 +679,8 @@ fn delete_files(vector: &[FileEntry], delete_method: &DeleteMethod, warnings: &m
|
||||||
}
|
}
|
||||||
DeleteMethod::AllExceptOldest => {
|
DeleteMethod::AllExceptOldest => {
|
||||||
for (index, file) in vector.iter().enumerate() {
|
for (index, file) in vector.iter().enumerate() {
|
||||||
let time_since_epoch = file.created_date.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs();
|
if q_time == 0 || q_time > file.modified_date {
|
||||||
if q_time == 0 || q_time > time_since_epoch {
|
q_time = file.modified_date;
|
||||||
q_time = time_since_epoch;
|
|
||||||
q_index = index;
|
q_index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -712,9 +701,8 @@ fn delete_files(vector: &[FileEntry], delete_method: &DeleteMethod, warnings: &m
|
||||||
}
|
}
|
||||||
DeleteMethod::AllExceptNewest => {
|
DeleteMethod::AllExceptNewest => {
|
||||||
for (index, file) in vector.iter().enumerate() {
|
for (index, file) in vector.iter().enumerate() {
|
||||||
let time_since_epoch = file.created_date.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs();
|
if q_time == 0 || q_time < file.modified_date {
|
||||||
if q_time == 0 || q_time < time_since_epoch {
|
q_time = file.modified_date;
|
||||||
q_time = time_since_epoch;
|
|
||||||
q_index = index;
|
q_index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::{File, Metadata};
|
use std::fs::{File, Metadata};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::time::SystemTime;
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use crate::common::Common;
|
use crate::common::Common;
|
||||||
use crate::common_directory::Directories;
|
use crate::common_directory::Directories;
|
||||||
|
@ -19,8 +19,7 @@ pub enum DeleteMethod {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FileEntry {
|
pub struct FileEntry {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub created_date: SystemTime,
|
pub modified_date: u64,
|
||||||
pub modified_date: SystemTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Info struck with helpful information's about results
|
/// Info struck with helpful information's about results
|
||||||
|
@ -228,15 +227,8 @@ impl EmptyFiles {
|
||||||
// Creating new file entry
|
// Creating new file entry
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
path: current_file_name.clone(),
|
path: current_file_name.clone(),
|
||||||
created_date: match metadata.created() {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(_) => {
|
|
||||||
self.text_messages.warnings.push("Unable to get creation date from file ".to_string() + current_file_name.as_str());
|
|
||||||
continue;
|
|
||||||
} // Permissions Denied
|
|
||||||
},
|
|
||||||
modified_date: match metadata.modified() {
|
modified_date: match metadata.modified() {
|
||||||
Ok(t) => t,
|
Ok(t) => t.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs(),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::collections::BTreeMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::{File, Metadata};
|
use std::fs::{File, Metadata};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::time::SystemTime;
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
/// Enum with values which show if folder is empty.
|
/// Enum with values which show if folder is empty.
|
||||||
/// In function "optimize_folders" automatically "Maybe" is changed to "Yes", so it is not necessary to put it here
|
/// In function "optimize_folders" automatically "Maybe" is changed to "Yes", so it is not necessary to put it here
|
||||||
|
@ -21,7 +21,7 @@ enum FolderEmptiness {
|
||||||
pub struct FolderEntry {
|
pub struct FolderEntry {
|
||||||
parent_path: Option<String>, // Usable only when finding
|
parent_path: Option<String>, // Usable only when finding
|
||||||
is_empty: FolderEmptiness,
|
is_empty: FolderEmptiness,
|
||||||
pub modified_date: SystemTime,
|
pub modified_date: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Struct to store most basics info about all folder
|
/// Struct to store most basics info about all folder
|
||||||
|
@ -128,7 +128,7 @@ impl EmptyFolder {
|
||||||
FolderEntry {
|
FolderEntry {
|
||||||
parent_path: None,
|
parent_path: None,
|
||||||
is_empty: FolderEmptiness::Maybe,
|
is_empty: FolderEmptiness::Maybe,
|
||||||
modified_date: SystemTime::now(),
|
modified_date: 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
folders_to_check.push(id.clone());
|
folders_to_check.push(id.clone());
|
||||||
|
@ -182,10 +182,10 @@ impl EmptyFolder {
|
||||||
parent_path: Option::from(current_folder.clone()),
|
parent_path: Option::from(current_folder.clone()),
|
||||||
is_empty: FolderEmptiness::Maybe,
|
is_empty: FolderEmptiness::Maybe,
|
||||||
modified_date: match metadata.modified() {
|
modified_date: match metadata.modified() {
|
||||||
Ok(t) => t,
|
Ok(t) => t.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs(),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.text_messages.warnings.push(format!("Failed to read modification date of folder {}", current_folder));
|
self.text_messages.warnings.push(format!("Failed to read modification date of folder {}", current_folder));
|
||||||
SystemTime::now()
|
continue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::{File, Metadata};
|
use std::fs::{File, Metadata};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::time::SystemTime;
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use crate::common::Common;
|
use crate::common::Common;
|
||||||
use crate::common_directory::Directories;
|
use crate::common_directory::Directories;
|
||||||
|
@ -18,8 +18,7 @@ pub enum DeleteMethod {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FileEntry {
|
pub struct FileEntry {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub created_date: SystemTime,
|
pub modified_date: u64,
|
||||||
pub modified_date: SystemTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Info struck with helpful information's about results
|
/// Info struck with helpful information's about results
|
||||||
|
@ -219,15 +218,8 @@ impl Temporary {
|
||||||
// Creating new file entry
|
// Creating new file entry
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
path: current_file_name.clone(),
|
path: current_file_name.clone(),
|
||||||
created_date: match metadata.created() {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(_) => {
|
|
||||||
self.text_messages.warnings.push("Unable to get creation date from file ".to_string() + current_file_name.as_str());
|
|
||||||
continue;
|
|
||||||
} // Permissions Denied
|
|
||||||
},
|
|
||||||
modified_date: match metadata.modified() {
|
modified_date: match metadata.modified() {
|
||||||
Ok(t) => t,
|
Ok(t) => t.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs(),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
self.text_messages.warnings.push("Unable to get modification date from file ".to_string() + current_file_name.as_str());
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -15,7 +15,6 @@ use gtk::{Builder, SelectionMode, TreeIter, TreeView};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::time::UNIX_EPOCH;
|
|
||||||
use std::{env, fs, process};
|
use std::{env, fs, process};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -410,7 +409,7 @@ fn main() {
|
||||||
let values: [&dyn ToValue; 4] = [
|
let values: [&dyn ToValue; 4] = [
|
||||||
&(path[index + 1..].to_string()),
|
&(path[index + 1..].to_string()),
|
||||||
&(path[..index].to_string()),
|
&(path[..index].to_string()),
|
||||||
&(NaiveDateTime::from_timestamp(entry.modified_date.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs() as i64, 0).to_string()),
|
&(NaiveDateTime::from_timestamp(entry.modified_date as i64, 0).to_string()),
|
||||||
&(MAIN_ROW_COLOR.to_string()),
|
&(MAIN_ROW_COLOR.to_string()),
|
||||||
];
|
];
|
||||||
list_store.set(&list_store.append(), &col_indices, &values);
|
list_store.set(&list_store.append(), &col_indices, &values);
|
||||||
|
@ -436,7 +435,7 @@ fn main() {
|
||||||
let values: [&dyn ToValue; 4] = [
|
let values: [&dyn ToValue; 4] = [
|
||||||
&(path[index + 1..].to_string()),
|
&(path[index + 1..].to_string()),
|
||||||
&(path[..index].to_string()),
|
&(path[..index].to_string()),
|
||||||
&(NaiveDateTime::from_timestamp(entry.modified_date.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs() as i64, 0).to_string()),
|
&(NaiveDateTime::from_timestamp(entry.modified_date as i64, 0).to_string()),
|
||||||
&(MAIN_ROW_COLOR.to_string()),
|
&(MAIN_ROW_COLOR.to_string()),
|
||||||
];
|
];
|
||||||
list_store.set(&list_store.append(), &col_indices, &values);
|
list_store.set(&list_store.append(), &col_indices, &values);
|
||||||
|
@ -513,7 +512,7 @@ fn main() {
|
||||||
let values: [&dyn ToValue; 4] = [
|
let values: [&dyn ToValue; 4] = [
|
||||||
&(name[index + 1..].to_string()),
|
&(name[index + 1..].to_string()),
|
||||||
&(name[..index].to_string()),
|
&(name[..index].to_string()),
|
||||||
&(NaiveDateTime::from_timestamp(entry.modified_date.duration_since(UNIX_EPOCH).expect("Invalid file date").as_secs() as i64, 0).to_string()),
|
&(NaiveDateTime::from_timestamp(entry.modified_date as i64, 0).to_string()),
|
||||||
&(MAIN_ROW_COLOR.to_string()),
|
&(MAIN_ROW_COLOR.to_string()),
|
||||||
];
|
];
|
||||||
list_store.set(&list_store.append(), &col_indices, &values);
|
list_store.set(&list_store.append(), &col_indices, &values);
|
||||||
|
@ -703,7 +702,7 @@ fn main() {
|
||||||
selection.select_all();
|
selection.select_all();
|
||||||
} else {
|
} else {
|
||||||
let tree_iter_all = tree_model.get_iter_first().unwrap(); // Never should be available button where there is no available records
|
let tree_iter_all = tree_model.get_iter_first().unwrap(); // Never should be available button where there is no available records
|
||||||
// let tree_iter_selection
|
|
||||||
let mut current_path_index = 0;
|
let mut current_path_index = 0;
|
||||||
let mut tree_iter_selected: TreeIter;
|
let mut tree_iter_selected: TreeIter;
|
||||||
loop {
|
loop {
|
||||||
|
@ -727,6 +726,58 @@ fn main() {
|
||||||
popover_select.popdown();
|
popover_select.popdown();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // All except oldest
|
||||||
|
// {
|
||||||
|
// // let scrolled_window_duplicate_finder = scrolled_window_duplicate_finder.clone();
|
||||||
|
// // let popover_select = popover_select.clone();
|
||||||
|
// buttons_popover_reverse.connect_clicked(move |_| {
|
||||||
|
// let tree_view = scrolled_window_duplicate_finder.get_children().get(0).unwrap().clone().downcast::<gtk::TreeView>().unwrap();
|
||||||
|
// let selection = tree_view.get_selection();
|
||||||
|
//
|
||||||
|
// let (vector_tree_path, tree_model) = selection.get_selected_rows();
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// let tree_iter_all = tree_model.get_iter_first().unwrap(); // Never should be available button where there is no available records
|
||||||
|
//
|
||||||
|
// let mut current_path_index = 0;
|
||||||
|
// let mut tree_iter_selected: TreeIter;
|
||||||
|
//
|
||||||
|
// let color = tree_model.get_value(&tree_model.get_iter(tree_path).unwrap(), Columns3Default::Color as i32).get::<String>().unwrap().unwrap();
|
||||||
|
//
|
||||||
|
// loop {
|
||||||
|
// let array_to_have: Vec<SystemTime> = Vec::new();
|
||||||
|
// let oldest_index : Option<int> = None;
|
||||||
|
//
|
||||||
|
// loop {
|
||||||
|
// if color == HEADER_ROW_COLOR {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if current_path_index >= vector_tree_path.len() {
|
||||||
|
// selection.select_iter(&tree_iter_all);
|
||||||
|
// } else {
|
||||||
|
// tree_iter_selected = tree_model.get_iter(vector_tree_path.get(current_path_index).unwrap()).unwrap();
|
||||||
|
// if tree_model.get_path(&tree_iter_all).unwrap() == tree_model.get_path(&tree_iter_selected).unwrap() {
|
||||||
|
// selection.unselect_iter(&tree_iter_selected);
|
||||||
|
// current_path_index += 1;
|
||||||
|
// } else {
|
||||||
|
// selection.select_iter(&tree_iter_all);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if !tree_model.iter_next(&tree_iter_all) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if arry
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// popover_select.popdown();
|
||||||
|
// });
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
// Upper Notepad
|
// Upper Notepad
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue