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"
|
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, AUTO"
|
<Grid RowDefinitions="AUTO,AUTO,AUTO,*,AUTO" ColumnDefinitions="*,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}" />
|
||||||
@ -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
|
- You are low on space
|
||||||
or
|
or
|
||||||
- You are not planning on installing SPT again any time soon
|
- 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.
|
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"
|
It also helps us prevent extra traffic to our limited download mirrors. Every bit helps <Span Foreground="red"
|
||||||
FontSize="25">♥️</Span>
|
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"
|
<Button Grid.Row="3" Grid.ColumnSpan="2"
|
||||||
Content="{Binding Source={x:Static helpers:DownloadCacheHelper.CachePath}}"
|
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"
|
||||||
@ -34,11 +32,17 @@ It also helps us prevent extra traffic to our limited download mirrors. Every bi
|
|||||||
<Label Grid.Row="4"
|
<Label Grid.Row="4"
|
||||||
Content="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AdditionalInfo}"
|
Content="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AdditionalInfo}"
|
||||||
Foreground="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AdditionalInfoColor}" />
|
Foreground="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AdditionalInfoColor}" />
|
||||||
|
|
||||||
|
<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 Content="Clear Metadata Cache"
|
||||||
|
Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=ClearCachedMetaData}"
|
||||||
|
/>
|
||||||
|
|
||||||
<Button Grid.Row="4" Grid.Column="1" Content="Move Downloaded Patcher" Margin="0 0 10 0"
|
<Button Content="Close" Classes="yellow"
|
||||||
Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=MoveDownloadsPatcherToCache}" />
|
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}" />
|
||||||
|
</StackPanel>
|
||||||
<Button Grid.Row="4" Grid.Column="2" Content="Close" Classes="yellow"
|
|
||||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}" />
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
@ -3,7 +3,9 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Media;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using Color = System.Drawing.Color;
|
||||||
|
|
||||||
namespace SPTInstaller.CustomControls.Dialogs;
|
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()
|
public void MoveDownloadsPatcherToCache()
|
||||||
{
|
{
|
||||||
switch (_movePatcherState)
|
switch (_movePatcherState)
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
<PackageIcon>icon.ico</PackageIcon>
|
<PackageIcon>icon.ico</PackageIcon>
|
||||||
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
|
||||||
<Configurations>Debug;Release;TEST</Configurations>
|
<Configurations>Debug;Release;TEST</Configurations>
|
||||||
<AssemblyVersion>2.64</AssemblyVersion>
|
<AssemblyVersion>2.66</AssemblyVersion>
|
||||||
<FileVersion>2.64</FileVersion>
|
<FileVersion>2.66</FileVersion>
|
||||||
<Company>SPT-AKI</Company>
|
<Company>SPT-AKI</Company>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user