Merge pull request #1418 from onesounds/EraseLogButton

Add 'Clear Log' Button
This commit is contained in:
Jeremy Wu 2022-10-05 21:18:07 +11:00 committed by GitHub
commit b87ee205fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 0 deletions

View file

@ -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 -->

View file

@ -2539,6 +2539,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}">

View file

@ -14,6 +14,7 @@ using Microsoft.Win32;
using ModernWpf;
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
@ -274,6 +275,20 @@ namespace Flow.Launcher
{
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)
{

View file

@ -600,6 +600,45 @@ namespace Flow.Launcher.ViewModel
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
}
}