mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
use Linq and move delete log logic to the viewmodel
This commit is contained in:
parent
02c77e86db
commit
bded19130e
2 changed files with 26 additions and 22 deletions
|
|
@ -14,6 +14,7 @@ using Microsoft.Win32;
|
||||||
using ModernWpf;
|
using ModernWpf;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
@ -272,20 +273,17 @@ namespace Flow.Launcher
|
||||||
}
|
}
|
||||||
private void ClearLogFolder(object sender, RoutedEventArgs e)
|
private void ClearLogFolder(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var confirmResult = MessageBox.Show(InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"),InternationalizationManager.Instance.GetTranslation("clearlogfolder"), MessageBoxButton.YesNo);
|
var confirmResult = MessageBox.Show(
|
||||||
|
InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"),
|
||||||
|
InternationalizationManager.Instance.GetTranslation("clearlogfolder"),
|
||||||
|
MessageBoxButton.YesNo);
|
||||||
|
|
||||||
if (confirmResult == MessageBoxResult.Yes)
|
if (confirmResult == MessageBoxResult.Yes)
|
||||||
{
|
{
|
||||||
DirectoryInfo Di = new DirectoryInfo(Path.Combine(DataLocation.DataDirectory(), Constant.Logs, Constant.Version));
|
viewModel.ClearLogFolder();
|
||||||
foreach (FileInfo file in Di.EnumerateFiles())
|
|
||||||
{
|
|
||||||
file.Delete();
|
|
||||||
}
|
|
||||||
ClearLogFolderBtn.Content = viewModel.CheckLogFolder;
|
ClearLogFolderBtn.Content = viewModel.CheckLogFolder;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPluginStoreRefreshClick(object sender, RoutedEventArgs e)
|
private void OnPluginStoreRefreshClick(object sender, RoutedEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -576,25 +576,31 @@ namespace Flow.Launcher.ViewModel
|
||||||
public string Github => Constant.GitHub;
|
public string Github => Constant.GitHub;
|
||||||
public static string Version => Constant.Version;
|
public static string Version => Constant.Version;
|
||||||
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
|
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
|
||||||
|
|
||||||
public string CheckLogFolder
|
public string CheckLogFolder
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(Path.Combine(DataLocation.DataDirectory(), Constant.Logs, Constant.Version));
|
|
||||||
long size = 0;
|
|
||||||
foreach (FileInfo fi in dirInfo.GetFiles("*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
size += fi.Length;
|
|
||||||
}
|
|
||||||
return _translater.GetTranslation("clearlogfolder") + " (" + FormatBytes(size) + ")" ;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
{
|
||||||
|
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) + ")" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FormatBytes(long bytes)
|
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;
|
const int scale = 1024;
|
||||||
string[] orders = new string[] { "GB", "MB", "KB", "Bytes" };
|
string[] orders = new string[] { "GB", "MB", "KB", "Bytes" };
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue