diff --git a/src/App.axaml b/src/App.axaml
index c97c91d..385b557 100644
--- a/src/App.axaml
+++ b/src/App.axaml
@@ -13,6 +13,6 @@
-
+
\ No newline at end of file
diff --git a/src/Storage/ClipboardUtility.cs b/src/Storage/ClipboardUtility.cs
index 43bc0a1..62a832d 100644
--- a/src/Storage/ClipboardUtility.cs
+++ b/src/Storage/ClipboardUtility.cs
@@ -17,5 +17,8 @@ public static async Task SetText(string content)
await _clipboard?.SetDataObjectAsync(dataObject);
}
- public static void CreateClipboard(Visual visual) => _clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
+ public static void CreateClipboard(Visual visual)
+ {
+ _clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
+ }
}
\ No newline at end of file
diff --git a/src/ViewModels/OSSPacketViewModel.cs b/src/ViewModels/OSSPacketViewModel.cs
index 83303b8..ad37cfe 100644
--- a/src/ViewModels/OSSPacketViewModel.cs
+++ b/src/ViewModels/OSSPacketViewModel.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
+using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
+using GeneralUpdate.Common.HashAlgorithms;
using GeneralUpdate.Tool.Avalonia.Models;
using Newtonsoft.Json;
using Nlnet.Avalonia.Controls;
@@ -18,6 +20,7 @@ public class OSSPacketViewModel : ObservableObject
private AsyncRelayCommand? _copyCommand;
private AsyncRelayCommand? _buildCommand;
+ private AsyncRelayCommand? _hashCommand;
private RelayCommand? _appendCommand;
private RelayCommand? _clearCommand;
private RelayCommand? _loadedCommand;
@@ -39,7 +42,9 @@ public OSSConfigModel CurrnetConfig
public RelayCommand AppendCommand { get => _appendCommand ??= new RelayCommand(AppendAction); }
public AsyncRelayCommand CopyCommand { get => _copyCommand ??= new AsyncRelayCommand(CopyAction); }
-
+
+ public AsyncRelayCommand HashCommand { get => _hashCommand ??= new AsyncRelayCommand(HashAction); }
+
public RelayCommand ClearCommand { get => _clearCommand ??= new RelayCommand(ClearAction); }
public RelayCommand LoadedCommand
@@ -119,7 +124,20 @@ private async Task CopyAction()
await MessageBox.ShowAsync("Copy fail", "Fail", Buttons.OK);
}
}
+
+ private async Task HashAction()
+ {
+ var files = await Storage.Instance.OpenFileDialog();
+ if (files is null || files.Count == 0) return;
+ var file = files.First();
+ if (file is not null)
+ {
+ Sha256HashAlgorithm hashAlgorithm = new();
+ CurrnetConfig.Hash = hashAlgorithm.ComputeHash(file.Path.AbsolutePath);
+ }
+ }
+
private void ClearAction()
{
CurrnetConfig.JsonContent = "{}";
@@ -134,8 +152,8 @@ private void Initialize()
CurrnetConfig = new OSSConfigModel
{
JsonContent = "{}",
- PacketName = "Packet1",
- Hash = Guid.NewGuid().ToString(),
+ PacketName = "Packet",
+ Hash = String.Empty,
Date = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day),
Time = new TimeSpan(dateTime.Hour, dateTime.Minute, dateTime.Second),
Version = "1.0.0.0",
diff --git a/src/Views/MainWindow.axaml.cs b/src/Views/MainWindow.axaml.cs
index dfb7280..566165c 100644
--- a/src/Views/MainWindow.axaml.cs
+++ b/src/Views/MainWindow.axaml.cs
@@ -8,5 +8,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
+ ClipboardUtility.CreateClipboard(this);
+ Storage.Instance.SetStorageProvider(this);
}
}
\ No newline at end of file
diff --git a/src/Views/OSSPacketView.axaml b/src/Views/OSSPacketView.axaml
index c4509f8..05dadee 100644
--- a/src/Views/OSSPacketView.axaml
+++ b/src/Views/OSSPacketView.axaml
@@ -14,7 +14,7 @@
-
+
+
diff --git a/src/Views/OSSPacketView.axaml.cs b/src/Views/OSSPacketView.axaml.cs
index bea47cd..64f4dd6 100644
--- a/src/Views/OSSPacketView.axaml.cs
+++ b/src/Views/OSSPacketView.axaml.cs
@@ -8,7 +8,6 @@ public partial class OSSPacketView : UserControl
public OSSPacketView()
{
InitializeComponent();
- ClipboardUtility.CreateClipboard(this);
DataContext = new OSSPacketViewModel();
}
}
\ No newline at end of file
diff --git a/src/Views/PacketView.axaml.cs b/src/Views/PacketView.axaml.cs
index 731c8f2..6397918 100644
--- a/src/Views/PacketView.axaml.cs
+++ b/src/Views/PacketView.axaml.cs
@@ -10,7 +10,6 @@ public partial class PacketView : UserControl
public PacketView()
{
InitializeComponent();
- Storage.Instance.SetStorageProvider(this);
DataContext = new PacketViewModel();
}
}
\ No newline at end of file