Skip to content

Commit 482fdc9

Browse files
committed
Add clean cache option
1 parent 8e8b5db commit 482fdc9

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@
325325
<system:String x:Key="logfolder">Log Folder</system:String>
326326
<system:String x:Key="clearlogfolder">Clear Logs</system:String>
327327
<system:String x:Key="clearlogfolderMessage">Are you sure you want to delete all logs?</system:String>
328+
<system:String x:Key="clearcachefolder">Clear Caches</system:String>
329+
<system:String x:Key="clearcachefolderMessage">Are you sure you want to delete all caches?</system:String>
328330
<system:String x:Key="welcomewindow">Wizard</system:String>
329331
<system:String x:Key="userdatapath">User Data Location</system:String>
330332
<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>

Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public string LogFolderSize
2727
}
2828
}
2929

30+
public string CacheFolderSize
31+
{
32+
get
33+
{
34+
var size = GetCacheFiles().Sum(file => file.Length);
35+
return $"{App.API.GetTranslation("clearcachefolder")} ({BytesToReadableString(size)})";
36+
}
37+
}
38+
3039
public string Website => Constant.Website;
3140
public string SponsorPage => Constant.SponsorPage;
3241
public string ReleaseNotes => _updater.GitHubRepository + "/releases/latest";
@@ -98,6 +107,21 @@ private void AskClearLogFolderConfirmation()
98107
}
99108
}
100109

110+
[RelayCommand]
111+
private void AskClearCacheFolderConfirmation()
112+
{
113+
var confirmResult = App.API.ShowMsgBox(
114+
App.API.GetTranslation("clearcachefolderMessage"),
115+
App.API.GetTranslation("clearcachefolder"),
116+
MessageBoxButton.YesNo
117+
);
118+
119+
if (confirmResult == MessageBoxResult.Yes)
120+
{
121+
ClearCacheFolder();
122+
}
123+
}
124+
101125
[RelayCommand]
102126
private void OpenSettingsFolder()
103127
{
@@ -112,7 +136,6 @@ private void OpenParentOfSettingsFolder(object parameter)
112136
App.API.OpenDirectory(parentFolderPath);
113137
}
114138

115-
116139
[RelayCommand]
117140
private void OpenLogsFolder()
118141
{
@@ -147,6 +170,30 @@ private static List<FileInfo> GetLogFiles(string version = "")
147170
return GetLogDir(version).EnumerateFiles("*", SearchOption.AllDirectories).ToList();
148171
}
149172

173+
private void ClearCacheFolder()
174+
{
175+
var cacheDirectory = GetCacheDir();
176+
var cacheFiles = GetCacheFiles();
177+
178+
cacheFiles.ForEach(f => f.Delete());
179+
180+
cacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
181+
.ToList()
182+
.ForEach(dir => dir.Delete(true));
183+
184+
OnPropertyChanged(nameof(CacheFolderSize));
185+
}
186+
187+
private static DirectoryInfo GetCacheDir()
188+
{
189+
return new DirectoryInfo(DataLocation.CacheDirectory);
190+
}
191+
192+
private static List<FileInfo> GetCacheFiles()
193+
{
194+
return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList();
195+
}
196+
150197
private static string BytesToReadableString(long bytes)
151198
{
152199
const int scale = 1024;

Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
Margin="0 12 0 0"
9191
Icon="&#xf12b;">
9292
<StackPanel Orientation="Horizontal">
93+
<Button
94+
Margin="0 0 12 0"
95+
Command="{Binding AskClearCacheFolderConfirmationCommand}"
96+
Content="{Binding CacheFolderSize, Mode=OneWay}" />
9397
<Button
9498
Margin="0 0 12 0"
9599
Command="{Binding AskClearLogFolderConfirmationCommand}"

0 commit comments

Comments
 (0)