Skip to content

Set pymusiclooper path #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2025
Merged
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
1 change: 1 addition & 0 deletions MSUScripter/Configs/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class Settings
public bool AutomaticallyRunPyMusicLooper { get; set; } = true;
public bool RunMsuPcmWithKeepTemps { get; set; }
public bool HasDoneFirstTimeSetup { get; set; }
public string? PyMusicLooperPath { get; set; }
}
2 changes: 1 addition & 1 deletion MSUScripter/MSUScripter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>MSUScripterIcon.ico</ApplicationIcon>
<PackageIcon>MSUScripterIcon.ico</PackageIcon>
<Version>4.2.0</Version>
<Version>4.2.1-beta.1</Version>
<RuntimeFrameworkVersion>8.0.0</RuntimeFrameworkVersion>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>12</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using Avalonia;
using Avalonia.Styling;
using AvaloniaControls.ControlServices;
using MSUScripter.ViewModels;

namespace MSUScripter.Services.ControlServices;

public class SettingsWindowService(SettingsService settingsService, ConverterService converterService, MsuPcmService msuPcmService) : ControlService
public class SettingsWindowService(SettingsService settingsService, ConverterService converterService, MsuPcmService msuPcmService, PyMusicLooperService pyMusicLooperService) : ControlService
{
private SettingsWindowViewModel _model = new();

public SettingsWindowViewModel InitializeModel()
{
converterService.ConvertViewModel(settingsService.Settings, _model);
_model.CanSetPyMusicLooperPath = OperatingSystem.IsWindows();
return _model;
}

Expand All @@ -26,4 +28,9 @@ public bool ValidateMsuPcm()
{
return msuPcmService.ValidateMsuPcmPath(_model.MsuPcmPath!, out _);
}

public bool ValidatePyMusicLooper()
{
return pyMusicLooperService.TestService(out _, _model.PyMusicLooperPath);
}
}
30 changes: 26 additions & 4 deletions MSUScripter/Services/PyMusicLooperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using MSUScripter.Models;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using Settings = MSUScripter.Configs.Settings;

namespace MSUScripter.Services;

Expand All @@ -26,13 +27,20 @@ public class PyMusicLooperService
private bool _canReturnMultipleResults;
private readonly string _cachePath;
private int _currentVersion;
private string _pyMusicLooperCommand = "pymusiclooper";
private readonly Settings _settings;

public PyMusicLooperService(ILogger<PyMusicLooperService> logger, PythonCommandRunnerService python, YamlService yamlService)
public PyMusicLooperService(ILogger<PyMusicLooperService> logger, PythonCommandRunnerService python, YamlService yamlService, Settings settings)
{
_logger = logger;
_python = python;
_yamlService = yamlService;
_settings = settings;
_cachePath = Path.Combine(Directories.CacheFolder, "pymusiclooper");
if (!string.IsNullOrEmpty(settings.PyMusicLooperPath) && File.Exists(settings.PyMusicLooperPath))
{
_pyMusicLooperCommand = settings.PyMusicLooperPath;
}
if (!Directory.Exists(_cachePath))
{
Directory.CreateDirectory(_cachePath);
Expand Down Expand Up @@ -125,15 +133,29 @@ public void ClearCache()
return loopPoints;
}

public bool TestService(out string message)
public bool TestService(out string message, string? testPath = null)
{
if (_hasValidated)
if (_hasValidated && testPath == null)
{
message = "";
return true;
}

if (testPath != null)
{
_settings.PyMusicLooperPath = testPath;
_pyMusicLooperCommand = string.Empty == testPath ? "pymusiclooper" : testPath;
}
else if (!string.IsNullOrEmpty(_settings.PyMusicLooperPath) && File.Exists(_settings.PyMusicLooperPath))
{
_pyMusicLooperCommand = _settings.PyMusicLooperPath;
}
else
{
_pyMusicLooperCommand = "pymusiclooper";
}

if (!_python.SetBaseCommand("pymusiclooper", "--version", out var result, out _) || !result.StartsWith("pymusiclooper ", StringComparison.OrdinalIgnoreCase))
if (!_python.SetBaseCommand(_pyMusicLooperCommand, "--version", out var result, out _) || !result.StartsWith("pymusiclooper ", StringComparison.OrdinalIgnoreCase))
{
message = "Could not run PyMusicLooper. Make sure it's installed and executable in command line.";
return false;
Expand Down
15 changes: 14 additions & 1 deletion MSUScripter/Services/PythonCommandRunnerService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -108,12 +109,24 @@ private bool RunInternal(string command, string arguments, out string result, ou

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var workingDirectory = "";
if (System.IO.File.Exists(command))
{
workingDirectory = Directory.GetParent(command)?.FullName;
if (!string.IsNullOrEmpty(workingDirectory))
{
var file = Path.GetFileName(command);
innerCommand = $"{file} {arguments}";
}
}

procStartInfo= new ProcessStartInfo("cmd", "/c " + innerCommand)
{
RedirectStandardOutput = redirectOutput,
RedirectStandardError = redirectOutput,
UseShellExecute = false,
CreateNoWindow = true
CreateNoWindow = true,
WorkingDirectory = workingDirectory
};
}
else
Expand Down
3 changes: 3 additions & 0 deletions MSUScripter/ViewModels/SettingsWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using MSUScripter.Configs;
using MSUScripter.Models;
using ReactiveUI.Fody.Helpers;

namespace MSUScripter.ViewModels;
Expand All @@ -18,7 +19,9 @@ public class SettingsWindowViewModel : ViewModelBase
[Reactive] public bool RunMsuPcmWithKeepTemps { get; set; }
[Reactive] public bool AutomaticallyRunPyMusicLooper { get; set; }
[Reactive] public bool HideSubTracksSubChannelsWarning { get; set; }
[Reactive] public string? PyMusicLooperPath { get; set; }
public bool HasDoneFirstTimeSetup { get; set; }
[SkipConvert] public bool CanSetPyMusicLooperPath { get; set; }

public override ViewModelBase DesignerExample()
{
Expand Down
19 changes: 19 additions & 0 deletions MSUScripter/Views/SettingsWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@

</controls1:LabeledControl>

<controls1:LabeledControl Text="PyMusicLooper Path: " Hint="Path to the PyMusicLooper executable file (not needed if installed via pip/pipx)">
<Grid ColumnDefinitions="*,Auto">
<controls1:FileControl
Grid.Column="0"
FilePath="{Binding PyMusicLooperPath, Mode=TwoWay}"
FileInputType="OpenFile"
IsEnabled="{Binding CanSetPyMusicLooperPath}"
></controls1:FileControl>
<Button Grid.Column="1"
Name="ValidatePyMusicLooper"
Margin="5 0 0 0"
Click="ValidatePyMusicLooper_OnClick"
>
Validate
</Button>
</Grid>

</controls1:LabeledControl>

<controls1:LabeledControl Text="Check for Updates:" Hint="Shows a popup when first launching when there is a new update on GitHub." DisplayHint="True">
<controls1:BoolComboBox AllowNulls="False" Value="{Binding PromptOnUpdate, Mode=TwoWay}" />
</controls1:LabeledControl>
Expand Down
15 changes: 15 additions & 0 deletions MSUScripter/Views/SettingsWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ await MessageWindow.ShowErrorDialog(
await MessageWindow.ShowInfoDialog("msupcm++ verification successful!", "Success", this);
}
}

private async void ValidatePyMusicLooper_OnClick(object? sender, RoutedEventArgs e)
{
var isSuccessful = _service?.ValidatePyMusicLooper();
if (isSuccessful != true)
{
await MessageWindow.ShowErrorDialog(
"There was an error verifying PyMusicLooper. Please verify that the application runs independently.",
"PyMusicLooper Error", this);
}
else
{
await MessageWindow.ShowInfoDialog("PyMusicLooper verification successful!", "Success", this);
}
}
}