diff --git a/Cargo.lock b/Cargo.lock index 8d9412f..8defbb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,6 +170,24 @@ version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + +[[package]] +name = "pbr" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4403eb718d70c03ee279e51737782902c68cca01e870a33b6a2f9dfb50b9cd83" +dependencies = [ + "libc", + "termion", + "time", + "winapi", +] + [[package]] name = "pkg-config" version = "0.3.17" @@ -273,6 +291,15 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +dependencies = [ + "redox_syscall", +] + [[package]] name = "regex" version = "1.3.4" @@ -299,13 +326,15 @@ dependencies = [ [[package]] name = "save-op1" -version = "0.3.0" +version = "0.4.0" dependencies = [ "dialoguer", "ears", "enquirer", + "pbr", "slug", "taglib", + "tee_readwrite", ] [[package]] @@ -388,6 +417,12 @@ dependencies = [ "libc", ] +[[package]] +name = "tee_readwrite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0642ac8a287350e5bd14ac50e7a137d49432ae625a1ae83668323ef3ca466af8" + [[package]] name = "tempfile" version = "3.1.0" @@ -402,6 +437,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "termion" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905" +dependencies = [ + "libc", + "numtoa", + "redox_syscall", + "redox_termios", +] + [[package]] name = "termios" version = "0.3.1" @@ -420,6 +467,17 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "time" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +dependencies = [ + "libc", + "redox_syscall", + "winapi", +] + [[package]] name = "unicode-segmentation" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index a14467d..9b6191a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "save-op1" -version = "0.3.0" +version = "0.4.0" authors = ["chee "] edition = "2018" @@ -12,3 +12,5 @@ dialoguer = "0.5.0" ears = "0.8.0" slug = "0.1.4" taglib = "1.0.0" +pbr = "1.0.2" +tee_readwrite = "0.1.0" diff --git a/src/disk.rs b/src/disk.rs index 0ccf020..262c0c4 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -1,8 +1,10 @@ use super::operator::Track; use super::song::Song; -use std::fs::{copy, create_dir_all, read_dir}; -use std::io::{Error, ErrorKind, Result}; +use pbr::{ProgressBar, Units}; +use std::fs::{create_dir_all, read_dir, File}; +use std::io::{copy, Error, ErrorKind, Result}; use std::path; +use tee_readwrite::TeeWriter; struct SongsPath { path: String, @@ -94,6 +96,18 @@ pub struct Disk { */ } +fn copy_file(source: &path::PathBuf, target: &path::PathBuf) -> Result<()> { + let mut source = File::open(source)?; + let bytes = source.metadata()?.len() as u64; + let mut progress_bar = ProgressBar::new(bytes); + progress_bar.set_units(Units::Bytes); + let mut target = File::create(target)?; + let mut tee = TeeWriter::new(&mut target, &mut progress_bar); + copy(&mut source, &mut tee)?; + progress_bar.finish_print("done"); + Ok(()) +} + impl Disk { fn make_song_dir(&self, song: &Song) -> Result<()> { create_dir_all(self.songs.song(&SongArg::Song(song))) @@ -140,7 +154,7 @@ impl Disk { pub fn save_aif(&self, song: &Song, source: &path::PathBuf) -> Result<()> { self.make_song_dir(song)?; - copy(source, self.songs.aif(&SongArg::Song(song)))?; + copy_file(source, &self.songs.aif(&SongArg::Song(song)))?; Ok(()) } @@ -148,9 +162,10 @@ impl Disk { self.make_tape_dir(song)?; for track in tracks { - copy( - track.path(), - self.songs.tape_track(&SongArg::Song(song), track), + println!("copying {}", track); + copy_file( + &path::PathBuf::from(track.path()), + &self.songs.tape_track(&SongArg::Song(song), track), )?; }