@@ -41,17 +41,19 @@ public class InstallationService : IInstallationService
4141 private readonly List < Download > _downloads ;
4242 private List < Installation > _installations = new ( ) ;
4343 private readonly string _installationsJsonFilePath ;
44+ private readonly ITTSService _TTSVersionService ;
4445
4546 public InstallationService ( HttpClient httpClient , IPreferencesService preferencesService ,
4647 IEnvironmentService environmentService , IServerService serverService , ICodeScanService codeScanService ,
47- ICodeScanConfigService codeScanConfigService )
48+ ICodeScanConfigService codeScanConfigService , ITTSService ITTSVersionService )
4849 {
4950 _httpClient = httpClient ;
5051 _preferencesService = preferencesService ;
5152 _environmentService = environmentService ;
5253 _serverService = serverService ;
5354 _codeScanService = codeScanService ;
5455 _codeScanConfigService = codeScanConfigService ;
56+ _TTSVersionService = ITTSVersionService ;
5557
5658 _downloads = new ( ) ;
5759 _installationsJsonFilePath = Path . Combine ( _environmentService . GetUserdataDirectory ( ) , "installations.json" ) ;
@@ -93,14 +95,12 @@ public List<Installation> GetInstallations()
9395 return ( null ! , failureReason ) ;
9496 }
9597
96- server . ServerGoodFileVersion = "1.0.0" ; //TODO
97-
98- bool result = await _codeScanConfigService . ValidGoodFilesVersionAsync ( server . ServerGoodFileVersion ) ;
98+ bool result = await _codeScanConfigService . ValidGoodFilesVersionAsync ( server . GoodFileVersion ) ;
9999
100100 if ( result == false )
101101 {
102102 const string failureReason = "server does not have a valid ServerGoodFileVersion " ;
103- Log . Warning ( failureReason + $ " ServerName: { server . ServerName } ServerGoodFileVersion : { server . ServerGoodFileVersion } ") ;
103+ Log . Warning ( failureReason + $ " ServerName: { server . ServerName } ServerGoodFileVersion : { server . GoodFileVersion } ") ;
104104 return ( null ! , failureReason ) ;
105105 }
106106
@@ -115,9 +115,20 @@ public List<Installation> GetInstallations()
115115
116116 string installationBasePath = _preferencesService . GetPreferences ( ) . InstallationPath ;
117117 // should be something like {basePath}/{forkName}/{version}
118- string installationPath = Path . Combine ( installationBasePath , server . ForkName . SanitiseStringPath ( ) , server . ServerGoodFileVersion . SanitiseStringPath ( ) , server . BuildVersion . ToString ( ) ) ;
118+ if ( server . ForkName . SanitiseStringPath ( ) == "nonbuild" )
119+ {
120+ throw new Exception ( $ " bad server ForkName { server . ForkName . SanitiseStringPath ( ) } Not allowed as save location (nonbuild)") ;
121+ }
122+
123+ if ( server . ForkName . SanitiseStringPath ( ) == "tts" )
124+ {
125+ throw new Exception ( $ " bad server ForkName { server . ForkName . SanitiseStringPath ( ) } Not allowed as save location (tts) ") ;
126+ }
127+
119128
120- download = new ( downloadUrl , installationPath , server . ForkName , server . BuildVersion , server . ServerGoodFileVersion ) ;
129+ string installationPath = Path . Combine ( installationBasePath , server . ForkName . SanitiseStringPath ( ) , server . GoodFileVersion . SanitiseStringPath ( ) , server . BuildVersion . ToString ( ) ) ;
130+
131+ download = new ( downloadUrl , installationPath , server . ForkName , server . BuildVersion , server . GoodFileVersion ) ;
121132
122133 ( bool canStartDownload , string cantDownloadReason ) = CanStartDownload ( download ) ;
123134
@@ -133,12 +144,17 @@ public List<Installation> GetInstallations()
133144 }
134145
135146 _downloads . Add ( download ) ;
147+
148+
149+
136150 RxApp . MainThreadScheduler . ScheduleAsync ( ( _ , _ ) => StartDownloadAsync ( download ) ) ;
137151 return ( download , string . Empty ) ;
138152 }
139153
140154 public ( bool , string ) StartInstallation ( Guid installationId , string ? server = null , short ? port = null )
141155 {
156+ _TTSVersionService . StartTTS ( ) ;
157+
142158 Installation ? installation = GetInstallationById ( installationId ) ;
143159 if ( installation == null )
144160 {
@@ -422,6 +438,9 @@ private static string GetArguments(string? server, long? port)
422438
423439 private async Task StartDownloadAsync ( Download download )
424440 {
441+ //Update TTS if it's needed
442+ await _TTSVersionService . CheckAndDownloadLatestVersion ( download ) ;
443+
425444 Log . Information ( "Download requested, Installation Path '{Path}', Url '{Url}'" , download . InstallPath , download . DownloadUrl ) ;
426445 try
427446 {
@@ -433,13 +452,11 @@ private async Task StartDownloadAsync(Download download)
433452 await using Stream responseStream = await request . Content . ReadAsStreamAsync ( ) ;
434453 Log . Information ( "Download connection established" ) ;
435454 await using ProgressStream progressStream = new ( responseStream ) ;
436- download . Size = request . Content . Headers . ContentLength ??
437- throw new ContentLengthNullException ( download . DownloadUrl ) ;
455+ download . Size = request . Content . Headers . ContentLength ?? throw new ContentLengthNullException ( download . DownloadUrl ) ;
438456
439457 using IDisposable logProgressDisposable = LogProgress ( progressStream , download ) ;
440458
441- using IDisposable progressDisposable = progressStream . Progress
442- . Subscribe ( p => { download . Downloaded = p ; } ) ;
459+ using IDisposable progressDisposable = progressStream . Progress . Subscribe ( p => { download . Downloaded = p ; } ) ;
443460
444461 // ExtractAndScan() must be run in a separate thread, but we want this one to wait for that one to finish
445462 // Without this download progress will not work properly
@@ -558,7 +575,7 @@ private static async Task ShowScanFailPopUp(string message, string logFolder)
558575 }
559576 }
560577
561- private static IDisposable LogProgress ( ProgressStream progressStream , Download download )
578+ public static IDisposable LogProgress ( ProgressStream progressStream , Download download )
562579 {
563580 long lastPosition = 0L ;
564581 DateTime lastTime = DateTime . Now ;
0 commit comments