Skip to content

Commit f3201fd

Browse files
Update to allow setting pymusiclooper path
1 parent 52f7465 commit f3201fd

File tree

7 files changed

+69
-7
lines changed

7 files changed

+69
-7
lines changed

MSUScripter/Configs/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class Settings
1717
public bool AutomaticallyRunPyMusicLooper { get; set; } = true;
1818
public bool RunMsuPcmWithKeepTemps { get; set; }
1919
public bool HasDoneFirstTimeSetup { get; set; }
20+
public string? PyMusicLooperPath { get; set; }
2021
}

MSUScripter/Services/ControlServices/PyMusicLooperPanelService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void FilterResults()
145145

146146
public void TestPyMusicLooper()
147147
{
148-
if (!pyMusicLooperService.TestService(out string message))
148+
if (!pyMusicLooperService.TestService(out string message, false))
149149
{
150150
_model.Message = message;
151151
_model.DisplayGitHubLink = true;

MSUScripter/Services/ControlServices/SettingsWindowService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
using System;
12
using Avalonia;
23
using Avalonia.Styling;
34
using AvaloniaControls.ControlServices;
45
using MSUScripter.ViewModels;
56

67
namespace MSUScripter.Services.ControlServices;
78

8-
public class SettingsWindowService(SettingsService settingsService, ConverterService converterService, MsuPcmService msuPcmService) : ControlService
9+
public class SettingsWindowService(SettingsService settingsService, ConverterService converterService, MsuPcmService msuPcmService, PyMusicLooperService pyMusicLooperService) : ControlService
910
{
1011
private SettingsWindowViewModel _model = new();
1112

1213
public SettingsWindowViewModel InitializeModel()
1314
{
1415
converterService.ConvertViewModel(settingsService.Settings, _model);
16+
_model.CanSetPyMusicLooperPath = OperatingSystem.IsWindows();
1517
return _model;
1618
}
1719

@@ -26,4 +28,9 @@ public bool ValidateMsuPcm()
2628
{
2729
return msuPcmService.ValidateMsuPcmPath(_model.MsuPcmPath!, out _);
2830
}
31+
32+
public bool ValidatePyMusicLooper()
33+
{
34+
return pyMusicLooperService.TestService(out _, true);
35+
}
2936
}

MSUScripter/Services/PyMusicLooperService.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using MSUScripter.Models;
1212
using YamlDotNet.Serialization;
1313
using YamlDotNet.Serialization.NamingConventions;
14+
using Settings = MSUScripter.Configs.Settings;
1415

1516
namespace MSUScripter.Services;
1617

@@ -26,13 +27,20 @@ public class PyMusicLooperService
2627
private bool _canReturnMultipleResults;
2728
private readonly string _cachePath;
2829
private int _currentVersion;
30+
private string _pyMusicLooperCommand = "pymusiclooper";
31+
private readonly Settings _settings;
2932

30-
public PyMusicLooperService(ILogger<PyMusicLooperService> logger, PythonCommandRunnerService python, YamlService yamlService)
33+
public PyMusicLooperService(ILogger<PyMusicLooperService> logger, PythonCommandRunnerService python, YamlService yamlService, Settings settings)
3134
{
3235
_logger = logger;
3336
_python = python;
3437
_yamlService = yamlService;
38+
_settings = settings;
3539
_cachePath = Path.Combine(Directories.CacheFolder, "pymusiclooper");
40+
if (!string.IsNullOrEmpty(settings.PyMusicLooperPath) && File.Exists(settings.PyMusicLooperPath))
41+
{
42+
_pyMusicLooperCommand = settings.PyMusicLooperPath;
43+
}
3644
if (!Directory.Exists(_cachePath))
3745
{
3846
Directory.CreateDirectory(_cachePath);
@@ -68,7 +76,7 @@ public void ClearCache()
6876

6977
if (!_hasValidated)
7078
{
71-
if (!TestService(out message))
79+
if (!TestService(out message, false))
7280
{
7381
IsRunning = false;
7482
return null;
@@ -125,15 +133,24 @@ public void ClearCache()
125133
return loopPoints;
126134
}
127135

128-
public bool TestService(out string message)
136+
public bool TestService(out string message, bool force)
129137
{
130-
if (_hasValidated)
138+
if (_hasValidated && !force)
131139
{
132140
message = "";
133141
return true;
134142
}
143+
144+
if (!string.IsNullOrEmpty(_settings.PyMusicLooperPath) && File.Exists(_settings.PyMusicLooperPath))
145+
{
146+
_pyMusicLooperCommand = _settings.PyMusicLooperPath;
147+
}
148+
else
149+
{
150+
_pyMusicLooperCommand = "pymusiclooper";
151+
}
135152

136-
if (!_python.SetBaseCommand("pymusiclooper", "--version", out var result, out _) || !result.StartsWith("pymusiclooper ", StringComparison.OrdinalIgnoreCase))
153+
if (!_python.SetBaseCommand(_pyMusicLooperCommand, "--version", out var result, out _) || !result.StartsWith("pymusiclooper ", StringComparison.OrdinalIgnoreCase))
137154
{
138155
message = "Could not run PyMusicLooper. Make sure it's installed and executable in command line.";
139156
return false;

MSUScripter/ViewModels/SettingsWindowViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using MSUScripter.Configs;
3+
using MSUScripter.Models;
34
using ReactiveUI.Fody.Helpers;
45

56
namespace MSUScripter.ViewModels;
@@ -18,7 +19,9 @@ public class SettingsWindowViewModel : ViewModelBase
1819
[Reactive] public bool RunMsuPcmWithKeepTemps { get; set; }
1920
[Reactive] public bool AutomaticallyRunPyMusicLooper { get; set; }
2021
[Reactive] public bool HideSubTracksSubChannelsWarning { get; set; }
22+
[Reactive] public string? PyMusicLooperPath { get; set; }
2123
public bool HasDoneFirstTimeSetup { get; set; }
24+
[SkipConvert] public bool CanSetPyMusicLooperPath { get; set; }
2225

2326
public override ViewModelBase DesignerExample()
2427
{

MSUScripter/Views/SettingsWindow.axaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@
5252

5353
</controls1:LabeledControl>
5454

55+
<controls1:LabeledControl Text="PyMusicLooper Path: " Hint="Path to the PyMusicLooper executable file (not needed if installed via pip/pipx)">
56+
<Grid ColumnDefinitions="*,Auto">
57+
<controls1:FileControl
58+
Grid.Column="0"
59+
FilePath="{Binding PyMusicLooperPath, Mode=TwoWay}"
60+
FileInputType="OpenFile"
61+
IsEnabled="{Binding CanSetPyMusicLooperPath}"
62+
></controls1:FileControl>
63+
<Button Grid.Column="1"
64+
Name="ValidatePyMusicLooper"
65+
Margin="5 0 0 0"
66+
Click="ValidatePyMusicLooper_OnClick"
67+
>
68+
Validate
69+
</Button>
70+
</Grid>
71+
72+
</controls1:LabeledControl>
73+
5574
<controls1:LabeledControl Text="Check for Updates:" Hint="Shows a popup when first launching when there is a new update on GitHub." DisplayHint="True">
5675
<controls1:BoolComboBox AllowNulls="False" Value="{Binding PromptOnUpdate, Mode=TwoWay}" />
5776
</controls1:LabeledControl>

MSUScripter/Views/SettingsWindow.axaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,19 @@ await MessageWindow.ShowErrorDialog(
5151
await MessageWindow.ShowInfoDialog("msupcm++ verification successful!", "Success", this);
5252
}
5353
}
54+
55+
private async void ValidatePyMusicLooper_OnClick(object? sender, RoutedEventArgs e)
56+
{
57+
var isSuccessful = _service?.ValidatePyMusicLooper();
58+
if (isSuccessful != true)
59+
{
60+
await MessageWindow.ShowErrorDialog(
61+
"There was an error verifying PyMusicLooper. Please verify that the application runs independently.",
62+
"PyMusicLooper Error", this);
63+
}
64+
else
65+
{
66+
await MessageWindow.ShowInfoDialog("PyMusicLooper verification successful!", "Success", this);
67+
}
68+
}
5469
}

0 commit comments

Comments
 (0)