@@ -224,22 +224,17 @@ private void GetPackages(bool isRefresh = false)
224224 if ( ! Directory . Exists ( _path + @"\manifests" ) || isRefresh )
225225 {
226226 var manifestUrl = "https://github.com/microsoft/winget-pkgs/archive/master.zip" ;
227- //Todo: A Fix Need Here
228- //DownloaderService = new DownloadService();
229- //DownloaderService.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e)
230- //{
231- // OnDownloadProgressChanged(sender, e, DownloadMode.Repository);
232- //};
233- //DownloaderService.DownloadFileCompleted += delegate (object sender, AsyncCompletedEventArgs e)
234- //{
235- // OnDownloadFileCompleted(sender, e, DownloadMode.Repository);
236- //};
237- //await DownloaderService.DownloadFileAsync(manifestUrl, new DirectoryInfo(_path));
238-
239- WebClient client = new WebClient ( ) ;
240- client . DownloadFileCompleted += Client_DownloadFileCompleted ;
241- client . DownloadProgressChanged += Client_DownloadProgressChanged ;
242- await client . DownloadFileTaskAsync ( new Uri ( manifestUrl ) , Path . Combine ( _path , "master.zip" ) ) ;
227+
228+ DownloaderService = new DownloadService ( ) ;
229+ DownloaderService . DownloadProgressChanged += delegate ( object sender , DownloadProgressChangedEventArgs e )
230+ {
231+ OnDownloadProgressChanged ( sender , e , DownloadMode . Repository ) ;
232+ } ;
233+ DownloaderService . DownloadFileCompleted += delegate ( object sender , AsyncCompletedEventArgs e )
234+ {
235+ OnDownloadFileCompleted ( sender , e , DownloadMode . Repository ) ;
236+ } ;
237+ await DownloaderService . DownloadFileAsync ( manifestUrl , new DirectoryInfo ( _path ) ) ;
243238 }
244239
245240 LoadingStatus = "Extracting packages..." ;
@@ -335,50 +330,6 @@ private void GetPackages(bool isRefresh = false)
335330 }
336331 }
337332
338- private void Client_DownloadProgressChanged ( object sender , System . Net . DownloadProgressChangedEventArgs e )
339- {
340- if ( e . TotalBytesToReceive == - 1 )
341- {
342- if ( ! IsIndeterminate )
343- {
344- IsIndeterminate = true ;
345- }
346-
347- LoadingStatus = "Downloading..." ;
348- }
349- else
350- {
351- if ( IsIndeterminate )
352- {
353- IsIndeterminate = false ;
354- }
355-
356- Progress = e . ProgressPercentage ;
357- LoadingStatus =
358- $ "Downloading { Tools . ConvertBytesToMegabytes ( e . BytesReceived ) } MB of { Tools . ConvertBytesToMegabytes ( e . TotalBytesToReceive ) } MB - { e . ProgressPercentage } %";
359- }
360- }
361-
362- private void Client_DownloadFileCompleted ( object sender , AsyncCompletedEventArgs e )
363- {
364- try
365- {
366- UpdatedDate = DateTime . Now . ToString ( ) ;
367- GlobalDataHelper < AppConfig > . Config . UpdatedDate = DateTime . Now ;
368- GlobalDataHelper < AppConfig > . Save ( ) ;
369- IsIndeterminate = true ;
370- LoadingStatus = "Extracting Manifests..." ;
371- ZipFile . ExtractToDirectory ( Path . Combine ( _path , "master.zip" ) , Path . Combine ( _path ) , true ) ;
372- LoadingStatus = "Cleaning Directory..." ;
373- CleanDirectory ( ) ;
374- Progress = 0 ;
375- IsIndeterminate = false ;
376- }
377- catch ( InvalidDataException )
378- {
379- }
380- }
381-
382333 private async void OnButtonAction ( string param )
383334 {
384335 string text = $ "winget install { _selectedPackage . Id } -v { _selectedPackage . Version } ";
@@ -687,9 +638,7 @@ public async void InstallInternalMode()
687638 private void CleanDirectory ( )
688639 {
689640 var rootDir = new DirectoryInfo ( _path + @"\winget-pkgs-master" ) ;
690- //Todo: A Fix Need Here
691- var zipFile = new FileInfo ( _path + @"\master.zip" ) ;
692- //var zipFile = new FileInfo(DownloaderService.Package.FileName);
641+ var zipFile = new FileInfo ( DownloaderService . Package . FileName ) ;
693642 var pkgDir = new DirectoryInfo ( _path + @"\manifests" ) ;
694643 var moveDir = new DirectoryInfo ( _path + @"\winget-pkgs-master\manifests" ) ;
695644 if ( moveDir . Exists )
@@ -728,16 +677,25 @@ private bool FilterCombo(VersionModel item)
728677
729678 private void OnDownloadFileCompleted ( object sender , AsyncCompletedEventArgs e , DownloadMode mode )
730679 {
731- //Todo: A Fix Need Here
732680 switch ( mode )
733681 {
734682 case DownloadMode . Repository :
735- // UpdatedDate = DateTime.Now.ToString();
736- // GlobalDataHelper<AppConfig>.Config.UpdatedDate = DateTime.Now;
737- // GlobalDataHelper<AppConfig>.Save();
738-
739- //await Task.Delay(1000);
740- //ZipFile.ExtractToDirectory(DownloaderService.Package.FileName, _path, true);
683+ try
684+ {
685+ UpdatedDate = DateTime . Now . ToString ( ) ;
686+ GlobalDataHelper < AppConfig > . Config . UpdatedDate = DateTime . Now ;
687+ GlobalDataHelper < AppConfig > . Save ( ) ;
688+ IsIndeterminate = true ;
689+ LoadingStatus = "Extracting Manifests..." ;
690+ ZipFile . ExtractToDirectory ( DownloaderService . Package . FileName , _path , true ) ;
691+ LoadingStatus = "Cleaning Directory..." ;
692+ CleanDirectory ( ) ;
693+ Progress = 0 ;
694+ IsIndeterminate = false ;
695+ }
696+ catch ( InvalidDataException )
697+ {
698+ }
741699 CleanDirectory ( ) ;
742700 break ;
743701 case DownloadMode . Package :
@@ -752,17 +710,35 @@ private void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e, D
752710
753711 private void OnDownloadProgressChanged ( object sender , DownloadProgressChangedEventArgs e , DownloadMode mode )
754712 {
755- //Todo: A Fix Need Here
756713 Progress = ( int ) e . ProgressPercentage ;
757714 switch ( mode )
758715 {
759716 case DownloadMode . Repository :
760- LoadingStatus =
761- $ "Downloading { Tools . ConvertBytesToMegabytes ( e . BytesReceived ) } MB from { Tools . ConvertBytesToMegabytes ( e . TotalBytesToReceive ) } MB - { ( int ) e . ProgressPercentage } %";
717+
718+ if ( e . TotalBytesToReceive == - 1 )
719+ {
720+ if ( ! IsIndeterminate )
721+ {
722+ IsIndeterminate = true ;
723+ }
724+
725+ LoadingStatus = "Downloading..." ;
726+ }
727+ else
728+ {
729+ if ( IsIndeterminate )
730+ {
731+ IsIndeterminate = false ;
732+ }
733+
734+ Progress = Progress ;
735+ LoadingStatus =
736+ $ "Downloading { Tools . ConvertBytesToMegabytes ( e . BytesReceived ) } MB of { Tools . ConvertBytesToMegabytes ( e . TotalBytesToReceive ) } MB - { Progress } %";
737+ }
762738 break ;
763739 case DownloadMode . Package :
764740 LoadingStatus =
765- $ "Downloading { _selectedPackage . Id } -{ _selectedPackage . Version } - { Tools . ConvertBytesToMegabytes ( e . BytesReceived ) } MB from { Tools . ConvertBytesToMegabytes ( e . TotalBytesToReceive ) } MB - { ( int ) e . ProgressPercentage } %";
741+ $ "Downloading { _selectedPackage . Id } -{ _selectedPackage . Version } - { Tools . ConvertBytesToMegabytes ( e . BytesReceived ) } MB of { Tools . ConvertBytesToMegabytes ( e . TotalBytesToReceive ) } MB - { Progress } %";
766742 break ;
767743 }
768744 }
0 commit comments