add clear cache metadata button
This commit is contained in:
parent
080cc0ab35
commit
8711bca159
@ -6,7 +6,7 @@
|
||||
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, AUTO"
|
||||
<Grid RowDefinitions="AUTO,AUTO,AUTO,*,AUTO" ColumnDefinitions="*,AUTO"
|
||||
Background="{StaticResource AKI_Background_Light}">
|
||||
<Label Content="What is the installer cache for?" FontSize="20"
|
||||
Foreground="{StaticResource AKI_Brush_Yellow}" />
|
||||
@ -16,7 +16,6 @@ The installer cache is used to ensure you don't re-download large files that you
|
||||
- You are low on space
|
||||
or
|
||||
- You are not planning on installing SPT again any time soon
|
||||
|
||||
If possible, you should leave the cache in place to avoid uneccessary, lengthy downloads.
|
||||
It also helps us prevent extra traffic to our limited download mirrors. Every bit helps <Span Foreground="red"
|
||||
FontSize="25">♥️</Span>
|
||||
@ -25,7 +24,6 @@ It also helps us prevent extra traffic to our limited download mirrors. Every bi
|
||||
<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"
|
||||
@ -35,10 +33,16 @@ It also helps us prevent extra traffic to our limited download mirrors. Every bi
|
||||
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}" />
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1" Spacing="10">
|
||||
<Button Content="Move Downloaded Patcher"
|
||||
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}" />
|
||||
<Button Content="Clear Metadata Cache"
|
||||
Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=ClearCachedMetaData}"
|
||||
/>
|
||||
|
||||
<Button Content="Close" Classes="yellow"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
@ -3,7 +3,9 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Serilog;
|
||||
using Color = System.Drawing.Color;
|
||||
|
||||
namespace SPTInstaller.CustomControls.Dialogs;
|
||||
|
||||
@ -54,6 +56,46 @@ public partial class WhyCacheThoughDialog : UserControl
|
||||
});
|
||||
}
|
||||
|
||||
public void ClearCachedMetaData()
|
||||
{
|
||||
var cachedMetadata =
|
||||
new DirectoryInfo(DownloadCacheHelper.CachePath).GetFiles("*.json", SearchOption.TopDirectoryOnly);
|
||||
|
||||
var message = "no cached metadata to remove";
|
||||
|
||||
if (cachedMetadata.Length == 0)
|
||||
{
|
||||
AdditionalInfo = message;
|
||||
AdditionalInfoColor = "dodgerblue";
|
||||
Log.Information(message);
|
||||
return;
|
||||
}
|
||||
|
||||
var allDeleted = true;
|
||||
|
||||
foreach (var file in cachedMetadata)
|
||||
{
|
||||
try
|
||||
{
|
||||
file.Delete();
|
||||
file.Refresh();
|
||||
if (file.Exists)
|
||||
{
|
||||
allDeleted = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failed to delete cached metadata file: {file.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
message = allDeleted ? "cached metadata removed" : "some files could not be removed. Check logs";
|
||||
AdditionalInfo = message;
|
||||
AdditionalInfoColor = allDeleted ? "green" : "red";
|
||||
Log.Information(message);
|
||||
}
|
||||
|
||||
public void MoveDownloadsPatcherToCache()
|
||||
{
|
||||
switch (_movePatcherState)
|
||||
|
@ -9,8 +9,8 @@
|
||||
<PackageIcon>icon.ico</PackageIcon>
|
||||
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
|
||||
<Configurations>Debug;Release;TEST</Configurations>
|
||||
<AssemblyVersion>2.64</AssemblyVersion>
|
||||
<FileVersion>2.64</FileVersion>
|
||||
<AssemblyVersion>2.66</AssemblyVersion>
|
||||
<FileVersion>2.66</FileVersion>
|
||||
<Company>SPT-AKI</Company>
|
||||
</PropertyGroup>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user