Skip to content

Commit c8975c6

Browse files
committed
change Report interface.
1 parent 5fd22cb commit c8975c6

File tree

9 files changed

+65
-32
lines changed

9 files changed

+65
-32
lines changed

Applications/Ice/Main/Sources/Internal/ExtractExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ internal static class ExtractExtension
8080
///
8181
/* ----------------------------------------------------------------- */
8282
public static string GetText(this ExtractFacade src) =>
83-
src.Report.Current != null ?
84-
src.Report.Current.FullName :
83+
src.Report.Target != null ?
84+
src.Report.Target.FullName :
8585
Properties.Resources.MessagePreExtract;
8686

8787
#endregion

Applications/Ice/Main/Sources/Internal/ProgressExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void SuspendOrResume(this ProgressFacade src)
7878
/* --------------------------------------------------------------------- */
7979
public static string GetTitle(this ProgressFacade src, string path)
8080
{
81-
var percentage = (int)(src.Report.Ratio * 100.0);
81+
var percentage = (int)(src.Report.GetRatio() * 100.0);
8282
var dest = new StringBuilder();
8383
_ = dest.Append($"{percentage}%");
8484
if (path.HasValue()) _ = dest.Append($" - {Io.GetFileName(path)}");

Applications/Ice/Main/Sources/Internal/ReportExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ internal static class ReportExtension
5555
/* ----------------------------------------------------------------- */
5656
public static TimeSpan Estimate(this Report src, TimeSpan elapsed, TimeSpan prev)
5757
{
58-
if (src.Ratio < 0.01 || elapsed <= TimeSpan.Zero) return TimeSpan.Zero;
58+
if (src.GetRatio() < 0.01 || elapsed <= TimeSpan.Zero) return TimeSpan.Zero;
5959

6060
var unit = 10L;
61-
var ratio = Math.Max(1 / src.Ratio - 1.0, 0.0);
61+
var ratio = Math.Max(1 / src.GetRatio() - 1.0, 0.0);
6262
var value = elapsed.TotalSeconds * ratio;
6363
var delta = value - prev.TotalSeconds;
6464

@@ -80,8 +80,8 @@ public static TimeSpan Estimate(this Report src, TimeSpan elapsed, TimeSpan prev
8080
/* ----------------------------------------------------------------- */
8181
public static void CopyTo(this Report src, Report dest)
8282
{
83-
dest.Current = src.Current;
8483
dest.State = src.State;
84+
dest.Target = src.Target;
8585
dest.Count = src.Count;
8686
dest.TotalCount = src.TotalCount;
8787
dest.Bytes = src.Bytes;

Applications/Ice/Main/Sources/Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private static string GetErrorText(Report src)
138138
src.Exception is SevenZipException se ? se.Code.ToString() :
139139
src.Exception.GetType().Name;
140140

141-
if (src.Current is not null) _ = dest.AppendLine(src.Current.RawName);
141+
if (src.Target is not null) _ = dest.AppendLine(src.Target.RawName);
142142

143143
return dest.AppendFormat(Properties.Resources.ErrorGeneric, e)
144144
.AppendLine()

Applications/Ice/Main/Sources/Presenters/Base/ProgressViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public int Value
102102
{
103103
get
104104
{
105-
var src = Math.Max((int)(Facade.Report.Ratio * Unit), 1);
105+
var src = Math.Max((int)(Facade.Report.GetRatio() * Unit), 1);
106106
var cmp = Get<int>();
107107
if (src > cmp) { _ = Set(src); return src; }
108108
else return cmp;

Applications/Ice/Main/Sources/Presenters/Extract/ExtractFacade.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void Invoke(ArchiveReader src, ExtractDirectory dir)
129129
e.CopyTo(Report);
130130
if (Report.State == ProgressState.Success)
131131
{
132-
try { Move(e.Current); }
132+
try { Move(e.Target); }
133133
catch (Exception err)
134134
{
135135
e.State = ProgressState.Failed;
@@ -140,7 +140,7 @@ private void Invoke(ArchiveReader src, ExtractDirectory dir)
140140
else if (Report.State == ProgressState.Failed)
141141
{
142142
Error?.Invoke(e);
143-
if (!e.Cancel) Logger.Warn(() => Move(e.Current));
143+
if (!e.Cancel) Logger.Warn(() => Move(e.Target));
144144
}
145145
});
146146

Libraries/Core/Sources/Internal/Callbacks/CallbackBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ protected SevenZipCode Run(Func<SevenZipCode> func, ProgressState state, Func<En
276276
Cancel = state == ProgressState.Failed,
277277
State = state,
278278
Exception = error,
279-
Current = entity,
279+
Target = entity,
280280
Bytes = Bytes,
281281
Count = Count,
282282
TotalBytes = TotalBytes,

Libraries/Core/Sources/Report.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,26 @@ public class Report
5858

5959
/* --------------------------------------------------------------------- */
6060
///
61-
/// Exception
61+
/// Target
6262
///
6363
/// <summary>
64-
/// Gets or sets an exception object. The property is set when the value
65-
/// of Status is Failed.
64+
/// Gets or sets the file information that is currently processing.
6665
/// </summary>
6766
///
6867
/* --------------------------------------------------------------------- */
69-
public Exception Exception { get; set; }
68+
public Entity Target { get; set; }
7069

7170
/* --------------------------------------------------------------------- */
7271
///
73-
/// Current
72+
/// Exception
7473
///
7574
/// <summary>
76-
/// Gets or sets the file information that is currently processing.
75+
/// Gets or sets an exception object. The property is set when the value
76+
/// of State is Failed.
7777
/// </summary>
7878
///
7979
/* --------------------------------------------------------------------- */
80-
public Entity Current { get; set; }
80+
public Exception Exception { get; set; }
8181

8282
/* --------------------------------------------------------------------- */
8383
///
@@ -123,19 +123,5 @@ public class Report
123123
/* --------------------------------------------------------------------- */
124124
public long TotalBytes { get; set; }
125125

126-
/* --------------------------------------------------------------------- */
127-
///
128-
/// Ratio
129-
///
130-
/// <summary>
131-
/// Gets the progress ratio within the range of [0, 1].
132-
/// </summary>
133-
///
134-
/* --------------------------------------------------------------------- */
135-
public double Ratio => Math.Min(
136-
TotalBytes > 0 ? Bytes / (double)TotalBytes : 0.0,
137-
TotalCount > 0 ? Count / (double)TotalCount : 0.0
138-
);
139-
140126
#endregion
141127
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)