diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index be4eeca72..97377e935 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -1361,6 +1361,24 @@ public static string Dialog_AlreadyRunning_Uninstaller { } } + /// + /// Looks up a localized string similar to Successfully cleaned the cache.. + /// + public static string Dialog_CacheCleaner_Cleaned { + get { + return ResourceManager.GetString("Dialog.CacheCleaner.Cleaned", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to clean the cache!. + /// + public static string Dialog_CacheCleaner_FailedToClean { + get { + return ResourceManager.GetString("Dialog.CacheCleaner.FailedToClean", resourceCulture); + } + } + /// /// Looks up a localized string similar to Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through the settings.. /// @@ -2589,6 +2607,33 @@ public static string Menu_Behaviour_BackgroundUpdates_Title { return ResourceManager.GetString("Menu.Behaviour.BackgroundUpdates.Title", resourceCulture); } } + + /// + /// Looks up a localized string similar to Clean. + /// + public static string Menu_Behaviour_CleanRobloxCache_Clean { + get { + return ResourceManager.GetString("Menu.Behaviour.CleanRobloxCache.Clean", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Deletes all files in Roblox's cache directories to free up disk space. Games will temporarily load slower after this!. + /// + public static string Menu_Behaviour_CleanRobloxCache_Description { + get { + return ResourceManager.GetString("Menu.Behaviour.CleanRobloxCache.Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Clean Roblox cache. + /// + public static string Menu_Behaviour_CleanRobloxCache_Title { + get { + return ResourceManager.GetString("Menu.Behaviour.CleanRobloxCache.Title", resourceCulture); + } + } /// /// Looks up a localized string similar to Prevent against closures of your existing game from accidentally launching another one.. diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 69e1da078..cc88eb4ee 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1407,4 +1407,19 @@ Defaulting to {1}. Due to the [Fast Flag allowlist update]({0}), most custom Fast Flags will have no effect on the Roblox player. + + Clean + + + Deletes all files in Roblox's cache directories to free up disk space. Games will temporarily load slower after this! + + + Clean Roblox cache + + + Successfully cleaned the cache. + + + Failed to clean the cache! + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/Settings/Pages/BootstrapperPage.xaml b/Bloxstrap/UI/Elements/Settings/Pages/BootstrapperPage.xaml index cb1026a13..b00696f18 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/BootstrapperPage.xaml +++ b/Bloxstrap/UI/Elements/Settings/Pages/BootstrapperPage.xaml @@ -43,5 +43,11 @@ + + + + diff --git a/Bloxstrap/UI/ViewModels/Settings/BehaviourViewModel.cs b/Bloxstrap/UI/ViewModels/Settings/BehaviourViewModel.cs index 9446e6a24..5ab366952 100644 --- a/Bloxstrap/UI/ViewModels/Settings/BehaviourViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Settings/BehaviourViewModel.cs @@ -1,4 +1,9 @@ -namespace Bloxstrap.UI.ViewModels.Settings +using System.Linq; +using System.Windows; +using System.Windows.Input; +using CommunityToolkit.Mvvm.Input; + +namespace Bloxstrap.UI.ViewModels.Settings { public class BehaviourViewModel : NotifyPropertyChangedViewModel { @@ -21,5 +26,79 @@ public bool ForceRobloxReinstallation get => App.State.Prop.ForceReinstall || IsRobloxInstallationMissing; set => App.State.Prop.ForceReinstall = value; } + + public ICommand CleanRobloxCacheCommand => new RelayCommand(CleanRobloxCache); + + private void CleanRobloxCache() + { + const string LOG_IDENT = "BehaviourViewModel::CleanRobloxCache"; + + IEnumerable files = Enumerable.Empty(); + IEnumerable dirs = Enumerable.Empty(); + + // all the cache folders i know of + string robloxTempFolder = Path.Combine(Path.GetTempPath(), "Roblox"); + string robloxStorageFolder = Path.Combine(Paths.LocalAppData, "Roblox\\rbx-storage"); + string dbFile = Path.Combine(Paths.LocalAppData, "Roblox\\rbx-storage.db"); // the other "rbx-storage" files are irrelevant + + if (Directory.Exists(robloxTempFolder)) + { + files = files.Concat(new DirectoryInfo(robloxTempFolder).GetFiles("*", SearchOption.AllDirectories)); + dirs = dirs.Concat(Directory.GetDirectories(robloxTempFolder)); + } + + if (Directory.Exists(robloxStorageFolder)) + { + files = files.Concat(new DirectoryInfo(robloxStorageFolder).GetFiles("*", SearchOption.AllDirectories)); + dirs = dirs.Concat(Directory.GetDirectories(robloxStorageFolder)); + } + + if (File.Exists(dbFile)) + files = files.Concat(new[] { new FileInfo(dbFile) }); + + if (!files.Any() && !dirs.Any()) + { + Frontend.ShowMessageBox(Strings.Dialog_CacheCleaner_Cleaned, MessageBoxImage.Information); + return; + } + + try + { + foreach (FileInfo file in files) + { + try + { + file.Delete(); + } + catch (Exception ex) + { + App.Logger.WriteLine(LOG_IDENT, $"Failed to delete file '{file.Name}'!"); + App.Logger.WriteException(LOG_IDENT, ex); + } + } + + // why not delete the folders aswell + foreach (string dir in dirs) + { + try + { + Directory.Delete(dir, true); + } + catch (Exception ex) + { + App.Logger.WriteLine(LOG_IDENT, $"Failed to delete directory '{Path.GetFileName(dir)}'!"); + App.Logger.WriteException(LOG_IDENT, ex); + } + } + + Frontend.ShowMessageBox(Strings.Dialog_CacheCleaner_Cleaned, MessageBoxImage.Information); + } + catch (Exception ex) + { + App.Logger.WriteLine(LOG_IDENT, "Failed to clean the cache!"); + App.Logger.WriteException(LOG_IDENT, ex); + Frontend.ShowMessageBox(Strings.Dialog_CacheCleaner_FailedToClean, MessageBoxImage.Error); + } + } } }