Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
<system:String x:Key="devtool">DevTools</system:String>
<system:String x:Key="settingfolder">Setting Folder</system:String>
<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="welcomewindow">Wizard</system:String>

<!-- FileManager Setting Dialog -->
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,11 @@
Margin="0,0,12,0"
Click="OpenSettingFolder"
Content="{DynamicResource settingfolder}" />
<Button
Name="ClearLogFolderBtn"
Margin="0,0,12,0"
Click="ClearLogFolder"
Content="{Binding CheckLogFolder, UpdateSourceTrigger=PropertyChanged}" />
<Button Click="OpenLogFolder" Content="{DynamicResource logfolder}" />
</StackPanel>
<TextBlock Style="{StaticResource Glyph}">
Expand Down
15 changes: 15 additions & 0 deletions Flow.Launcher/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
39 changes: 39 additions & 0 deletions Flow.Launcher/ViewModel/SettingWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}