Skip to content

Commit

Permalink
update rust and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Aggrathon committed Nov 5, 2022
1 parent 394deb5 commit 9f2f853
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 500 deletions.
872 changes: 466 additions & 406 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "simple_backup"
version = "2.0.0"
version = "2.0.1"
authors = ["Aggrathon <antonbjo@gmail.com>"]
edition = "2021"
description = "A minimal application for doing backups."
Expand All @@ -9,33 +9,33 @@ keywords = ["backup", "compression", "application", "software"]

[dependencies]
tar = "0.4.38"
clap = { version = "3.2.6", features = ["derive"] }
serde = { version = "1.0.137", features = ["derive"] }
serde_yaml = "0.8.24"
clap = { version = "4.0.19", features = ["derive"] }
serde = { version = "1.0.147", features = ["derive"] }
serde_yaml = "0.9.14"
yaml-rust = "0.4.5"
chrono = "0.4.19"
regex = "1.5.6"
chrono = "0.4.22"
regex = "1.6.0"
path-clean = "0.1.0"
path-absolutize = "3.0.13"
indicatif = { version = "0.16.2", features = ["improved_unicode"] }
path-absolutize = "3.0.14"
indicatif = { version = "0.17.1", features = ["improved_unicode"] }
zstd = { version = "0.11.2", features = ["zstdmt"] }
number_prefix = "0.4.0"
num_cpus = "1.13.1"
num_cpus = "1.14.0"
iced = { version = "0.4.2", features = ["smol", "pure"], optional = true }
rfd = { version = "0.9.1", optional = true }
rfd = { version = "0.10.0", optional = true }
dirs = { version = "4.0.0", optional = true }

[dev-dependencies]
tempfile = "3.3.0"

[build-dependencies]
resvg = "0.23"
usvg = {version = "0.23", features = ["text"]}
tiny-skia = "0.6.5"
resvg = "0.25.0"
usvg = { version = "0.25.0", features = ["text"] }
tiny-skia = "0.8.2"

[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
ico = "0.1"
winres = "0.1.12"
ico = "0.1.0"

[features]
default = ["gui", "dirs"]
Expand Down
109 changes: 55 additions & 54 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
use std::{fs, path::Path};

use tiny_skia::{Pixmap, Transform};
use usvg::{FitTo, Options, Tree};

const ICON_SIZE: u32 = 64;
const ICON_SIZES: [u32; 2] = [16, 64];

fn main() {
// Render the icon to a bitmap and store the raw bytes so that they can be included when the binary is compiled
let input = Path::new("assets/icon.svg");
let output = Path::new("target/icon.dump");
let svg = fs::read_to_string(input).expect("Could not read svg");
let mut opts = Options::default();
opts.fontdb.load_system_fonts();
let tree = Tree::from_str(&svg, &opts.to_ref()).expect("Could not parse svg");
let mut pixmap = Pixmap::new(ICON_SIZE, ICON_SIZE).unwrap();
resvg::render(
&tree,
FitTo::Size(ICON_SIZE, ICON_SIZE),
Transform::identity(),
pixmap.as_mut(),
)
.unwrap();
fs::write(output, pixmap.data()).expect("Could not write image dump");

#[cfg(windows)]
{
// Create a ico file and embed it with resources in the Windows executable
let output = Path::new("target/icon.ico");
let mut icon = ico::IconDir::new(ico::ResourceType::Icon);
for size in ICON_SIZES {
let mut pixmap = Pixmap::new(size, size).unwrap();
resvg::render(
&tree,
FitTo::Size(size, size),
Transform::identity(),
pixmap.as_mut(),
)
.unwrap();
let img = ico::IconImage::from_rgba_data(size, size, pixmap.data().to_vec());
icon.add_entry(ico::IconDirEntry::encode(&img).expect("Could not encode ico"));
}
{
icon.write(fs::File::create(output).expect("Could not create icon file"))
.expect("Could not write icon file");
}
// TODO The `winres` library needs to be updated, in order to do something with Rust 1.61+
winres::WindowsResource::new()
.set_icon(&output.to_string_lossy())
.compile()
.expect("Could not compile resources");
}
}
use std::fs;
use std::path::Path;

use tiny_skia::{Pixmap, Transform};
use usvg::{FitTo, Options, Tree};

const ICON_SIZE: u32 = 64;
const ICON_SIZES: [u32; 2] = [16, 64];

fn main() {
// Render the icon to a bitmap and store the raw bytes so that they can be included when the binary is compiled
let input = Path::new("assets/icon.svg");
let output = Path::new("target/icon.dump");
let svg = fs::read_to_string(input).expect("Could not read svg");
let mut opts = Options::default();
opts.fontdb.load_system_fonts();
let tree = Tree::from_str(&svg, &opts.to_ref()).expect("Could not parse svg");
let mut pixmap = Pixmap::new(ICON_SIZE, ICON_SIZE).unwrap();
resvg::render(
&tree,
FitTo::Size(ICON_SIZE, ICON_SIZE),
Transform::identity(),
pixmap.as_mut(),
)
.unwrap();
fs::write(output, pixmap.data()).expect("Could not write image dump");

#[cfg(windows)]
{
// Create a ico file and embed it with resources in the Windows executable
let output = Path::new("target/icon.ico");
let mut icon = ico::IconDir::new(ico::ResourceType::Icon);
for size in ICON_SIZES {
let mut pixmap = Pixmap::new(size, size).unwrap();
resvg::render(
&tree,
FitTo::Size(size, size),
Transform::identity(),
pixmap.as_mut(),
)
.unwrap();
let img = ico::IconImage::from_rgba_data(size, size, pixmap.data().to_vec());
icon.add_entry(ico::IconDirEntry::encode(&img).expect("Could not encode ico"));
}
{
icon.write(fs::File::create(output).expect("Could not create icon file"))
.expect("Could not write icon file");
}
// TODO The `winres` library needs to be updated, in order to do something with Rust 1.61+
winres::WindowsResource::new()
.set_icon(&output.to_string_lossy())
.compile()
.expect("Could not compile resources");
}
}
7 changes: 3 additions & 4 deletions src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ impl BackupReader {
}

pub fn get_decoder<'a>(&self) -> Result<CompressionDecoder<'a>, BackupError> {
CompressionDecoder::read(&self.path.copy_path().as_path())
.map_err(BackupError::ArchiveError)
CompressionDecoder::read(self.path.copy_path().as_path()).map_err(BackupError::ArchiveError)
}

/// Read a backup, but only return the embedded config
Expand Down Expand Up @@ -809,7 +808,7 @@ impl BackupMerger {
fn cleanup(&mut self) -> Result<(), BackupError> {
if self.delete {
for r in self.readers.iter_mut() {
std::fs::remove_file(&r.path.get_path()).map_err(BackupError::DeleteError)?;
std::fs::remove_file(r.path.get_path()).map_err(BackupError::DeleteError)?;
}
} else {
for r in self.readers.iter_mut() {
Expand All @@ -818,7 +817,7 @@ impl BackupMerger {
while path.exists() {
path = extend_pathbuf(path, ".old");
}
std::fs::rename(&r.path.get_path(), &path).map_err(|e| {
std::fs::rename(r.path.get_path(), &path).map_err(|e| {
BackupError::RenameError(
r.path.get_string().to_string(),
path.to_string_lossy().to_string(),
Expand Down
19 changes: 9 additions & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use core::panic;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::time::Duration;

use indicatif::{ProgressBar, ProgressStyle};
use number_prefix::NumberPrefix;
Expand Down Expand Up @@ -97,10 +98,10 @@ pub fn backup(config: Config, verbose: bool, force: bool, dry: bool, quiet: bool
};
bar.set_style(ProgressStyle::default_bar().template(
"{wide_msg} {bytes:>8} / {total_bytes:<8}\n{wide_bar} {elapsed_precise:>8} / {duration_precise:<8}",
));
).expect("The progressbar template is wrong!"));
bar.set_message("Compressing file list");
bar.tick();
bar.enable_steady_tick(1000);
bar.enable_steady_tick(Duration::from_secs(1));
bw.write(
|fi: &mut FileInfo, err| {
bar.set_message(fi.move_string());
Expand Down Expand Up @@ -204,14 +205,12 @@ pub fn restore<P: AsRef<Path>>(
} else {
ProgressBar::new(list.len() as u64)
};
bar.set_style(
ProgressStyle::default_bar().template(
"{wide_msg} {pos:>8} / {len:<8}\n{wide_bar} {elapsed_precise:>8} / {duration_precise:<8}",
),
);
bar.set_style(ProgressStyle::default_bar().template(
"{wide_msg} {pos:>8} / {len:<8}\n{wide_bar} {elapsed_precise:>8} / {duration_precise:<8}"
).expect("The progressbar template is wrong!"));
bar.set_message("Restoring files");
bar.tick();
bar.enable_steady_tick(1000);
bar.enable_steady_tick(Duration::from_secs(1));

let callback = |res| {
match res {
Expand Down Expand Up @@ -350,10 +349,10 @@ pub fn merge(
};
bar.set_style(ProgressStyle::default_bar().template(
"{wide_msg} {pos:>8} / {len:<8}\n{wide_bar} {elapsed_precise:>8} / {duration_precise:<8}",
));
).expect("The progressbar template is wrong!"));
bar.set_message("Merging backups...");
bar.tick();
bar.enable_steady_tick(1000);
bar.enable_steady_tick(Duration::from_secs(1));

merger
.write(
Expand Down
2 changes: 1 addition & 1 deletion src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> CompressionEncoder<'a> {
/// Add a file to the compressed archive
pub fn append_file(&mut self, file: &PathBuf) -> std::io::Result<()> {
let name = path_to_archive(file);
self.0.append_path_with_name(&file, name)
self.0.append_path_with_name(file, name)
}

/// Add raw data as a file to the compressed archive
Expand Down
3 changes: 1 addition & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use serde::{Deserialize, Serialize};
use crate::backup::BACKUP_FILE_EXTENSION;
use crate::parse_date;
use crate::parse_date::{create_backup_file_name, naive_now};
use crate::utils::default_dir;
use crate::utils::{clamp, BackupIterator};
use crate::utils::{clamp, default_dir, BackupIterator};

#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct Config {
Expand Down
1 change: 1 addition & 0 deletions src/gui/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum ListSort {
Time,
}

#[allow(clippy::large_enum_variant)]
enum BackupStage {
Scanning(ThreadWrapper<Result<FileInfo, BackupError>, BackupWriter>),
Viewing(BackupWriter),
Expand Down
8 changes: 4 additions & 4 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ fn open_config() -> Option<Config> {
FileDialog::new()
.set_directory(default_dir())
.set_title("Open existing config or backup file")
.add_filter(
"Config and backup files",
&[&CONFIG_FILE_EXTENSION[1..], &BACKUP_FILE_EXTENSION[1..]],
)
.add_filter("Config and backup files", &[
&CONFIG_FILE_EXTENSION[1..],
&BACKUP_FILE_EXTENSION[1..],
])
.add_filter("Config files", &[&CONFIG_FILE_EXTENSION[1..]])
.add_filter("Backup files", &[&BACKUP_FILE_EXTENSION[1..]])
.pick_file()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl RestoreState {
Message::Export => {
if let RestoreStage::Viewing(reader, _) = &mut self.stage {
if let Some(file) = FileDialog::new()
.set_directory(&reader.path.get_path())
.set_directory(reader.path.get_path())
.set_title("Save the list of files in the backup")
.set_file_name("files.txt")
.add_filter("Text file", &["txt"])
Expand Down
4 changes: 2 additions & 2 deletions src/parse_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ pub fn try_parse(input: &str) -> Result<Option<NaiveDateTime>, &'static str> {
return Ok(None);
}
for f in FORMATS_DT.iter() {
if let Ok(t) = NaiveDateTime::parse_from_str(input, *f) {
if let Ok(t) = NaiveDateTime::parse_from_str(input, f) {
return Ok(Some(t));
}
}
for f in FORMATS_D.iter() {
if let Ok(t) = NaiveDate::parse_from_str(input, *f) {
if let Ok(t) = NaiveDate::parse_from_str(input, f) {
return Ok(Some(t.and_hms(0, 0, 0)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl BackupIterator {
/// Get the latest backup based on the timestamp in the file name
pub fn get_latest(&mut self) -> Option<PathBuf> {
self.filter_map(|res| res.ok())
.max_by_key(|p| get_probable_time(&p))
.max_by_key(|p| get_probable_time(p))
}

/// Get the previous backup based on a file name
Expand Down

0 comments on commit 9f2f853

Please sign in to comment.