Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
<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="clearcachefolder">Clear Caches</system:String>
<system:String x:Key="clearcachefolderMessage">Are you sure you want to delete all caches?</system:String>
<system:String x:Key="clearfolderfailMessage">Failed to clear folders and files</system:String>
<system:String x:Key="welcomewindow">Wizard</system:String>
<system:String x:Key="userdatapath">User Data Location</system:String>
<system:String x:Key="userdatapathToolTip">User settings and installed plugins are saved in the user data folder. This location may vary depending on whether it's in portable mode or not.</system:String>
Expand Down
81 changes: 71 additions & 10 deletions Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
Expand All @@ -24,7 +23,16 @@ public string LogFolderSize
get
{
var size = GetLogFiles().Sum(file => file.Length);
return $"{InternationalizationManager.Instance.GetTranslation("clearlogfolder")} ({BytesToReadableString(size)})";
return $"{App.API.GetTranslation("clearlogfolder")} ({BytesToReadableString(size)})";
}
}

public string CacheFolderSize
{
get
{
var size = GetCacheFiles().Sum(file => file.Length);
return $"{App.API.GetTranslation("clearcachefolder")} ({BytesToReadableString(size)})";
}
}

Expand All @@ -42,7 +50,7 @@ public string LogFolderSize
};

public string ActivatedTimes => string.Format(
InternationalizationManager.Instance.GetTranslation("about_activate_times"),
App.API.GetTranslation("about_activate_times"),
_settings.ActivateTimes
);

Expand Down Expand Up @@ -88,14 +96,45 @@ private void OpenWelcomeWindow()
private void AskClearLogFolderConfirmation()
{
var confirmResult = App.API.ShowMsgBox(
InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"),
InternationalizationManager.Instance.GetTranslation("clearlogfolder"),
App.API.GetTranslation("clearlogfolderMessage"),
App.API.GetTranslation("clearlogfolder"),
MessageBoxButton.YesNo
);

if (confirmResult == MessageBoxResult.Yes)
{
ClearLogFolder();
try
{
ClearLogFolder();
}
catch (Exception e)
{
App.API.LogException(nameof(SettingsPaneAboutViewModel), "Failed to clear log folder", e);
App.API.ShowMsgBox(App.API.GetTranslation("clearfolderfailMessage"));
}
}
}

[RelayCommand]
private void AskClearCacheFolderConfirmation()
{
var confirmResult = App.API.ShowMsgBox(
App.API.GetTranslation("clearcachefolderMessage"),
App.API.GetTranslation("clearcachefolder"),
MessageBoxButton.YesNo
);

if (confirmResult == MessageBoxResult.Yes)
{
try
{
ClearCacheFolder();
}
catch (Exception e)
{
App.API.LogException(nameof(SettingsPaneAboutViewModel), "Failed to clear cache folder", e);
App.API.ShowMsgBox(App.API.GetTranslation("clearfolderfailMessage"));
}
}
}

Expand All @@ -113,15 +152,14 @@ private void OpenParentOfSettingsFolder(object parameter)
App.API.OpenDirectory(parentFolderPath);
}


[RelayCommand]
private void OpenLogsFolder()
{
App.API.OpenDirectory(GetLogDir(Constant.Version).FullName);
}

[RelayCommand]
private Task UpdateApp() => _updater.UpdateAppAsync(false);
private Task UpdateAppAsync() => _updater.UpdateAppAsync(false);

private void ClearLogFolder()
{
Expand All @@ -148,6 +186,30 @@ private static List<FileInfo> GetLogFiles(string version = "")
return GetLogDir(version).EnumerateFiles("*", SearchOption.AllDirectories).ToList();
}

private void ClearCacheFolder()
{
var cacheDirectory = GetCacheDir();
var cacheFiles = GetCacheFiles();

cacheFiles.ForEach(f => f.Delete());

cacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
.ToList()
.ForEach(dir => dir.Delete(true));

OnPropertyChanged(nameof(CacheFolderSize));
}

private static DirectoryInfo GetCacheDir()
{
return new DirectoryInfo(DataLocation.CacheDirectory);
}

private static List<FileInfo> GetCacheFiles()
{
return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList();
}

private static string BytesToReadableString(long bytes)
{
const int scale = 1024;
Expand All @@ -156,8 +218,7 @@ private static string BytesToReadableString(long bytes)

foreach (string order in orders)
{
if (bytes > max)
return $"{decimal.Divide(bytes, max):##.##} {order}";
if (bytes > max) return $"{decimal.Divide(bytes, max):##.##} {order}";

max /= scale;
}
Expand Down
4 changes: 4 additions & 0 deletions Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
Margin="0 12 0 0"
Icon="&#xf12b;">
<StackPanel Orientation="Horizontal">
<Button
Margin="0 0 12 0"
Command="{Binding AskClearCacheFolderConfirmationCommand}"
Content="{Binding CacheFolderSize, Mode=OneWay}" />
<Button
Margin="0 0 12 0"
Command="{Binding AskClearLogFolderConfirmationCommand}"
Expand Down
Loading