mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add clean cache option
This commit is contained in:
parent
8e8b5dbbba
commit
482fdc939f
3 changed files with 54 additions and 1 deletions
|
|
@ -325,6 +325,8 @@
|
|||
<system:String x:Key="logfolder">Log Folder</system:String>
|
||||
<system:String x:Key="clearlogfolder">Clear Logs</system:String>
|
||||
<system:String x:Key="clearlogfolderMessage">Are you sure you want to delete all logs?</system:String>
|
||||
<system:String x:Key="clearcachefolder">Clear Caches</system:String>
|
||||
<system:String x:Key="clearcachefolderMessage">Are you sure you want to delete all caches?</system:String>
|
||||
<system:String x:Key="welcomewindow">Wizard</system:String>
|
||||
<system:String x:Key="userdatapath">User Data Location</system:String>
|
||||
<system:String x:Key="userdatapathToolTip">User settings and installed plugins are saved in the user data folder. This location may vary depending on whether it's in portable mode or not.</system:String>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,15 @@ public partial class SettingsPaneAboutViewModel : BaseModel
|
|||
}
|
||||
}
|
||||
|
||||
public string CacheFolderSize
|
||||
{
|
||||
get
|
||||
{
|
||||
var size = GetCacheFiles().Sum(file => file.Length);
|
||||
return $"{App.API.GetTranslation("clearcachefolder")} ({BytesToReadableString(size)})";
|
||||
}
|
||||
}
|
||||
|
||||
public string Website => Constant.Website;
|
||||
public string SponsorPage => Constant.SponsorPage;
|
||||
public string ReleaseNotes => _updater.GitHubRepository + "/releases/latest";
|
||||
|
|
@ -98,6 +107,21 @@ public partial class SettingsPaneAboutViewModel : BaseModel
|
|||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AskClearCacheFolderConfirmation()
|
||||
{
|
||||
var confirmResult = App.API.ShowMsgBox(
|
||||
App.API.GetTranslation("clearcachefolderMessage"),
|
||||
App.API.GetTranslation("clearcachefolder"),
|
||||
MessageBoxButton.YesNo
|
||||
);
|
||||
|
||||
if (confirmResult == MessageBoxResult.Yes)
|
||||
{
|
||||
ClearCacheFolder();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenSettingsFolder()
|
||||
{
|
||||
|
|
@ -112,7 +136,6 @@ public partial class SettingsPaneAboutViewModel : BaseModel
|
|||
App.API.OpenDirectory(parentFolderPath);
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenLogsFolder()
|
||||
{
|
||||
|
|
@ -147,6 +170,30 @@ public partial class SettingsPaneAboutViewModel : BaseModel
|
|||
return GetLogDir(version).EnumerateFiles("*", SearchOption.AllDirectories).ToList();
|
||||
}
|
||||
|
||||
private void ClearCacheFolder()
|
||||
{
|
||||
var cacheDirectory = GetCacheDir();
|
||||
var cacheFiles = GetCacheFiles();
|
||||
|
||||
cacheFiles.ForEach(f => f.Delete());
|
||||
|
||||
cacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
|
||||
.ToList()
|
||||
.ForEach(dir => dir.Delete(true));
|
||||
|
||||
OnPropertyChanged(nameof(CacheFolderSize));
|
||||
}
|
||||
|
||||
private static DirectoryInfo GetCacheDir()
|
||||
{
|
||||
return new DirectoryInfo(DataLocation.CacheDirectory);
|
||||
}
|
||||
|
||||
private static List<FileInfo> GetCacheFiles()
|
||||
{
|
||||
return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList();
|
||||
}
|
||||
|
||||
private static string BytesToReadableString(long bytes)
|
||||
{
|
||||
const int scale = 1024;
|
||||
|
|
|
|||
|
|
@ -90,6 +90,10 @@
|
|||
Margin="0 12 0 0"
|
||||
Icon="">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button
|
||||
Margin="0 0 12 0"
|
||||
Command="{Binding AskClearCacheFolderConfirmationCommand}"
|
||||
Content="{Binding CacheFolderSize, Mode=OneWay}" />
|
||||
<Button
|
||||
Margin="0 0 12 0"
|
||||
Command="{Binding AskClearLogFolderConfirmationCommand}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue