Skip to content

Commit

Permalink
fate: add get file hash
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Feb 14, 2025
1 parent 472422d commit a049600
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</Application.Resources>
<Application.Styles>
<FluentTheme />
<semi:SemiTheme Locale="zh-CN" />
<semi:SemiTheme />
</Application.Styles>
</Application>
5 changes: 4 additions & 1 deletion src/Storage/ClipboardUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ public static async Task SetText(string content)
await _clipboard?.SetDataObjectAsync(dataObject);

Check warning on line 17 in src/Storage/ClipboardUtility.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

public static void CreateClipboard(Visual visual) => _clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
public static void CreateClipboard(Visual visual)
{
_clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
}
}
24 changes: 21 additions & 3 deletions src/ViewModels/OSSPacketViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 = "{}";
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
ClipboardUtility.CreateClipboard(this);
Storage.Instance.SetStorageProvider(this);
}
}
3 changes: 2 additions & 1 deletion src/Views/OSSPacketView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ia:InvokeCommandAction Command="{Binding LoadedCommand}"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<Grid RowDefinitions="9*,1*">
<Grid RowDefinitions="8*,1*">
<Grid ColumnDefinitions="2*,4*,4*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,*">
<!-- 发布时间 -->
<TextBlock
Expand Down Expand Up @@ -100,6 +100,7 @@
VerticalAlignment="Center"
Orientation="Horizontal"
Spacing="10">
<Button Classes="Primary" Command="{Binding HashCommand}" Content="Hash" toolTip:ToolTip.Tip="Hash"></Button>
<Button Classes="Primary" Command="{Binding AppendCommand}" toolTip:ToolTip.Tip="Append">
<PathIcon Width="15" Height="15" Data="M602.251 885.76H165.203a28.738 28.738 0 0 1-20.186-8.605 28.644 28.644 0 0 1-8.189-20.377V167.331c0-16.063 12.695-28.991 28.375-28.991H756.8c15.702 0 28.321 12.928 28.321 28.991v378.33c0 20.547 16.361 37.204 36.46 37.204 20.164 0 36.438-16.657 36.438-37.204v-378.33c0-57.155-45.341-103.462-101.282-103.462H165.203c-55.943 0-101.284 46.307-101.284 103.462v689.447c0 57.133 45.341 103.451 101.284 103.451H602.25c20.184 0 36.545-16.657 36.545-37.202a36.852 36.852 0 0 0-10.539-26.219 36.844 36.844 0 0 0-26.005-11.048zM261.122 340.247c29.086 0 52.66-23.573 52.66-52.66 0-29.087-23.573-52.66-52.66-52.66-29.087 0-52.66 23.573-52.66 52.66 0 29.086 23.574 52.66 52.66 52.66z m199.89 0c29.076 0 52.66-23.573 52.66-52.66 0-29.087-23.584-52.66-52.66-52.66-29.087 0-52.671 23.573-52.671 52.66 0 29.086 23.585 52.66 52.671 52.66z m199.88 0c29.087 0 52.671-23.573 52.671-52.66 0-29.087-23.584-52.66-52.671-52.66s-52.649 23.573-52.649 52.66c-0.001 29.086 23.562 52.66 52.649 52.66zM245.653 477.693h411.731c20.569 0 37.248 16.668 37.248 37.224 0 20.569-16.679 37.248-37.248 37.248H245.653c-13.3 0-25.59-7.097-32.241-18.613a37.257 37.257 0 0 1 0-37.246 37.234 37.234 0 0 1 32.241-18.613z m0 201.313h249.715c20.567 0 37.235 16.659 37.235 37.226s-16.668 37.245-37.235 37.245H245.653c-20.567 0-37.235-16.679-37.235-37.245s16.669-37.226 37.235-37.226z m679.378 89.174h-72.537v-78.126c0-20.608-13.661-37.35-33.166-37.35-19.42 0-33.103 16.742-33.103 37.35v78.061h-72.6c-20.014 0.596-35.757 17.316-35.185 37.352 0 20.61 15.702 33.975 35.185 33.975h72.622v74.704c0 20.693 13.661 37.352 33.081 37.352 19.505 0 33.166-16.659 33.166-37.352v-74.704h72.537c19.483 0 35.248-13.365 35.248-33.975 0-20.693-15.68-37.352-35.248-37.352" />
</Button>
Expand Down
1 change: 0 additions & 1 deletion src/Views/OSSPacketView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public partial class OSSPacketView : UserControl
public OSSPacketView()
{
InitializeComponent();
ClipboardUtility.CreateClipboard(this);
DataContext = new OSSPacketViewModel();
}
}
1 change: 0 additions & 1 deletion src/Views/PacketView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public partial class PacketView : UserControl
public PacketView()
{
InitializeComponent();
Storage.Instance.SetStorageProvider(this);
DataContext = new PacketViewModel();
}
}

0 comments on commit a049600

Please sign in to comment.