@@ -53,25 +53,27 @@ public class SpecialKHelperSettings : ObservableObject
5353 public class SpecialKHelperSettingsViewModel : ObservableObject , ISettings
5454 {
5555 private readonly SpecialKHelper _plugin ;
56+ private readonly ILogger _logger ;
5657 private readonly SpecialKServiceManager _specialKServiceManager ;
5758
58- private SpecialKHelperSettings editingClone { get ; set ; }
59+ private SpecialKHelperSettings _editingClone ;
5960
60- private SpecialKHelperSettings settings ;
61+ private SpecialKHelperSettings _settings ;
6162 public SpecialKHelperSettings Settings
6263 {
63- get => settings ;
64+ get => _settings ;
6465 set
6566 {
66- settings = value ;
67+ _settings = value ;
6768 OnPropertyChanged ( ) ;
6869 }
6970 }
7071
71- public SpecialKHelperSettingsViewModel ( SpecialKHelper plugin , SpecialKServiceManager specialKServiceManager )
72+ public SpecialKHelperSettingsViewModel ( SpecialKHelper plugin , SpecialKServiceManager specialKServiceManager , ILogger logger )
7273 {
7374 // Injecting your plugin instance is required for Save/Load method because Playnite saves data to a location based on what plugin requested the operation.
7475 _plugin = plugin ;
76+ _logger = logger ;
7577 _specialKServiceManager = specialKServiceManager ;
7678 // Load saved settings.
7779 var savedSettings = plugin . LoadPluginSettings < SpecialKHelperSettings > ( ) ;
@@ -85,27 +87,48 @@ public SpecialKHelperSettingsViewModel(SpecialKHelper plugin, SpecialKServiceMan
8587 {
8688 Settings = new SpecialKHelperSettings ( ) ;
8789 }
90+ UpdateSpecialKServiceSettings ( ) ;
8891 }
8992
9093 public void BeginEdit ( )
9194 {
9295 // Code executed when settings view is opened and user starts editing values.
93- editingClone = Serialization . GetClone ( Settings ) ;
96+ _editingClone = Serialization . GetClone ( Settings ) ;
9497 }
9598
9699 public void CancelEdit ( )
97100 {
98101 // Code executed when user decides to cancel any changes made since BeginEdit was called.
99102 // This method should revert any changes made to Option1 and Option2.
100- Settings = editingClone ;
103+ Settings = _editingClone ;
101104 }
102105
103106 public void EndEdit ( )
104107 {
105108 // Code executed when user decides to confirm changes made since BeginEdit was called.
106109 // This method should save settings made to Option1 and Option2.
107110 _plugin . SavePluginSettings ( Settings ) ;
108- _specialKServiceManager . SetSpecialKInstallDirectory ( Path . GetDirectoryName ( settings . CustomSpecialKPath ) ) ;
111+ UpdateSpecialKServiceSettings ( ) ;
112+ }
113+
114+ private void UpdateSpecialKServiceSettings ( )
115+ {
116+ try
117+ {
118+ if ( ! _settings . CustomSpecialKPath . IsNullOrEmpty ( ) && FileSystem . FileExists ( _settings . CustomSpecialKPath ) )
119+ {
120+ var directory = Path . GetDirectoryName ( string . Empty ) ;
121+ _specialKServiceManager . SetSpecialKInstallDirectory ( directory ) ;
122+ }
123+ else
124+ {
125+ _specialKServiceManager . ResetSpecialKInstallDirectory ( ) ;
126+ }
127+ }
128+ catch ( Exception ex )
129+ {
130+ _logger . Error ( ex , $ "Failed to set Special K installation from executable: { _settings . CustomSpecialKPath ?? "null" } ") ;
131+ }
109132 }
110133
111134 public bool VerifySettings ( out List < string > errors )
@@ -132,7 +155,7 @@ public RelayCommand BrowseSelectSpecialKExecutableCommand
132155 var filePath = _plugin . PlayniteApi . Dialogs . SelectFile ( "SKIF|SKIF.exe" ) ;
133156 if ( ! filePath . IsNullOrEmpty ( ) )
134157 {
135- settings . CustomSpecialKPath = filePath ;
158+ _settings . CustomSpecialKPath = filePath ;
136159 }
137160 } ) ;
138161 }
@@ -141,7 +164,7 @@ public RelayCommand RemoveSpecialKExecutableCommand
141164 {
142165 get => new RelayCommand ( ( ) =>
143166 {
144- settings . CustomSpecialKPath = string . Empty ;
167+ _settings . CustomSpecialKPath = string . Empty ;
145168 } ) ;
146169 }
147170 }
0 commit comments