diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml
index f55b57236f8..1ca2f0f7eaf 100644
--- a/Flow.Launcher/Languages/en.xaml
+++ b/Flow.Launcher/Languages/en.xaml
@@ -165,6 +165,8 @@
DevTools
Setting Folder
Log Folder
+ Clear Logs
+ Are you sure you want to delete all logs?
Wizard
diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml
index 14520cfe0a1..e4eea4ef9e5 100644
--- a/Flow.Launcher/SettingWindow.xaml
+++ b/Flow.Launcher/SettingWindow.xaml
@@ -2538,6 +2538,11 @@
Margin="0,0,12,0"
Click="OpenSettingFolder"
Content="{DynamicResource settingfolder}" />
+
diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs
index 069457d018c..dc8c3a300a4 100644
--- a/Flow.Launcher/SettingWindow.xaml.cs
+++ b/Flow.Launcher/SettingWindow.xaml.cs
@@ -14,6 +14,7 @@
using ModernWpf;
using System;
using System.IO;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
@@ -270,6 +271,20 @@ private void OpenLogFolder(object sender, RoutedEventArgs e)
{
PluginManager.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Logs, Constant.Version));
}
+ private void ClearLogFolder(object sender, RoutedEventArgs e)
+ {
+ var confirmResult = MessageBox.Show(
+ InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"),
+ InternationalizationManager.Instance.GetTranslation("clearlogfolder"),
+ MessageBoxButton.YesNo);
+
+ if (confirmResult == MessageBoxResult.Yes)
+ {
+ viewModel.ClearLogFolder();
+
+ ClearLogFolderBtn.Content = viewModel.CheckLogFolder;
+ }
+ }
private void OnPluginStoreRefreshClick(object sender, RoutedEventArgs e)
{
diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs
index 64cb9e36cbe..039ba8baf0b 100644
--- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs
+++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs
@@ -576,6 +576,45 @@ public FamilyTypeface SelectedResultFontFaces
public string Github => Constant.GitHub;
public static string Version => Constant.Version;
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
+
+ public string CheckLogFolder
+ {
+ get
+ {
+ var dirInfo = new DirectoryInfo(Path.Combine(DataLocation.DataDirectory(), Constant.Logs, Constant.Version));
+ long size = dirInfo.EnumerateFiles("*", SearchOption.AllDirectories).Sum(file => file.Length);
+
+ return _translater.GetTranslation("clearlogfolder") + " (" + FormatBytes(size) + ")" ;
+ }
+ }
+
+ internal void ClearLogFolder()
+ {
+ var directory = new DirectoryInfo(
+ Path.Combine(
+ DataLocation.DataDirectory(),
+ Constant.Logs,
+ Constant.Version));
+
+ directory.EnumerateFiles()
+ .ToList()
+ .ForEach(x => x.Delete());
+ }
+ internal string FormatBytes(long bytes)
+ {
+ const int scale = 1024;
+ string[] orders = new string[] { "GB", "MB", "KB", "Bytes" };
+ long max = (long)Math.Pow(scale, orders.Length - 1);
+
+ foreach (string order in orders)
+ {
+ if (bytes > max)
+ return string.Format("{0:##.##} {1}", decimal.Divide(bytes, max), order);
+
+ max /= scale;
+ }
+ return "0 Bytes";
+ }
#endregion
}
}