@@ -11,7 +11,7 @@ namespace ChuChartManager.Controllers;
1111public class ModController : ControllerBase
1212{
1313 public record ModInfo ( string Name , string Version ) ;
14- public record ModStatus ( bool LoaderInstalled , List < ModInfo > Mods ) ;
14+ public record ModStatus ( bool LoaderInstalled , bool ProxyInstalled , List < ModInfo > Mods ) ;
1515 public record ModSectionConfig ( bool Enabled , Dictionary < string , object ? > Entries ) ;
1616 public record ModConfigRequest ( Dictionary < string , ModSectionConfig > Sections ) ;
1717
@@ -20,10 +20,11 @@ public ActionResult<ModStatus> GetStatus()
2020 {
2121 var gamePath = StaticSettings . GamePath ;
2222 if ( string . IsNullOrEmpty ( gamePath ) )
23- return Ok ( new ModStatus ( false , [ ] ) ) ;
23+ return Ok ( new ModStatus ( false , false , [ ] ) ) ;
2424
2525 var binPath = Path . Combine ( gamePath , "bin" ) ;
2626 var loaderInstalled = System . IO . File . Exists ( Path . Combine ( binPath , "version.dll" ) ) ;
27+ var proxyInstalled = System . IO . File . Exists ( Path . Combine ( binPath , "d3d9.dll" ) ) ;
2728 var modsPath = Path . Combine ( binPath , "mods" ) ;
2829 var mods = Directory . Exists ( modsPath )
2930 ? Directory . GetFiles ( modsPath , "*.dll" , SearchOption . TopDirectoryOnly )
@@ -32,11 +33,12 @@ public ActionResult<ModStatus> GetStatus()
3233 . ToList ( )
3334 : [ ] ;
3435
35- return Ok ( new ModStatus ( loaderInstalled , mods ) ) ;
36+ return Ok ( new ModStatus ( loaderInstalled , proxyInstalled , mods ) ) ;
3637 }
3738
3839 private const string LoaderRepo = "MuNET-OSS/ChuModLoader" ;
3940 private const string LoaderAsset = "version.dll" ;
41+ private const string ProxyAsset = "d3d9.dll" ;
4042 private const string AppleChuRepo = "MuNET-OSS/AppleChu" ;
4143 private const string AppleChuAsset = "AppleChu.dll" ;
4244
@@ -59,11 +61,13 @@ public async Task<ActionResult> GetLatestVersions()
5961
6062 var binPath = string . IsNullOrEmpty ( StaticSettings . GamePath ) ? "" : Path . Combine ( StaticSettings . GamePath , "bin" ) ;
6163 var loaderInstalled = ! string . IsNullOrEmpty ( binPath ) && System . IO . File . Exists ( Path . Combine ( binPath , "version.dll" ) ) ;
64+ var proxyInstalled = ! string . IsNullOrEmpty ( binPath ) && System . IO . File . Exists ( Path . Combine ( binPath , "d3d9.dll" ) ) ;
6265 var appleChuInstalled = ! string . IsNullOrEmpty ( binPath ) && System . IO . File . Exists ( Path . Combine ( binPath , "mods" , "AppleChu.dll" ) ) ;
6366
6467 return Ok ( new
6568 {
6669 loader = new VersionInfo ( loader ? . Tag_name ?? "" , loaderInstalled ? "installed" : "" , loader ? . Assets . FirstOrDefault ( a => a . Name == LoaderAsset ) ? . Browser_download_url ?? "" ) ,
70+ proxy = new VersionInfo ( loader ? . Tag_name ?? "" , proxyInstalled ? "installed" : "" , loader ? . Assets . FirstOrDefault ( a => a . Name == ProxyAsset ) ? . Browser_download_url ?? "" ) ,
6771 applechu = new VersionInfo ( applechu ? . Tag_name ?? "" , appleChuInstalled ? "installed" : "" , applechu ? . Assets . FirstOrDefault ( a => a . Name == AppleChuAsset ) ? . Browser_download_url ?? "" ) ,
6872 } ) ;
6973 }
@@ -75,18 +79,25 @@ public async Task<ActionResult> InstallLoader([FromBody] InstallRequest? request
7579 if ( string . IsNullOrEmpty ( gamePath ) )
7680 return BadRequest ( "GamePath not set" ) ;
7781
78- var url = request ? . Url ;
79- if ( string . IsNullOrEmpty ( url ) )
82+ var release = await GetLatestRelease ( LoaderRepo , LoaderAsset ) ;
83+
84+ var loaderUrl = request ? . Url ;
85+ if ( string . IsNullOrEmpty ( loaderUrl ) )
86+ loaderUrl = release ? . Assets . FirstOrDefault ( a => a . Name == LoaderAsset ) ? . Browser_download_url ;
87+ if ( string . IsNullOrEmpty ( loaderUrl ) )
88+ return NotFound ( "No release found" ) ;
89+
90+ var binPath = Path . Combine ( gamePath , "bin" ) ;
91+ var loaderData = await Http . GetByteArrayAsync ( loaderUrl ) ;
92+ await System . IO . File . WriteAllBytesAsync ( Path . Combine ( binPath , "version.dll" ) , loaderData ) ;
93+
94+ var proxyUrl = release ? . Assets . FirstOrDefault ( a => a . Name == ProxyAsset ) ? . Browser_download_url ;
95+ if ( ! string . IsNullOrEmpty ( proxyUrl ) )
8096 {
81- var release = await GetLatestRelease ( LoaderRepo , LoaderAsset ) ;
82- url = release ? . Assets . FirstOrDefault ( a => a . Name == LoaderAsset ) ? . Browser_download_url ;
97+ var proxyData = await Http . GetByteArrayAsync ( proxyUrl ) ;
98+ await System . IO . File . WriteAllBytesAsync ( Path . Combine ( binPath , "d3d9.dll" ) , proxyData ) ;
8399 }
84- if ( string . IsNullOrEmpty ( url ) )
85- return NotFound ( "No release found" ) ;
86100
87- var data = await Http . GetByteArrayAsync ( url ) ;
88- var dest = Path . Combine ( gamePath , "bin" , "version.dll" ) ;
89- await System . IO . File . WriteAllBytesAsync ( dest , data ) ;
90101 return Ok ( ) ;
91102 }
92103
0 commit comments