11using System ;
22using System . Collections . ObjectModel ;
33using System . IO ;
4+ using System . Linq ;
45using System . Threading . Tasks ;
56using CommunityToolkit . Mvvm . ComponentModel ;
67using CommunityToolkit . Mvvm . Input ;
8+ using GeneralUpdate . Common . HashAlgorithms ;
79using GeneralUpdate . Tool . Avalonia . Models ;
810using Newtonsoft . Json ;
911using Nlnet . Avalonia . Controls ;
@@ -18,6 +20,7 @@ public class OSSPacketViewModel : ObservableObject
1820
1921 private AsyncRelayCommand ? _copyCommand ;
2022 private AsyncRelayCommand ? _buildCommand ;
23+ private AsyncRelayCommand ? _hashCommand ;
2124 private RelayCommand ? _appendCommand ;
2225 private RelayCommand ? _clearCommand ;
2326 private RelayCommand ? _loadedCommand ;
@@ -39,7 +42,9 @@ public OSSConfigModel CurrnetConfig
3942 public RelayCommand AppendCommand { get => _appendCommand ??= new RelayCommand ( AppendAction ) ; }
4043
4144 public AsyncRelayCommand CopyCommand { get => _copyCommand ??= new AsyncRelayCommand ( CopyAction ) ; }
42-
45+
46+ public AsyncRelayCommand HashCommand { get => _hashCommand ??= new AsyncRelayCommand ( HashAction ) ; }
47+
4348 public RelayCommand ClearCommand { get => _clearCommand ??= new RelayCommand ( ClearAction ) ; }
4449
4550 public RelayCommand LoadedCommand
@@ -119,7 +124,20 @@ private async Task CopyAction()
119124 await MessageBox . ShowAsync ( "Copy fail" , "Fail" , Buttons . OK ) ;
120125 }
121126 }
127+
128+ private async Task HashAction ( )
129+ {
130+ var files = await Storage . Instance . OpenFileDialog ( ) ;
131+ if ( files is null || files . Count == 0 ) return ;
122132
133+ var file = files . First ( ) ;
134+ if ( file is not null )
135+ {
136+ Sha256HashAlgorithm hashAlgorithm = new ( ) ;
137+ CurrnetConfig . Hash = hashAlgorithm . ComputeHash ( file . Path . AbsolutePath ) ;
138+ }
139+ }
140+
123141 private void ClearAction ( )
124142 {
125143 CurrnetConfig . JsonContent = "{}" ;
@@ -134,8 +152,8 @@ private void Initialize()
134152 CurrnetConfig = new OSSConfigModel
135153 {
136154 JsonContent = "{}" ,
137- PacketName = "Packet1 " ,
138- Hash = Guid . NewGuid ( ) . ToString ( ) ,
155+ PacketName = "Packet " ,
156+ Hash = String . Empty ,
139157 Date = new DateTime ( dateTime . Year , dateTime . Month , dateTime . Day ) ,
140158 Time = new TimeSpan ( dateTime . Hour , dateTime . Minute , dateTime . Second ) ,
141159 Version = "1.0.0.0" ,
0 commit comments