Skip to content

Commit 74409f2

Browse files
Merge pull request #144 from MattEqualsCoder/set-pymusiclooper-path
Set pymusiclooper path
2 parents 52f7465 + 0a8799a commit 74409f2

File tree

8 files changed

+87
-7
lines changed

8 files changed

+87
-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/MSUScripter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
99
<ApplicationIcon>MSUScripterIcon.ico</ApplicationIcon>
1010
<PackageIcon>MSUScripterIcon.ico</PackageIcon>
11-
<Version>4.2.0</Version>
11+
<Version>4.2.1-beta.1</Version>
1212
<RuntimeFrameworkVersion>8.0.0</RuntimeFrameworkVersion>
1313
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
1414
<LangVersion>12</LangVersion>

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 _, _model.PyMusicLooperPath);
35+
}
2936
}

MSUScripter/Services/PyMusicLooperService.cs

Lines changed: 26 additions & 4 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);
@@ -125,15 +133,29 @@ public void ClearCache()
125133
return loopPoints;
126134
}
127135

128-
public bool TestService(out string message)
136+
public bool TestService(out string message, string? testPath = null)
129137
{
130-
if (_hasValidated)
138+
if (_hasValidated && testPath == null)
131139
{
132140
message = "";
133141
return true;
134142
}
143+
144+
if (testPath != null)
145+
{
146+
_settings.PyMusicLooperPath = testPath;
147+
_pyMusicLooperCommand = string.Empty == testPath ? "pymusiclooper" : testPath;
148+
}
149+
else if (!string.IsNullOrEmpty(_settings.PyMusicLooperPath) && File.Exists(_settings.PyMusicLooperPath))
150+
{
151+
_pyMusicLooperCommand = _settings.PyMusicLooperPath;
152+
}
153+
else
154+
{
155+
_pyMusicLooperCommand = "pymusiclooper";
156+
}
135157

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

MSUScripter/Services/PythonCommandRunnerService.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.IO;
34
using System.Runtime.InteropServices;
45
using System.Text;
56
using System.Threading;
@@ -108,12 +109,24 @@ private bool RunInternal(string command, string arguments, out string result, ou
108109

109110
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
110111
{
112+
var workingDirectory = "";
113+
if (System.IO.File.Exists(command))
114+
{
115+
workingDirectory = Directory.GetParent(command)?.FullName;
116+
if (!string.IsNullOrEmpty(workingDirectory))
117+
{
118+
var file = Path.GetFileName(command);
119+
innerCommand = $"{file} {arguments}";
120+
}
121+
}
122+
111123
procStartInfo= new ProcessStartInfo("cmd", "/c " + innerCommand)
112124
{
113125
RedirectStandardOutput = redirectOutput,
114126
RedirectStandardError = redirectOutput,
115127
UseShellExecute = false,
116-
CreateNoWindow = true
128+
CreateNoWindow = true,
129+
WorkingDirectory = workingDirectory
117130
};
118131
}
119132
else

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)