1111using MSUScripter . Models ;
1212using YamlDotNet . Serialization ;
1313using YamlDotNet . Serialization . NamingConventions ;
14+ using Settings = MSUScripter . Configs . Settings ;
1415
1516namespace 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 ;
0 commit comments