@@ -6,6 +6,7 @@ use zsync_rs::{ControlFile, ZsyncAssembly};
66use crate :: appimage:: AppImage ;
77use crate :: error:: { Error , Result } ;
88use crate :: update_info:: UpdateInfo ;
9+ use crate :: util:: format_size;
910
1011struct UpdateContext {
1112 source_size : u64 ,
@@ -238,10 +239,20 @@ impl Updater {
238239 zsync_url : & str ,
239240 ctx : & UpdateContext ,
240241 ) -> Result < UpdateStats > {
241- let assembly = ZsyncAssembly :: from_url ( zsync_url, output_path)
242+ let mut assembly = ZsyncAssembly :: from_url ( zsync_url, output_path)
242243 . map_err ( |e| Error :: Zsync ( format ! ( "Failed to initialize zsync: {}" , e) ) ) ?;
243244
244- let mut assembly = assembly;
245+ assembly. set_progress_callback ( |done, total| {
246+ let percent = total. checked_div ( 100 ) . map ( |p| done / p) . unwrap_or ( 0 ) ;
247+ print ! (
248+ "\r Progress: {:3}% ({}/{})" ,
249+ percent,
250+ format_size( done) ,
251+ format_size( total)
252+ ) ;
253+ use std:: io:: Write ;
254+ std:: io:: stdout ( ) . flush ( ) . ok ( ) ;
255+ } ) ;
245256
246257 let blocks_reused = assembly
247258 . submit_source_file ( source_path)
@@ -256,6 +267,8 @@ impl Updater {
256267 . download_missing_blocks ( )
257268 . map_err ( |e| Error :: Zsync ( format ! ( "Failed to download blocks: {}" , e) ) ) ?;
258269
270+ println ! ( ) ;
271+
259272 assembly
260273 . complete ( )
261274 . map_err ( |e| Error :: Zsync ( format ! ( "Failed to complete assembly: {}" , e) ) ) ?;
0 commit comments