Skip to content
Open
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
45 changes: 45 additions & 0 deletions Bloxstrap/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1407,4 +1407,19 @@ Defaulting to {1}.</value>
<data name="Menu.FastFlagEditor.AllowlistInformation" xml:space="preserve">
<value>Due to the [Fast Flag allowlist update]({0}), most custom Fast Flags will have no effect on the Roblox player.</value>
</data>
<data name="Menu.Behaviour.CleanRobloxCache.Clean" xml:space="preserve">
<value>Clean</value>
</data>
<data name="Menu.Behaviour.CleanRobloxCache.Description" xml:space="preserve">
<value>Deletes all files in Roblox's cache directories to free up disk space. Games will temporarily load slower after this!</value>
</data>
<data name="Menu.Behaviour.CleanRobloxCache.Title" xml:space="preserve">
<value>Clean Roblox cache</value>
</data>
<data name="Dialog.CacheCleaner.Cleaned" xml:space="preserve">
<value>Successfully cleaned the cache.</value>
</data>
<data name="Dialog.CacheCleaner.FailedToClean" xml:space="preserve">
<value>Failed to clean the cache!</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Bloxstrap/UI/Elements/Settings/Pages/BootstrapperPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@
</controls:OptionControl.Style>
<ui:ToggleSwitch IsChecked="{Binding ForceRobloxReinstallation, Mode=TwoWay}" />
</controls:OptionControl>

<controls:OptionControl
Header="{x:Static resources:Strings.Menu_Behaviour_CleanRobloxCache_Title}"
Description="{x:Static resources:Strings.Menu_Behaviour_CleanRobloxCache_Description}">
<ui:Button Icon="Delete48" Content="{x:Static resources:Strings.Menu_Behaviour_CleanRobloxCache_Clean}" Command="{Binding CleanRobloxCacheCommand}" Appearance="Danger" />
</controls:OptionControl>
</StackPanel>
</ui:UiPage>
81 changes: 80 additions & 1 deletion Bloxstrap/UI/ViewModels/Settings/BehaviourViewModel.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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<FileInfo> files = Enumerable.Empty<FileInfo>();
IEnumerable<string> dirs = Enumerable.Empty<string>();

// 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);
}
}
}
}