@@ -22,7 +22,7 @@ class FileCopyDialog {
22
22
private readonly ProgressBar _progressTotal ;
23
23
private readonly ProgressBar _progressCurrent ;
24
24
private readonly Label _labelTotal ;
25
- private readonly Label _labelCurrent ;
25
+ // private readonly Label _labelCurrent;
26
26
private long _copiedTotal = 0 ;
27
27
private long _sizeTotal = 0 ;
28
28
@@ -37,7 +37,7 @@ public FileCopyDialog(View parent, FSView from, FSView to) {
37
37
_cts . Cancel ( ) ;
38
38
} ;
39
39
40
- _dialog = new Dialog ( "Copy files" , width / 2 , 10 , cancel ) ;
40
+ _dialog = new Dialog ( "Copy files" , width / 2 , 7 , cancel ) ;
41
41
42
42
var lbl = new Label ( " total: " ) { X = 0 , Y = 0 } ;
43
43
_dialog . Add ( lbl ) ;
@@ -50,21 +50,24 @@ public FileCopyDialog(View parent, FSView from, FSView to) {
50
50
} ;
51
51
_dialog . Add ( _progressTotal ) ;
52
52
53
- _labelTotal = new Label ( "0 / 0" ) { X = 0 , Y = Pos . Bottom ( lbl ) } ;
54
- _dialog . Add ( _labelTotal ) ;
53
+ // _labelTotal = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
54
+ // _dialog.Add(_labelTotal);
55
55
56
- lbl = new Label ( "current: " ) { X = 0 , Y = Pos . Bottom ( _labelTotal ) } ;
56
+ lbl = new Label ( "current: " ) { X = 0 , Y = Pos . Bottom ( lbl ) } ;
57
57
_dialog . Add ( lbl ) ;
58
58
_progressCurrent = new ProgressBar ( ) {
59
59
X = Pos . Right ( lbl ) ,
60
- Y = Pos . Bottom ( _progressTotal ) ,
60
+ Y = 1 ,
61
61
Width = Dim . Fill ( ) ,
62
62
Height = 1
63
63
} ;
64
64
_dialog . Add ( _progressCurrent ) ;
65
65
66
- _labelCurrent = new Label ( "0 / 0" ) { X = 0 , Y = Pos . Bottom ( lbl ) } ;
67
- _dialog . Add ( _labelCurrent ) ;
66
+ //_labelCurrent = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
67
+ //_dialog.Add(_labelCurrent);
68
+
69
+ _labelTotal = new Label ( "?" ) { X = 0 , Y = Pos . Bottom ( lbl ) } ;
70
+ _dialog . Add ( _labelTotal ) ;
68
71
}
69
72
70
73
public void Start ( ) {
@@ -98,15 +101,21 @@ private async Task Copy(IFileStorage fsFrom, IFileStorage fsTo, IOPath pathFrom,
98
101
byte [ ] buffer = ArrayPool < byte > . Shared . Rent ( DefaultCopyBufferSize ) ;
99
102
try {
100
103
int bytesRead ;
104
+ long totalRead = 0 ;
101
105
while ( ( bytesRead = await streamFrom . ReadAsync ( new Memory < byte > ( buffer ) , _cts . Token ) ) != 0 ) {
102
106
await streamTo . WriteAsync ( new ReadOnlyMemory < byte > ( buffer , 0 , bytesRead ) , _cts . Token ) ;
103
- float fraction = streamFrom . Position / ( float ) streamFrom . Length ;
107
+
108
+ _copiedTotal += bytesRead ;
109
+ totalRead += bytesRead ;
110
+ float fracCurrent = totalRead / ( float ) streamFrom . Length ;
111
+ float fracTotal = _copiedTotal / ( float ) _sizeTotal ;
112
+ string status = $ "{ _copiedTotal . Bytes ( ) } / { _sizeTotal . Bytes ( ) } ";
104
113
105
114
Application . MainLoop . Invoke ( ( ) => {
106
- _progressCurrent . Fraction = fraction ;
107
- _copiedTotal += bytesRead ;
108
- _labelCurrent . Text = $ " { streamFrom . Position . Bytes ( ) } / { streamFrom . Length . Bytes ( ) } " ;
109
- _labelTotal . Text = $ " { _copiedTotal . Bytes ( ) } / { _sizeTotal . Bytes ( ) } " ;
115
+
116
+ _progressCurrent . Fraction = fracCurrent ;
117
+ _progressTotal . Fraction = fracTotal ;
118
+ _labelTotal . Text = status ;
110
119
} ) ;
111
120
}
112
121
@@ -127,14 +136,8 @@ private void RunCopy() {
127
136
IReadOnlyCollection < IOEntry > sourceEntries = await Explode ( _from . Fs , _from . SelectedEntry ! ) ;
128
137
_sizeTotal = sourceEntries . Sum ( e => e . Size ! . Value ) ;
129
138
130
- int i = 0 ;
131
139
foreach ( IOEntry entry in sourceEntries ) {
132
-
133
140
await Copy ( _from . Fs , _to . Fs , entry . Path , _to . CurrentPath . Combine ( entry . Path . Name ) ) ;
134
-
135
- Application . MainLoop . Invoke ( ( ) => {
136
- _progressTotal . Fraction = i ++ * 100.0f / sourceEntries . Count ;
137
- } ) ;
138
141
}
139
142
} catch ( Exception ex1 ) {
140
143
ex = ex1 ;
@@ -143,8 +146,10 @@ private void RunCopy() {
143
146
Application . MainLoop . Invoke ( ( ) => {
144
147
if ( ex != null ) {
145
148
MessageBox . ErrorQuery ( 60 , 10 , "Error" , ex . ToString ( ) , "Ok" ) ;
149
+ } else {
150
+ MessageBox . Query ( 60 , 5 , "Done" , "Files copied." , "Ok" ) ;
151
+ Application . RequestStop ( ) ;
146
152
}
147
- Application . RequestStop ( ) ;
148
153
} ) ;
149
154
} ) ;
150
155
}
0 commit comments