From 472f506817bb1af2fceb039ba148d15723944562 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Thu, 25 Feb 2016 13:47:30 -0600 Subject: Improve progress bar handling for backup / restore / image flash The progress bar will now be updated during image backups, restores and during image flashing (except for sparse images which will require significant changes to libsparse, and except for mtd nand using flash_utils). The progress bar will now be updated mid-file for file systems (tar) so the user will see changes even during large file backup / restore. Add a new progress tracking class to simplify handling of progress bar updates. The class will only update the progress bar 5 times a second to reduce the CPU load from updating the GUI frequently which does affect backup times. Change-Id: Iff382faef3df1f86604af336c1a8ce8993cd12c5 --- progresstracking.hpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 progresstracking.hpp (limited to 'progresstracking.hpp') diff --git a/progresstracking.hpp b/progresstracking.hpp new file mode 100644 index 000000000..15cf91c28 --- /dev/null +++ b/progresstracking.hpp @@ -0,0 +1,54 @@ +/* + Copyright 2016 bigbiff/Dees_Troy TeamWin + This file is part of TWRP/TeamWin Recovery Project. + + TWRP is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + TWRP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TWRP. If not, see . +*/ + +#ifndef __PROGRESSTRACKING_HPP +#define __PROGRESSTRACKING_HPP + +#include + +// Progress tracking class for tracking backup progess and updating the progress bar as appropriate +class ProgressTracking +{ +public: + ProgressTracking(const unsigned long long backup_size); + + void SetPartitionSize(const unsigned long long part_size); + void SetSizeCount(const unsigned long long part_size, unsigned long long f_count); + + void UpdateSize(const unsigned long long size); + void UpdateSizeCount(const unsigned long long size, const unsigned long long count); + + void DisplayFileCount(const bool display); + void UpdateDisplayDetails(const bool force); + +private: + unsigned long long total_backup_size; // Overall size (for the progress bar) + + unsigned long long partition_size; // Size of the current partition + unsigned long long file_count; // Count of files for the current partition (tar backup only, not restore) + + unsigned long long current_size; // Size of the current partition's already backed up data + unsigned long long current_count; // Count of files that have already been backed up for the current partition + + unsigned long long previous_partitions_size; // Total data already backed up from previous partitions (for the progress bar) + + bool display_file_count; // Inidicates if we will display the file count text + timespec last_update; // Tracks last update of the displayed progress (frequent updates tax the CPU and slow us down) +}; + +#endif //__PROGRESSTRACKING_HPP -- cgit v1.2.3