44using System . IO ;
55using System . IO . Compression ;
66using System . Net . Http ;
7+ using System . Reactive . Concurrency ;
78using System . Text . Json ;
89using System . Threading ;
910using System . Threading . Tasks ;
1011using Avalonia . Controls . Shapes ;
1112using Mono . Unix ;
13+ using ReactiveUI ;
1214using Serilog ;
1315using SharpCompress . Archives ;
1416using SharpCompress . Archives . Tar ;
@@ -130,18 +132,19 @@ public async Task CheckAndDownloadLatestVersion(Download Download)
130132
131133 Download . Active = true ;
132134 Download . DownloadState = DownloadState . InProgress ;
135+
133136 HttpResponseMessage request = await _httpClient . GetAsync ( ApiUrls . TTSFiles + "/" + zip ,
134137 HttpCompletionOption . ResponseHeadersRead ) ;
135138
136- Download . Size = request . Content . Headers . ContentLength ??
137- throw new ContentLengthNullException ( ApiUrls . TTSFiles + "/" + zip ) ;
138139 using Stream responseStream = await request . Content . ReadAsStreamAsync ( ) ;
139140 Log . Information ( "Download connection established" ) ;
140141 await using ProgressStream progressStream = new ( responseStream ) ;
141142 using IDisposable logProgressDisposable = InstallationService . LogProgress ( progressStream , Download ) ;
142143
143- using IDisposable progressDisposable =
144- progressStream . Progress . Subscribe ( p => { Download . Downloaded = p ; } ) ;
144+ Download . Size = request . Content . Headers . ContentLength ??
145+ throw new ContentLengthNullException ( ApiUrls . TTSFiles + "/" + zip ) ;
146+
147+ using IDisposable progressDisposable = progressStream . Progress . Subscribe ( p => { Download . Downloaded = p ; } ) ;
145148
146149 await Task . Run ( ( ) => ExtractTo ( progressStream , LocalVersion , Download ) ) ;
147150 }
@@ -157,18 +160,20 @@ public async Task CheckAndDownloadLatestVersion(Download Download)
157160
158161 private void ExtractTo ( Stream progressStream , string LocalVersion , Download Download )
159162 {
160- Download . DownloadState = DownloadState . Extracting ;
163+
161164 switch ( _environmentService . GetCurrentEnvironment ( ) )
162165 {
163166 case CurrentEnvironment . WindowsStandalone :
164167 {
165168 ZipArchive archive = new ( progressStream ) ;
169+ Download . DownloadState = DownloadState . Extracting ;
166170 archive . ExtractToDirectory ( LocalVersion , true ) ;
167171 break ;
168172 }
169173 case CurrentEnvironment . LinuxStandalone or CurrentEnvironment . LinuxFlatpak :
170174 {
171175 using var decompressedStream = DecompressXz ( progressStream ) ; // Decompress XZ stream to get .tar
176+
172177 ExtractTar ( decompressedStream , LocalVersion ) ;
173178 break ;
174179 }
@@ -220,11 +225,13 @@ private void ExtractTar(Stream tarStream, string destinationPath)
220225 return _environmentService . GetCurrentEnvironment ( ) switch
221226 {
222227 CurrentEnvironment . WindowsStandalone
223- => ( Path . Combine ( installationBasePath , "tts" , "python-3.10.11.amd64" , "python.exe" ) , Path . Combine ( installationBasePath , "tts" , "scripts" ) ) ,
228+ => ( Path . Combine ( installationBasePath , "tts" , "python-3.10.11.amd64" , "python.exe" ) ,
229+ Path . Combine ( installationBasePath , "tts" , "scripts" ) ) ,
224230 CurrentEnvironment . MacOsStandalone
225231 => throw new NotImplementedException ( "tts Mac Support not implemented" ) ,
226232 CurrentEnvironment . LinuxStandalone or CurrentEnvironment . LinuxFlatpak
227- => ( Path . Combine ( installationBasePath , "tts" , "bin" , "python" ) , Path . Combine ( installationBasePath , "tts" , "bin" ) ) ,
233+ => ( Path . Combine ( installationBasePath , "tts" , "bin" , "python" ) ,
234+ Path . Combine ( installationBasePath , "tts" , "bin" ) ) ,
228235 _ => ( null , null )
229236 } ;
230237 }
0 commit comments