|
| 1 | +/* ------------------------------------------------------------------------- */ |
| 2 | +// |
| 3 | +// Copyright (c) 2010 CubeSoft, Inc. |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU Lesser General Public License as |
| 7 | +// published by the Free Software Foundation, either version 3 of the |
| 8 | +// License, or (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU Lesser General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU Lesser General Public License |
| 16 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +// |
| 18 | +/* ------------------------------------------------------------------------- */ |
| 19 | +namespace Cube.FileSystem.SevenZip; |
| 20 | + |
| 21 | +using System; |
| 22 | + |
| 23 | +/* ------------------------------------------------------------------------- */ |
| 24 | +/// |
| 25 | +/// ReportExtension |
| 26 | +/// |
| 27 | +/// <summary> |
| 28 | +/// Provides extended methods of the Report class. |
| 29 | +/// </summary> |
| 30 | +/// |
| 31 | +/* ------------------------------------------------------------------------- */ |
| 32 | +public static class ReportExtension |
| 33 | +{ |
| 34 | + /* --------------------------------------------------------------------- */ |
| 35 | + /// |
| 36 | + /// GetRatio |
| 37 | + /// |
| 38 | + /// <summary> |
| 39 | + /// Gets the progress ratio within the range of [0, 1]. |
| 40 | + /// </summary> |
| 41 | + /// |
| 42 | + /* --------------------------------------------------------------------- */ |
| 43 | + public static double GetRatio(this Report src) => Math.Min( |
| 44 | + src.TotalBytes > 0 ? src.Bytes / (double)src.TotalBytes : 0.0, |
| 45 | + src.TotalCount > 0 ? src.Count / (double)src.TotalCount : 0.0 |
| 46 | + ); |
| 47 | +} |
0 commit comments