Skip to content

Commit

Permalink
Merge pull request #136 from ONLOX/dev
Browse files Browse the repository at this point in the history
Exception List in Installer
  • Loading branch information
ONLOX authored Mar 17, 2024
2 parents 2976179 + 67536d6 commit 360252f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 19 deletions.
2 changes: 1 addition & 1 deletion installer/Model/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public override void Dispose()
public class ExceptionStack
{
public Logger logger;
protected ConcurrentStack<Exception> Exceptions;
public ConcurrentStack<Exception> Exceptions;
protected object? Source;
public event EventHandler? OnFailed;
public event EventHandler? OnFailProcessed;
Expand Down
48 changes: 40 additions & 8 deletions installer/Page/InstallPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
x:Class="installer.Page.InstallPage"
Title="Installer">

<VerticalStackLayout
<Grid
HorizontalOptions="Center"
WidthRequest="600">

<HorizontalStackLayout>
WidthRequest="600"
RowDefinitions="*,*,*,*,*,*,*,*,*,*,*,*"
ColumnDefinitions="*">

<HorizontalStackLayout
Grid.Row="1">
<Label
WidthRequest="100"
Text="文件路径:"
Expand All @@ -29,14 +32,18 @@
BackgroundColor="{Binding ConstBackgroundColor}"
TextColor="{Binding ConstTextColor}"/>
</HorizontalStackLayout>

<Button
Grid.Row="2"
Text="下载"
Command="{Binding DownloadBtnClickedCommand}"
IsEnabled="{Binding DownloadEnabled}"
BackgroundColor="{Binding ConstBackgroundColor}"
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>
<HorizontalStackLayout>

<HorizontalStackLayout
Grid.Row="3">
<Button
WidthRequest="200"
Text="检查更新"
Expand All @@ -54,12 +61,37 @@
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>
</HorizontalStackLayout>

<Label
Grid.Row="4"
Text="{Binding DebugAlert1}"/>
<Label
Grid.Row="5"
Text="{Binding DebugAlert2}"/>
<Label
Text="{Binding DebugAlert3}"/>
</VerticalStackLayout>

<CollectionView
WidthRequest="570"
Grid.Row="6"
Grid.RowSpan="3"
BackgroundColor="Grey"
ItemsSource="{Binding Exceptions}"
ItemsUpdatingScrollMode="KeepLastItemInView"
VerticalScrollBarVisibility="Always">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid
HorizontalOptions="Center"
WidthRequest="550">

<Label
Text="{Binding Message}"
TextColor="Black"/>

</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

</Grid>

</ContentPage>
52 changes: 42 additions & 10 deletions installer/ViewModel/InstallViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using CommunityToolkit.Maui;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -15,13 +17,16 @@ public class InstallViewModel : BaseViewModel
{
private readonly Model.Downloader Downloader;
private readonly IFolderPicker FolderPicker;
public ObservableCollection<Exception> Exceptions { get; private set; }

public InstallViewModel(IFolderPicker folderPicker, Model.Downloader downloader)
{
Downloader = downloader;
FolderPicker = folderPicker;
Exceptions = new ObservableCollection<Exception>();

downloadPath = Downloader.Data.InstallPath;
DebugAlert3 = Downloader.Data.Installed.ToString();

BrowseBtnClickedCommand = new AsyncRelayCommand(BrowseBtnClicked);
CheckUpdBtnClickedCommand = new RelayCommand(CheckUpdBtnClicked);
DownloadBtnClickedCommand = new AsyncRelayCommand(DownloadBtnClicked);
Expand Down Expand Up @@ -58,6 +63,16 @@ public string? DebugAlert3
OnPropertyChanged();
}
}
private string? debugAlert4;
public string? DebugAlert4
{
get => debugAlert4;
set
{
debugAlert4 = value;
OnPropertyChanged();
}
}

private string downloadPath;
public string DownloadPath
Expand All @@ -67,11 +82,11 @@ public string DownloadPath
{
downloadPath = value;
DownloadEnabled =
Directory.Exists(value)
&& Local_Data.CountFile(value) == 0 && Local_Data.CountFile(value) == 0;
!value.EndsWith(':') && !value.EndsWith('\\')
&& Directory.Exists(value) && Local_Data.CountFile(value) == 0;
CheckEnabled =
Directory.Exists(value)
&& (Local_Data.CountFile(value) > 0 || Local_Data.CountFile(value) > 0);
!value.EndsWith(':') && !value.EndsWith('\\')
&& Directory.Exists(value) && Local_Data.CountFile(value) > 0;
OnPropertyChanged();
}
}
Expand All @@ -81,7 +96,7 @@ public bool BrowseEnabled
get => browseEnabled;
set
{
browseEnabled = value;
browseEnabled = Downloader.Data.Installed && value;
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -117,6 +132,21 @@ public bool UpdateEnabled
}
}

// private int cnt = 1;
public void UpdateExceptions()
{
while (Downloader.Exceptions.Count > 0)
{
var exception = Downloader.Exceptions.Pop();
if (exception != null)
{
Exceptions.Add(exception);
}
}
// Exceptions.Add(new Exception($"exp {cnt}"));
// cnt ++;
}

public ICommand BrowseBtnClickedCommand { get; }
private async Task BrowseBtnClicked()
{
Expand All @@ -129,14 +159,13 @@ private async Task BrowseBtnClicked()
if (result.IsSuccessful)
{
DownloadPath = result.Folder.Path;
// DebugAlert2 = result.Folder.Path.ToString();
}
else
{
DownloadPath = DownloadPath;
}
BrowseEnabled = true;

UpdateExceptions();
}
public ICommand CheckUpdBtnClickedCommand { get; }
private async void CheckUpdBtnClicked()
Expand All @@ -159,6 +188,7 @@ private async void CheckUpdBtnClicked()
}
BrowseEnabled = true;
CheckEnabled = true;
UpdateExceptions();
}
public ICommand DownloadBtnClickedCommand { get; }
private async Task DownloadBtnClicked()
Expand All @@ -174,11 +204,12 @@ private async Task DownloadBtnClicked()
}
else
{
await Task.Run(() => Downloader.Install());
await Task.Run(() => Downloader.Install(DownloadPath));
}
DebugAlert2 = Downloader.Data.InstallPath;
CheckEnabled = true;
BrowseEnabled = true;
UpdateExceptions();
// DebugAlert2 = "Installed" + Downloader.Data.Installed.ToString();
}
public ICommand UpdateBtnClickedCommand { get; }
private async Task UpdateBtnClicked()
Expand All @@ -191,6 +222,7 @@ private async Task UpdateBtnClicked()
await Task.Run(() => Downloader.Update());
CheckEnabled = true;
BrowseEnabled = true;
UpdateExceptions();
}
}
}

0 comments on commit 360252f

Please sign in to comment.