Skip to content

Commit

Permalink
Merge pull request #818 from lottev1991/ClearCacheOnQuit
Browse files Browse the repository at this point in the history
Add option to automatically clear cache on quit
  • Loading branch information
stakira authored Sep 13, 2023
2 parents c1909b4 + 7a0f8fa commit 2a010de
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions OpenUtau.Core/Util/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class SerializablePreferences {
public bool ShowTips = true;
public int Theme;
public bool UseTrackColor = false;
public bool ClearCacheOnQuit = false;
public bool PreRender = true;
public int NumRenderThreads = 2;
public string OnnxRunner = string.Empty;
Expand Down
2 changes: 2 additions & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ Warning: this option removes custom presets.</system:String>
<system:String x:Key="prefs.appearance.theme.light">Light</system:String>
<system:String x:Key="prefs.appearance.trackcolor">Use track color in UI</system:String>
<system:String x:Key="prefs.caption">Preferences</system:String>
<system:String x:Key="prefs.cache">Cache</system:String>
<system:String x:Key="prefs.cache.clearonquit">Clear cache on quit</system:String>
<system:String x:Key="prefs.note.restart">Note: please restart OpenUtau after changing this item.</system:String>
<system:String x:Key="prefs.off">Off</system:String>
<system:String x:Key="prefs.on">On</system:String>
Expand Down
8 changes: 8 additions & 0 deletions OpenUtau/ViewModels/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public AudioOutputDevice? AudioOutputDevice {
public string AdditionalSingersPath => PathManager.Inst.AdditionalSingersPath;
[Reactive] public bool InstallToAdditionalSingersPath { get; set; }
[Reactive] public bool PreRender { get; set; }
public string CachePath => PathManager.Inst.CachePath;
[Reactive] public int NumRenderThreads { get; set; }
public List<string> OnnxRunnerOptions { get; set; }
[Reactive] public string OnnxRunner { get; set; }
Expand All @@ -41,6 +42,7 @@ public AudioOutputDevice? AudioOutputDevice {
[Reactive] public bool ShowGhostNotes { get; set; }
[Reactive] public int OtoEditor { get; set; }
public string VLabelerPath => Preferences.Default.VLabelerPath;
[Reactive] public bool ClearCacheOnQuit { get; set; }
public int LogicalCoreCount {
get => Environment.ProcessorCount;
}
Expand Down Expand Up @@ -133,6 +135,7 @@ public PreferencesViewModel() {
RememberMid = Preferences.Default.RememberMid;
RememberUst = Preferences.Default.RememberUst;
RememberVsqx = Preferences.Default.RememberVsqx;
ClearCacheOnQuit = Preferences.Default.ClearCacheOnQuit;

this.WhenAnyValue(vm => vm.AudioOutputDevice)
.WhereNotNull()
Expand Down Expand Up @@ -260,6 +263,11 @@ public PreferencesViewModel() {
Preferences.Default.RememberVsqx = index;
Preferences.Save();
});
this.WhenAnyValue(vm => vm.ClearCacheOnQuit)
.Subscribe(index => {
Preferences.Default.ClearCacheOnQuit = index;
Preferences.Save();
});
}

public void TestAudioOutputDevice() {
Expand Down
22 changes: 14 additions & 8 deletions OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using OpenUtau.Core;
using OpenUtau.Core.Format;
using OpenUtau.Core.Ustx;
using OpenUtau.Core.Util;
using ReactiveUI;
using Serilog;
using Point = Avalonia.Point;
Expand Down Expand Up @@ -564,7 +565,7 @@ private void LayoutSplit(double? x, double? y) {
Width = x != null ? wa.Size.Width * x.Value : wa.Size.Width;
Height = (y != null ? wa.Size.Height * y.Value : wa.Size.Height) - titleBarHeight;
if (pianoRollWindow != null) {
pianoRollWindow.Position = new PixelPoint(x != null ? (int)Width : 0, y != null ? (int)(Height + (OS.IsMacOS() ? 25 : titleBarHeight)) : 0);
pianoRollWindow.Position = new PixelPoint(x != null ? (int) Width : 0, y != null ? (int) (Height + (OS.IsMacOS() ? 25 : titleBarHeight)) : 0);
pianoRollWindow.Width = x != null ? wa.Size.Width - Width : wa.Size.Width;
pianoRollWindow.Height = (y != null ? wa.Size.Height - (Height + titleBarHeight) : wa.Size.Height) - titleBarHeight;
}
Expand All @@ -575,7 +576,7 @@ void OnKeyDown(object sender, KeyEventArgs args) {
return;
}
var tracksVm = viewModel.TracksViewModel;
if (args.KeyModifiers == KeyModifiers.None) {
if (args.KeyModifiers == KeyModifiers.None){
args.Handled = true;
switch (args.Key) {
case Key.Delete: viewModel.TracksViewModel.DeleteSelectedParts(); break;
Expand Down Expand Up @@ -696,10 +697,10 @@ async void OnDrop(object? sender, DragEventArgs args) {
} else if (ext == ".dll") {
var result = await MessageBox.Show(
this,
ThemeManager.GetString("dialogs.installdll.message")+file,
ThemeManager.GetString("dialogs.installdll.message") + file,
ThemeManager.GetString("dialogs.installdll.caption"),
MessageBox.MessageBoxButtons.OkCancel);
if(result == MessageBox.MessageBoxResult.Ok){
if (result == MessageBox.MessageBoxResult.Ok) {
Core.Api.PhonemizerInstaller.Install(file);
}
} else if (ext == ".exe") {
Expand Down Expand Up @@ -756,7 +757,7 @@ public void VScrollPointerWheelChanged(object sender, PointerWheelEventArgs args

public void TimelinePointerWheelChanged(object sender, PointerWheelEventArgs args) {
var control = (Control)sender;
var position = args.GetCurrentPoint((Visual)sender).Position;
var position = args.GetCurrentPoint((Visual) sender).Position;
var size = control.Bounds.Size;
position = position.WithX(position.X / size.Width).WithY(position.Y / size.Height);
viewModel.TracksViewModel.OnXZoomed(position, 0.1 * args.Delta.Y);
Expand Down Expand Up @@ -857,7 +858,7 @@ public void PartsCanvasPointerPressed(object sender, PointerPressedEventArgs arg
}

public void PartsCanvasPointerMoved(object sender, PointerEventArgs args) {
var control = (Control)sender;
var control = (Control) sender;
var point = args.GetCurrentPoint(control);
if (partEditState != null) {
partEditState.Update(point.Pointer, point.Position);
Expand Down Expand Up @@ -886,7 +887,7 @@ public void PartsCanvasPointerReleased(object sender, PointerReleasedEventArgs a
if (partEditState.MouseButton != args.InitialPressMouseButton) {
return;
}
var control = (Control)sender;
var control = (Control) sender;
var point = args.GetCurrentPoint(control);
partEditState.Update(point.Pointer, point.Position);
partEditState.End(point.Pointer, point.Position);
Expand Down Expand Up @@ -994,6 +995,11 @@ async void ReplaceAudio(UPart part) {

public async void WindowClosing(object? sender, WindowClosingEventArgs e) {
if (forceClose || DocManager.Inst.ChangesSaved) {
if (Preferences.Default.ClearCacheOnQuit) {
Log.Information("Clearing cache...");
PathManager.Inst.ClearCache();
Log.Information("Cache cleared.");
}
return;
}
e.Cancel = true;
Expand Down Expand Up @@ -1028,4 +1034,4 @@ public void OnNext(UCommand cmd, bool isUndo) {
}
}
}
}
}
6 changes: 6 additions & 0 deletions OpenUtau/Views/PreferencesDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
</Grid>
</StackPanel>
</HeaderedContentControl>
<HeaderedContentControl Classes="groupbox" Header="{DynamicResource prefs.cache}">
<Grid>
<TextBlock Text="{DynamicResource prefs.cache.clearonquit}" HorizontalAlignment="Left"/>
<ToggleSwitch IsChecked="{Binding ClearCacheOnQuit}"/>
</Grid>
</HeaderedContentControl>
<HeaderedContentControl Classes="groupbox" Header="{DynamicResource prefs.rendering}">
<StackPanel>
<Grid>
Expand Down

0 comments on commit 2a010de

Please sign in to comment.