Skip to content

Commit b87ee20

Browse files
authored
Merge pull request #1418 from onesounds/EraseLogButton
Add 'Clear Log' Button
2 parents b8a89ef + bded191 commit b87ee20

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@
165165
<system:String x:Key="devtool">DevTools</system:String>
166166
<system:String x:Key="settingfolder">Setting Folder</system:String>
167167
<system:String x:Key="logfolder">Log Folder</system:String>
168+
<system:String x:Key="clearlogfolder">Clear Logs</system:String>
169+
<system:String x:Key="clearlogfolderMessage">Are you sure you want to delete all logs?</system:String>
168170
<system:String x:Key="welcomewindow">Wizard</system:String>
169171

170172
<!-- FileManager Setting Dialog -->

Flow.Launcher/SettingWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,11 @@
25392539
Margin="0,0,12,0"
25402540
Click="OpenSettingFolder"
25412541
Content="{DynamicResource settingfolder}" />
2542+
<Button
2543+
Name="ClearLogFolderBtn"
2544+
Margin="0,0,12,0"
2545+
Click="ClearLogFolder"
2546+
Content="{Binding CheckLogFolder, UpdateSourceTrigger=PropertyChanged}" />
25422547
<Button Click="OpenLogFolder" Content="{DynamicResource logfolder}" />
25432548
</StackPanel>
25442549
<TextBlock Style="{StaticResource Glyph}">

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using ModernWpf;
1515
using System;
1616
using System.IO;
17+
using System.Linq;
1718
using System.Windows;
1819
using System.Windows.Controls;
1920
using System.Windows.Forms;
@@ -274,6 +275,20 @@ private void OpenLogFolder(object sender, RoutedEventArgs e)
274275
{
275276
PluginManager.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Logs, Constant.Version));
276277
}
278+
private void ClearLogFolder(object sender, RoutedEventArgs e)
279+
{
280+
var confirmResult = MessageBox.Show(
281+
InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"),
282+
InternationalizationManager.Instance.GetTranslation("clearlogfolder"),
283+
MessageBoxButton.YesNo);
284+
285+
if (confirmResult == MessageBoxResult.Yes)
286+
{
287+
viewModel.ClearLogFolder();
288+
289+
ClearLogFolderBtn.Content = viewModel.CheckLogFolder;
290+
}
291+
}
277292

278293
private void OnPluginStoreRefreshClick(object sender, RoutedEventArgs e)
279294
{

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,45 @@ public FamilyTypeface SelectedResultFontFaces
600600
public string Github => Constant.GitHub;
601601
public static string Version => Constant.Version;
602602
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
603+
604+
public string CheckLogFolder
605+
{
606+
get
607+
{
608+
var dirInfo = new DirectoryInfo(Path.Combine(DataLocation.DataDirectory(), Constant.Logs, Constant.Version));
609+
long size = dirInfo.EnumerateFiles("*", SearchOption.AllDirectories).Sum(file => file.Length);
610+
611+
return _translater.GetTranslation("clearlogfolder") + " (" + FormatBytes(size) + ")" ;
612+
}
613+
}
614+
615+
internal void ClearLogFolder()
616+
{
617+
var directory = new DirectoryInfo(
618+
Path.Combine(
619+
DataLocation.DataDirectory(),
620+
Constant.Logs,
621+
Constant.Version));
622+
623+
directory.EnumerateFiles()
624+
.ToList()
625+
.ForEach(x => x.Delete());
626+
}
627+
internal string FormatBytes(long bytes)
628+
{
629+
const int scale = 1024;
630+
string[] orders = new string[] { "GB", "MB", "KB", "Bytes" };
631+
long max = (long)Math.Pow(scale, orders.Length - 1);
632+
633+
foreach (string order in orders)
634+
{
635+
if (bytes > max)
636+
return string.Format("{0:##.##} {1}", decimal.Divide(bytes, max), order);
637+
638+
max /= scale;
639+
}
640+
return "0 Bytes";
641+
}
603642
#endregion
604643
}
605644
}

0 commit comments

Comments
 (0)