55using  OtterGui . Services ; 
66using  Penumbra . Api . Api ; 
77using  Penumbra . Api . Enums ; 
8+ using  Penumbra . Mods . Settings ; 
89
910namespace  Penumbra . Api ; 
1011
@@ -13,13 +14,15 @@ public class HttpApi : IDisposable, IApiService
1314    private  partial  class  Controller  :  WebApiController 
1415    { 
1516        // @formatter:off 
16-         [ Route (  HttpVerbs . Get ,   "/mods"        ) ]  public  partial  object ?  GetMods ( ) ; 
17-         [ Route (  HttpVerbs . Post ,  "/redraw"      ) ]  public  partial  Task     Redraw ( ) ; 
18-         [ Route (  HttpVerbs . Post ,  "/redrawAll"   ) ]  public  partial  Task     RedrawAll ( ) ; 
19-         [ Route (  HttpVerbs . Post ,  "/reloadmod"   ) ]  public  partial  Task     ReloadMod ( ) ; 
20-         [ Route (  HttpVerbs . Post ,  "/installmod"  ) ]  public  partial  Task     InstallMod ( ) ; 
21-         [ Route (  HttpVerbs . Post ,  "/openwindow"  ) ]  public  partial  void     OpenWindow ( ) ; 
22-         [ Route (  HttpVerbs . Post ,  "/focusmod"    ) ]  public  partial  Task     FocusMod ( ) ; 
17+         [ Route (  HttpVerbs . Get ,   "/moddirectory"   ) ]  public  partial  string  GetModDirectory ( ) ; 
18+         [ Route (  HttpVerbs . Get ,   "/mods"           ) ]  public  partial  object ?  GetMods ( ) ; 
19+         [ Route (  HttpVerbs . Post ,  "/redraw"         ) ]  public  partial  Task     Redraw ( ) ; 
20+         [ Route (  HttpVerbs . Post ,  "/redrawAll"      ) ]  public  partial  Task     RedrawAll ( ) ; 
21+         [ Route (  HttpVerbs . Post ,  "/reloadmod"      ) ]  public  partial  Task     ReloadMod ( ) ; 
22+         [ Route (  HttpVerbs . Post ,  "/installmod"     ) ]  public  partial  Task     InstallMod ( ) ; 
23+         [ Route (  HttpVerbs . Post ,  "/openwindow"     ) ]  public  partial  void     OpenWindow ( ) ; 
24+         [ Route (  HttpVerbs . Post ,  "/focusmod"       ) ]  public  partial  Task     FocusMod ( ) ; 
25+         [ Route (  HttpVerbs . Post ,  "/setmodsettings" ) ]  public  partial  Task     SetModSettings ( ) ; 
2326        // @formatter:on 
2427    } 
2528
@@ -65,6 +68,12 @@ public void Dispose()
6568
6669    private  partial  class  Controller ( IPenumbraApi  api ,  IFramework  framework ) 
6770    { 
71+         public  partial  string  GetModDirectory ( ) 
72+         { 
73+             Penumbra . Log . Debug ( $ "[HTTP] { nameof ( GetModDirectory ) }  triggered.") ; 
74+             return  api . PluginState . GetModDirectory ( ) ; 
75+         } 
76+ 
6877        public  partial  object ?  GetMods ( ) 
6978        { 
7079            Penumbra . Log . Debug ( $ "[HTTP] { nameof ( GetMods ) }  triggered.") ; 
@@ -116,6 +125,7 @@ public partial void OpenWindow()
116125            Penumbra . Log . Debug ( $ "[HTTP] { nameof ( OpenWindow ) }  triggered.") ; 
117126            api . Ui . OpenMainWindow ( TabType . Mods ,  string . Empty ,  string . Empty ) ; 
118127        } 
128+ 
119129        public  async  partial  Task  FocusMod ( ) 
120130        { 
121131            var  data  =  await  HttpContext . GetRequestDataAsync < ModFocusData > ( ) . ConfigureAwait ( false ) ; 
@@ -124,6 +134,30 @@ public async partial Task FocusMod()
124134                api . Ui . OpenMainWindow ( TabType . Mods ,  data . Path ,  data . Name ) ; 
125135        } 
126136
137+         public  async  partial  Task  SetModSettings ( ) 
138+         { 
139+             var  data  =  await  HttpContext . GetRequestDataAsync < SetModSettingsData > ( ) . ConfigureAwait ( false ) ; 
140+             Penumbra . Log . Debug ( $ "[HTTP] { nameof ( SetModSettings ) }  triggered.") ; 
141+             await  framework . RunOnFrameworkThread ( ( )  => 
142+                 { 
143+                     var  collection  =  data . CollectionId  ??  api . Collection . GetCollection ( ApiCollectionType . Current ) ! . Value . Id ; 
144+                     if  ( data . Inherit . HasValue ) 
145+                     { 
146+                         api . ModSettings . TryInheritMod ( collection ,  data . ModPath ,  data . ModName ,  data . Inherit . Value ) ; 
147+                         if  ( data . Inherit . Value ) 
148+                             return ; 
149+                     } 
150+ 
151+                     if  ( data . State . HasValue ) 
152+                         api . ModSettings . TrySetMod ( collection ,  data . ModPath ,  data . ModName ,  data . State . Value ) ; 
153+                     if  ( data . Priority . HasValue ) 
154+                         api . ModSettings . TrySetModPriority ( collection ,  data . ModPath ,  data . ModName ,  data . Priority . Value . Value ) ; 
155+                     foreach  ( var  ( group ,  settings )  in  data . Settings  ??  [ ] ) 
156+                         api . ModSettings . TrySetModSettings ( collection ,  data . ModPath ,  data . ModName ,  group ,  settings ) ; 
157+                 } 
158+             ) . ConfigureAwait ( false ) ; 
159+         } 
160+ 
127161        private  record  ModReloadData ( string  Path ,  string  Name ) 
128162        { 
129163            public  ModReloadData ( ) 
@@ -151,5 +185,15 @@ public RedrawData()
151185                :  this ( string . Empty ,  RedrawType . Redraw ,  - 1 ) 
152186            {  } 
153187        } 
188+ 
189+         private  record  SetModSettingsData ( 
190+             Guid ?  CollectionId , 
191+             string  ModPath , 
192+             string  ModName , 
193+             bool ?  Inherit , 
194+             bool ?  State , 
195+             ModPriority ?  Priority , 
196+             Dictionary < string ,  List < string > > ?  Settings ) 
197+         {  } 
154198    } 
155199} 
0 commit comments