add move downloaded patcher button
This commit is contained in:
parent
3352ce5e31
commit
320fd072b1
@ -6,12 +6,12 @@
|
||||
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SPTInstaller.CustomControls.Dialogs.WhyCacheThoughDialog">
|
||||
<Grid RowDefinitions="AUTO,AUTO,AUTO,*,AUTO" ColumnDefinitions="*,AUTO"
|
||||
<Grid RowDefinitions="AUTO,AUTO,AUTO,*,AUTO" ColumnDefinitions="*,AUTO, AUTO"
|
||||
Background="{StaticResource AKI_Background_Light}">
|
||||
<Label Content="What is the installer cache for?" FontSize="20"
|
||||
Foreground="{StaticResource AKI_Brush_Yellow}"
|
||||
/>
|
||||
<TextBlock Grid.Row="1" TextWrapping="Wrap" xml:space="preserve">
|
||||
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" TextWrapping="Wrap" xml:space="preserve">
|
||||
The installer cache is used to ensure you don't re-download large files that you've already downloaded before.
|
||||
<Span Foreground="red">You should only delete the cache folder if</Span>
|
||||
- You are low on space
|
||||
@ -23,15 +23,26 @@ It also helps us prevent extra traffic to our limited download mirrors. Every bi
|
||||
</TextBlock>
|
||||
<Label Grid.Row="2" Content="You can find the cache folder here"
|
||||
/>
|
||||
<Button Grid.Row="3" Content="{Binding Source={x:Static helpers:DownloadCacheHelper.CachePath}}"
|
||||
<Button Grid.Row="3" Grid.ColumnSpan="2" Content="{Binding Source={x:Static helpers:DownloadCacheHelper.CachePath}}"
|
||||
Classes="link"
|
||||
Margin="0 10"
|
||||
IsVisible="{Binding CacheExists, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
Command="{Binding OpenCacheFolder, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
/>
|
||||
<Label Grid.Row="3" Content="No cache folder exists"
|
||||
IsVisible="{Binding !CacheExists, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
/>
|
||||
<Button Grid.Row="4" Grid.Column="1" Content="Close" Classes="yellow"
|
||||
|
||||
<Label Grid.Row="4"
|
||||
Content="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AdditionalInfo}"
|
||||
Foreground="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AdditionalInfoColor}"
|
||||
/>
|
||||
|
||||
<Button Grid.Row="4" Grid.Column="1" Content="Move Downloaded Patcher" Margin="0 0 10 0"
|
||||
Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=MoveDownloadsPatcherToCache}"
|
||||
/>
|
||||
|
||||
<Button Grid.Row="4" Grid.Column="2" Content="Close" Classes="yellow"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}"
|
||||
/>
|
||||
</Grid>
|
||||
|
@ -1,15 +1,41 @@
|
||||
using Avalonia.Controls;
|
||||
using SPTInstaller.Helpers;
|
||||
using SPTInstaller.Helpers;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Serilog;
|
||||
|
||||
namespace SPTInstaller.CustomControls.Dialogs;
|
||||
public partial class WhyCacheThoughDialog : UserControl
|
||||
{
|
||||
private int _movePatcherState = 0;
|
||||
|
||||
private FileInfo? _foundPatcher;
|
||||
|
||||
public WhyCacheThoughDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<string> AdditionalInfoProperty =
|
||||
AvaloniaProperty.Register<WhyCacheThoughDialog, string>(nameof(AdditionalInfo));
|
||||
|
||||
public string AdditionalInfo
|
||||
{
|
||||
get => GetValue(AdditionalInfoProperty);
|
||||
set => SetValue(AdditionalInfoProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<string> AdditionalInfoColorProperty =
|
||||
AvaloniaProperty.Register<WhyCacheThoughDialog, string>(nameof(AdditionalInfoColor));
|
||||
|
||||
public string AdditionalInfoColor
|
||||
{
|
||||
get => GetValue(AdditionalInfoColorProperty);
|
||||
set => SetValue(AdditionalInfoColorProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public bool CacheExists => Directory.Exists(DownloadCacheHelper.CachePath);
|
||||
|
||||
public void OpenCacheFolder()
|
||||
@ -24,4 +50,55 @@ public partial class WhyCacheThoughDialog : UserControl
|
||||
Verb = "open"
|
||||
});
|
||||
}
|
||||
|
||||
public void MoveDownloadsPatcherToCache()
|
||||
{
|
||||
switch (_movePatcherState)
|
||||
{
|
||||
case 0:
|
||||
var downloadsPath =
|
||||
Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
|
||||
|
||||
var downloadsFolder = new DirectoryInfo(downloadsPath);
|
||||
|
||||
if (!downloadsFolder.Exists)
|
||||
{
|
||||
AdditionalInfo = "Could not get downloads folder :(";
|
||||
AdditionalInfoColor = "red";
|
||||
_movePatcherState = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
_foundPatcher = downloadsFolder.GetFiles("Patcher_*").FirstOrDefault();
|
||||
|
||||
if (_foundPatcher == null || !_foundPatcher.Exists)
|
||||
{
|
||||
AdditionalInfo =
|
||||
"Could not find a patcher file in your downloads folder";
|
||||
|
||||
AdditionalInfoColor = "red";
|
||||
return;
|
||||
}
|
||||
|
||||
AdditionalInfo = $"Click again to move the below patcher file to the cache folder\n{_foundPatcher?.Name ?? "-SOMETHING WENT WRONG-"}";
|
||||
AdditionalInfoColor = "#FFC107";
|
||||
_movePatcherState = 1;
|
||||
break;
|
||||
case 1:
|
||||
try
|
||||
{
|
||||
var cacheFilePath = Path.Join(DownloadCacheHelper.CachePath, "patcher");
|
||||
_foundPatcher?.MoveTo(cacheFilePath, true);
|
||||
AdditionalInfo = "Patch was moved into cache :D";
|
||||
AdditionalInfoColor = "ForestGreen";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AdditionalInfo = "Something went wrong :(";
|
||||
AdditionalInfoColor = "red";
|
||||
Log.Error(ex, "Failed to move downloaded patcher file into cache");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user