Merge pull request 'add move downloaded patcher button' (#59) from waffle.lord/SPT-AKI-Installer:imp/move-patcher-button into master
Reviewed-on: CWX/SPT-AKI-Installer#59
This commit is contained in:
commit
8687768d2f
@ -6,12 +6,12 @@
|
|||||||
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
|
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="SPTInstaller.CustomControls.Dialogs.WhyCacheThoughDialog">
|
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}">
|
Background="{StaticResource AKI_Background_Light}">
|
||||||
<Label Content="What is the installer cache for?" FontSize="20"
|
<Label Content="What is the installer cache for?" FontSize="20"
|
||||||
Foreground="{StaticResource AKI_Brush_Yellow}"
|
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.
|
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>
|
<Span Foreground="red">You should only delete the cache folder if</Span>
|
||||||
- You are low on space
|
- You are low on space
|
||||||
@ -23,15 +23,26 @@ It also helps us prevent extra traffic to our limited download mirrors. Every bi
|
|||||||
</TextBlock>
|
</TextBlock>
|
||||||
<Label Grid.Row="2" Content="You can find the cache folder here"
|
<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"
|
Classes="link"
|
||||||
|
Margin="0 10"
|
||||||
IsVisible="{Binding CacheExists, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
IsVisible="{Binding CacheExists, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||||
Command="{Binding OpenCacheFolder, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
Command="{Binding OpenCacheFolder, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||||
/>
|
/>
|
||||||
<Label Grid.Row="3" Content="No cache folder exists"
|
<Label Grid.Row="3" Content="No cache folder exists"
|
||||||
IsVisible="{Binding !CacheExists, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
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}"
|
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}"
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -1,15 +1,41 @@
|
|||||||
using Avalonia.Controls;
|
using SPTInstaller.Helpers;
|
||||||
using SPTInstaller.Helpers;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace SPTInstaller.CustomControls.Dialogs;
|
namespace SPTInstaller.CustomControls.Dialogs;
|
||||||
public partial class WhyCacheThoughDialog : UserControl
|
public partial class WhyCacheThoughDialog : UserControl
|
||||||
{
|
{
|
||||||
|
private int _movePatcherState = 0;
|
||||||
|
|
||||||
|
private FileInfo? _foundPatcher;
|
||||||
|
|
||||||
public WhyCacheThoughDialog()
|
public WhyCacheThoughDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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 bool CacheExists => Directory.Exists(DownloadCacheHelper.CachePath);
|
||||||
|
|
||||||
public void OpenCacheFolder()
|
public void OpenCacheFolder()
|
||||||
@ -24,4 +50,55 @@ public partial class WhyCacheThoughDialog : UserControl
|
|||||||
Verb = "open"
|
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