11using System . ComponentModel ;
2- using System . IO ;
2+ using System . Threading ;
3+ using System . Threading . Tasks ;
4+ using ByteSizeLib ;
35using CommunityToolkit . Mvvm . ComponentModel ;
46using OwlCore . Storage ;
7+ using SecureFolderFS . Shared . ComponentModel ;
8+ using SecureFolderFS . Storage . Extensions ;
59
610namespace SecureFolderFS . Sdk . ViewModels . Views . Overlays
711{
812 [ Bindable ( true ) ]
9- public sealed partial class VaultItemInfoOverlayViewModel : OverlayViewModel
13+ public sealed partial class VaultItemInfoOverlayViewModel : OverlayViewModel , IAsyncInitialize
1014 {
15+ private readonly IStorable _ciphertextItem ;
16+ private readonly IStorable _plaintextItem ;
17+
18+ [ ObservableProperty ] private string ? _PlaintextSize ;
19+ [ ObservableProperty ] private string ? _PlaintextFullSize ;
20+ [ ObservableProperty ] private string ? _CiphertextSize ;
21+ [ ObservableProperty ] private string ? _CiphertextFullSize ;
1122 [ ObservableProperty ] private string ? _PlaintextName ;
1223 [ ObservableProperty ] private string ? _CiphertextName ;
1324 [ ObservableProperty ] private string ? _PlaintextPath ;
1425 [ ObservableProperty ] private string ? _CiphertextPath ;
1526 [ ObservableProperty ] private bool _IsFile ;
1627
17- public VaultItemInfoOverlayViewModel ( IStorable ciphertextItem , string plaintextPath )
28+ public VaultItemInfoOverlayViewModel ( IStorable ciphertextItem , IStorable plaintextItem )
1829 {
1930 IsFile = ciphertextItem is IFile ;
20- CiphertextPath = ciphertextItem . Id ;
21- CiphertextName = ciphertextItem . Name ;
22- PlaintextPath = plaintextPath . Replace ( Path . AltDirectorySeparatorChar , Path . DirectorySeparatorChar ) ;
23- PlaintextName = Path . GetFileName ( plaintextPath ) ;
31+ _ciphertextItem = ciphertextItem ;
32+ _plaintextItem = plaintextItem ;
33+ }
34+
35+ /// <inheritdoc/>
36+ public async Task InitAsync ( CancellationToken cancellationToken = default )
37+ {
38+ CiphertextPath = _ciphertextItem . Id ;
39+ CiphertextName = _ciphertextItem . Name ;
40+ PlaintextPath = _plaintextItem . Id ;
41+ PlaintextName = _plaintextItem . Name ;
42+
43+ if ( ! IsFile )
44+ return ;
45+
46+ var ciphertextSize = await ( ( IFile ) _ciphertextItem ) . GetSizeAsync ( cancellationToken ) ;
47+ var plaintextSize = await ( ( IFile ) _plaintextItem ) . GetSizeAsync ( cancellationToken ) ;
48+
49+ if ( ciphertextSize . HasValue )
50+ {
51+ CiphertextSize = ByteSize . FromBytes ( ciphertextSize . Value ) . ToString ( ) ;
52+ CiphertextFullSize = $ "{ ciphertextSize . Value } B";
53+ }
54+
55+ if ( plaintextSize . HasValue )
56+ {
57+ PlaintextSize = ByteSize . FromBytes ( plaintextSize . Value ) . ToString ( ) ;
58+ PlaintextFullSize = $ "{ plaintextSize . Value } B";
59+
60+ if ( ciphertextSize . HasValue )
61+ {
62+ var difference = ciphertextSize . Value - plaintextSize . Value ;
63+ CiphertextSize += $ " (+{ ByteSize . FromBytes ( difference ) } )";
64+ }
65+ }
2466 }
2567 }
2668}
0 commit comments