Skip to content

Commit 472422d

Browse files
committed
feat: add oss packet build
1 parent 7f31e50 commit 472422d

13 files changed

+561
-150
lines changed

src/App.axaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
x:Class="GeneralUpdate.Tool.Avalonia.App"
44
xmlns:local="using:GeneralUpdate.Tool.Avalonia"
5+
xmlns:semi="https://irihi.tech/semi"
56
RequestedThemeVariant="Default">
6-
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.MergedDictionaries>
10+
<ResourceInclude Source="avares://Nlnet.Avalonia.MessageBox/Assets/Themes.axaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
714
<Application.Styles>
815
<FluentTheme />
9-
<StyleInclude Source="avares://Semi.Avalonia/Themes/Index.axaml" />
16+
<semi:SemiTheme Locale="zh-CN" />
1017
</Application.Styles>
1118
</Application>

src/App.axaml.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ public override void OnFrameworkInitializationCompleted()
1717
{
1818
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
1919
{
20-
desktop.MainWindow = new MainWindow
21-
{
22-
DataContext = new MainWindowViewModel(),
23-
};
20+
desktop.MainWindow = new MainWindow();
2421
}
2522

2623
base.OnFrameworkInitializationCompleted();

src/GeneralUpdate.Tool.Avalonia.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.2" />
2323
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.1" />
2424
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
25-
<PackageReference Include="GeneralUpdate.Core" Version="9.1.2" />
25+
<PackageReference Include="GeneralUpdate.Core" Version="9.1.5" />
26+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2627
<PackageReference Include="Nlnet.Avalonia.MessageBox" Version="1.0.2" />
27-
<PackageReference Include="Semi.Avalonia" Version="11.2.1.1" />
28+
<PackageReference Include="Semi.Avalonia" Version="11.2.1.4" />
2829
</ItemGroup>
2930
</Project>

src/Models/OSSConfigModel.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using CommunityToolkit.Mvvm.ComponentModel;
3+
4+
namespace GeneralUpdate.Tool.Avalonia.Models;
5+
6+
public class OSSConfigModel : ObservableObject
7+
{
8+
private string _packetName, _hash, _version, _url, _jsonContent;
9+
private DateTime _date;
10+
private TimeSpan _time;
11+
12+
public string PacketName
13+
{
14+
get => _packetName;
15+
set
16+
{
17+
SetProperty(ref _packetName, value);
18+
}
19+
}
20+
21+
public string Hash
22+
{
23+
get => _hash;
24+
set
25+
{
26+
SetProperty(ref _hash, value);
27+
}
28+
}
29+
30+
public string Version
31+
{
32+
get => _version;
33+
set
34+
{
35+
SetProperty(ref _version, value);
36+
}
37+
}
38+
39+
public string Url
40+
{
41+
get => _url;
42+
set
43+
{
44+
SetProperty(ref _url, value);
45+
}
46+
}
47+
48+
public string JsonContent
49+
{
50+
get => _jsonContent;
51+
set
52+
{
53+
SetProperty(ref _jsonContent, value);
54+
}
55+
}
56+
57+
public DateTime Date
58+
{
59+
get => _date;
60+
set
61+
{
62+
SetProperty(ref _date, value);
63+
}
64+
}
65+
66+
public TimeSpan Time
67+
{
68+
get => _time;
69+
set
70+
{
71+
SetProperty(ref _time, value);
72+
}
73+
}
74+
75+
public DateTime PubTime
76+
{
77+
get => Date + Time;
78+
}
79+
}

src/Storage/ClipboardUtility.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading.Tasks;
2+
using Avalonia;
3+
using Avalonia.Controls;
4+
using Avalonia.Input;
5+
using Avalonia.Input.Platform;
6+
7+
namespace GeneralUpdate.Tool.Avalonia;
8+
9+
public class ClipboardUtility
10+
{
11+
private static IClipboard? _clipboard = null;
12+
13+
public static async Task SetText(string content)
14+
{
15+
var dataObject = new DataObject();
16+
dataObject.Set(DataFormats.Text, content);
17+
await _clipboard?.SetDataObjectAsync(dataObject);
18+
}
19+
20+
public static void CreateClipboard(Visual visual) => _clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
21+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using CommunityToolkit.Mvvm.ComponentModel;
6+
using CommunityToolkit.Mvvm.Input;
7+
using GeneralUpdate.Tool.Avalonia.Models;
8+
using Newtonsoft.Json;
9+
using Nlnet.Avalonia.Controls;
10+
11+
namespace GeneralUpdate.Tool.Avalonia.ViewModels;
12+
13+
public class OSSPacketViewModel : ObservableObject
14+
{
15+
#region Private Members
16+
17+
private OSSConfigModel? _currnetConfig;
18+
19+
private AsyncRelayCommand? _copyCommand;
20+
private AsyncRelayCommand? _buildCommand;
21+
private RelayCommand? _appendCommand;
22+
private RelayCommand? _clearCommand;
23+
private RelayCommand? _loadedCommand;
24+
25+
#endregion
26+
27+
#region Public Properties
28+
29+
public ObservableCollection<OSSConfigModel> Configs { get; set; } = new();
30+
31+
public OSSConfigModel CurrnetConfig
32+
{
33+
get => _currnetConfig;
34+
set => SetProperty(ref _currnetConfig, value);
35+
}
36+
37+
public AsyncRelayCommand BuildCommand { get => _buildCommand ??= new AsyncRelayCommand(OSSBuildAction); }
38+
39+
public RelayCommand AppendCommand { get => _appendCommand ??= new RelayCommand(AppendAction); }
40+
41+
public AsyncRelayCommand CopyCommand { get => _copyCommand ??= new AsyncRelayCommand(CopyAction); }
42+
43+
public RelayCommand ClearCommand { get => _clearCommand ??= new RelayCommand(ClearAction); }
44+
45+
public RelayCommand LoadedCommand
46+
{
47+
get { return _loadedCommand ??= new (LoadedAction); }
48+
}
49+
50+
#endregion
51+
52+
#region Private Methods
53+
54+
private async Task OSSBuildAction()
55+
{
56+
try
57+
{
58+
var file = await Storage.Instance.SaveFilePickerAsync();
59+
if (file != null)
60+
{
61+
var json = JsonConvert.SerializeObject(Configs);
62+
await File.WriteAllTextAsync(file.Path.AbsolutePath, json, System.Text.Encoding.UTF8);
63+
var caption = string.Empty;
64+
var message = string.Empty;
65+
if (File.Exists(file.Path.AbsolutePath))
66+
{
67+
caption = "Success";
68+
message = "Build success";
69+
}
70+
else
71+
{
72+
caption = "Fail";
73+
message = "Build fail";
74+
}
75+
76+
await MessageBox.ShowAsync(message, caption, Buttons.OK);
77+
}
78+
}
79+
catch (Exception e)
80+
{
81+
await MessageBox.ShowAsync("Build fail", "Fail", Buttons.OK);
82+
}
83+
}
84+
85+
private void AppendAction()
86+
{
87+
try
88+
{
89+
Configs.Add(new OSSConfigModel
90+
{
91+
Date = CurrnetConfig.Date,
92+
Time = CurrnetConfig.Time,
93+
Hash = CurrnetConfig.Hash,
94+
PacketName = CurrnetConfig.PacketName,
95+
Url = CurrnetConfig.Url,
96+
Version = CurrnetConfig.Version
97+
});
98+
var settings = new JsonSerializerSettings
99+
{
100+
Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore
101+
};
102+
CurrnetConfig.JsonContent = JsonConvert.SerializeObject(Configs, settings);
103+
}
104+
catch (Exception e)
105+
{
106+
MessageBox.Show("Append fail", "Fail", Buttons.OK);
107+
}
108+
}
109+
110+
private async Task CopyAction()
111+
{
112+
try
113+
{
114+
await ClipboardUtility.SetText(CurrnetConfig.JsonContent);
115+
await MessageBox.ShowAsync("Copy success", "Success", Buttons.OK);
116+
}
117+
catch (Exception e)
118+
{
119+
await MessageBox.ShowAsync("Copy fail", "Fail", Buttons.OK);
120+
}
121+
}
122+
123+
private void ClearAction()
124+
{
125+
CurrnetConfig.JsonContent = "{}";
126+
Configs.Clear();
127+
}
128+
129+
private void LoadedAction() => Initialize();
130+
131+
private void Initialize()
132+
{
133+
DateTime dateTime = DateTime.Now;
134+
CurrnetConfig = new OSSConfigModel
135+
{
136+
JsonContent = "{}",
137+
PacketName = "Packet1",
138+
Hash = Guid.NewGuid().ToString(),
139+
Date = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day),
140+
Time = new TimeSpan(dateTime.Hour, dateTime.Minute, dateTime.Second),
141+
Version = "1.0.0.0",
142+
Url = "http://127.0.0.1"
143+
};
144+
}
145+
146+
#endregion
147+
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
using CommunityToolkit.Mvvm.ComponentModel;
1010
using CommunityToolkit.Mvvm.Input;
1111
using GeneralUpdate.Common.Compress;
12-
using GeneralUpdate.Common.HashAlgorithms;
1312
using GeneralUpdate.Differential;
1413
using GeneralUpdate.Tool.Avalonia.Models;
1514
using Nlnet.Avalonia.Controls;
1615

1716
namespace GeneralUpdate.Tool.Avalonia.ViewModels;
1817

19-
public class MainWindowViewModel : ObservableObject
18+
public class PacketViewModel : ObservableObject
2019
{
2120
private PacketConfigModel? _configModel;
22-
private Sha256HashAlgorithm _hashAlgorithms = new Sha256HashAlgorithm();
2321

2422
private RelayCommand? _clearCommand;
2523
private RelayCommand? _loadedCommand;

0 commit comments

Comments
 (0)