@@ -33,6 +33,8 @@ import VersionBundlesLoader, {
3333import  {  sep  }  from  "path" ; 
3434import  {  join  as  posixJoin  }  from  "path/posix" ; 
3535import  {  NINJA_AUTO_INSTALL_DISABLED  }  from  "../webview/newProjectPanel.mjs" ; 
36+ import  Logger  from  "../logger.mjs" ; 
37+ import  type  {  Progress  as  GotProgress  }  from  "got" ; 
3638
3739export  interface  AdvancedSwitchSDKOptions  { 
3840  toolchainVersion : {  label : string ;  toolchain : SupportedToolchainVersion  } ; 
@@ -47,6 +49,7 @@ interface SwitchSDKOptions {
4749
4850export  default  class  SwitchSDKCommand  extends  Command  { 
4951  private  _versionBundlesLoader : VersionBundlesLoader ; 
52+   private  _logger : Logger  =  new  Logger ( "SwitchSDKCommand" ) ; 
5053
5154  public  static  readonly  id  =  "switchSDK" ; 
5255
@@ -383,107 +386,305 @@ export default class SwitchSDKCommand extends Command {
383386          //options.advancedOptions is defined 
384387          options . advancedOptions ! . toolchainVersion ; 
385388
386-     // show progress bar  while installing 
387-     const  result  =  await  window . withProgress ( 
389+     // show individual  progress bars  while installing 
390+     let  result  =  await  window . withProgress ( 
388391      { 
389-         title :
390-           `Installing SDK ${ selectedSDK . label }  , `  + 
391-           `toolchain ${ selectedToolchain . label }   `  + 
392-           "and tools..." , 
393392        location : ProgressLocation . Notification , 
393+         title : "Installing SDK..." , 
394+         cancellable : false , 
394395      } , 
395396      async  progress  =>  { 
396397        // download and install selected SDK 
397-         if  ( 
398-           ( await  downloadAndInstallSDK ( selectedSDK . sdk ,  SDK_REPOSITORY_URL ) )  && 
399-           ( await  downloadAndInstallTools ( selectedSDK . sdk ) ) 
400-         )  { 
398+         // TODO: maybe parse python3 path 
399+         const  result  =  await  downloadAndInstallSDK ( 
400+           selectedSDK . sdk , 
401+           SDK_REPOSITORY_URL 
402+         ) ; 
403+ 
404+         if  ( result )  { 
405+           this . _logger . debug ( "Successfully installed SDK." ) ; 
406+ 
401407          progress . report ( { 
402-             increment : 40 , 
408+             increment : 100 , 
409+             // TODO: maybe only finished or sth like that 
410+             message : `Successfully installed SDK ${ selectedSDK . label }  .` , 
403411          } ) ; 
404412
405-           if  ( await  downloadAndInstallToolchain ( selectedToolchain . toolchain ) )  { 
413+           return  true ; 
414+         } 
415+ 
416+         this . _logger . error ( "Failed to install SDK." ) ; 
417+ 
418+         progress . report ( { 
419+           increment : 100 , 
420+         } ) ; 
421+ 
422+         void  window . showErrorMessage ( 
423+           `Failed to install SDK ${ selectedSDK . label }  . `  + 
424+             "Make sure all requirements are met." 
425+         ) ; 
426+ 
427+         return  false ; 
428+       } 
429+     ) ; 
430+ 
431+     if  ( ! result )  { 
432+       return ; 
433+     } 
434+ 
435+     let  progressState  =  0 ; 
436+     result  =  await  window . withProgress ( 
437+       { 
438+         location : ProgressLocation . Notification , 
439+         title : "Installing toolchain..." , 
440+         cancellable : false , 
441+       } , 
442+       async  progress  =>  { 
443+         // download and install selected toolchain 
444+         const  result  =  await  downloadAndInstallToolchain ( 
445+           selectedToolchain . toolchain , 
446+           ( prog : GotProgress )  =>  { 
447+             const  percent  =  prog . percent  *  100 ; 
448+             progress . report ( { 
449+               increment : percent  -  progressState , 
450+             } ) ; 
451+             progressState  =  percent ; 
452+           } 
453+         ) ; 
454+ 
455+         if  ( result )  { 
456+           this . _logger . debug ( "Successfully installed toolchain." ) ; 
457+ 
458+           progress . report ( { 
459+             increment : 100 , 
460+             message :
461+               "Successfully installed "  + 
462+               `toolchain ${ selectedToolchain . label }  .` , 
463+           } ) ; 
464+ 
465+           return  true ; 
466+         } 
467+ 
468+         this . _logger . error ( "Failed to install toolchain." ) ; 
469+ 
470+         progress . report ( { 
471+           increment : 100 , 
472+         } ) ; 
473+ 
474+         void  window . showErrorMessage ( 
475+           `Failed to install toolchain ${ selectedToolchain . label }  .` 
476+         ) ; 
477+ 
478+         return  false ; 
479+       } 
480+     ) ; 
481+ 
482+     if  ( ! result )  { 
483+       return ; 
484+     } 
485+ 
486+     progressState  =  0 ; 
487+     result  =  await  window . withProgress ( 
488+       { 
489+         location : ProgressLocation . Notification , 
490+         title : "Installing tools..." , 
491+         cancellable : false , 
492+       } , 
493+       async  progress  =>  { 
494+         // download and install tools 
495+         const  result  =  await  downloadAndInstallTools ( 
496+           selectedSDK . sdk , 
497+           ( prog : GotProgress )  =>  { 
498+             const  percent  =  prog . percent  *  100 ; 
406499            progress . report ( { 
407-               increment : 20 , 
500+               increment : percent   -   progressState , 
408501            } ) ; 
502+             progressState  =  percent ; 
503+           } 
504+         ) ; 
505+ 
506+         if  ( result )  { 
507+           this . _logger . debug ( "Successfully installed tools." ) ; 
508+ 
509+           progress . report ( { 
510+             increment : 100 , 
511+             message : "Successfully installed tools." , 
512+           } ) ; 
513+ 
514+           return  true ; 
515+         } 
516+ 
517+         this . _logger . error ( "Failed to install tools." ) ; 
518+ 
519+         progress . report ( { 
520+           increment : 100 , 
521+         } ) ; 
522+ 
523+         void  window . showErrorMessage ( "Failed to install tools." ) ; 
524+ 
525+         return  false ; 
526+       } 
527+     ) ; 
528+ 
529+     if  ( ! result )  { 
530+       return ; 
531+     } 
409532
410-             if  ( 
411-               options . advancedOptions ?. ninjaVersion  !==  undefined  && 
412-               ( await  downloadAndInstallNinja ( 
413-                 options . advancedOptions . ninjaVersion 
414-               ) ) 
415-             )  { 
533+     if  ( options . advancedOptions ?. ninjaVersion  !==  undefined )  { 
534+       progressState  =  0 ; 
535+       result  =  await  window . withProgress ( 
536+         { 
537+           location : ProgressLocation . Notification , 
538+           title : "Downloading and installing Ninja..." , 
539+           cancellable : false , 
540+         } , 
541+         async  progress  =>  { 
542+           const  result  =  await  downloadAndInstallNinja ( 
543+             options . advancedOptions ! . ninjaVersion ! , 
544+             ( prog : GotProgress )  =>  { 
545+               const  percent  =  prog . percent  *  100 ; 
416546              progress . report ( { 
417-                 increment : 10 , 
547+                 increment : percent   -   progressState , 
418548              } ) ; 
549+               progressState  =  percent ; 
419550            } 
551+           ) ; 
552+ 
553+           if  ( result )  { 
554+             progress . report ( { 
555+               increment : 100 , 
556+               message : "Successfully installed Ninja." , 
557+             } ) ; 
558+ 
559+             return  true ; 
560+           } 
561+ 
562+           progress . report ( { 
563+             increment : 100 , 
564+           } ) ; 
420565
421-             // install if cmakeVersion is not a path and not a command 
422-             if  ( 
423-               options . advancedOptions ?. cmakeVersion  !==  undefined  && 
566+           void  window . showWarningMessage ( "Failed to install Ninja." ) ; 
567+ 
568+           return  false ; 
569+         } 
570+       ) ; 
571+ 
572+       if  ( ! result )  { 
573+         return ; 
574+       } 
575+     }  else  { 
576+       // TODO: maybe show error 
577+       /* 
578+       this._logger.error("Advanced options are undefined."); 
579+ 
580+         void window.showErrorMessage("Failed to get Ninja version."); 
581+ 
582+         return; 
583+         */ 
584+     } 
585+ 
586+     // TODO: check if not version bundle check here would be better 
587+     /* compare with ninja checks 
588+     options.advancedOptions?.cmakeVersion !== undefined && 
424589              !options.advancedOptions.cmakeVersion.includes("/") && 
425590              options.advancedOptions.cmakeVersion !== "cmake" && 
426591              (await downloadAndInstallCmake( 
427592                options.advancedOptions.cmakeVersion 
428-               ) ) 
429-             )  { 
593+               ))*/ 
594+     if  ( 
595+       options . advancedOptions ?. cmakeVersion  !==  undefined  && 
596+       ! options . advancedOptions . cmakeVersion . includes ( "/" )  && 
597+       options . advancedOptions . cmakeVersion  !==  "cmake" 
598+     )  { 
599+       progressState  =  0 ; 
600+       result  =  await  window . withProgress ( 
601+         { 
602+           location : ProgressLocation . Notification , 
603+           title : "Downloading and installing CMake..." , 
604+           cancellable : false , 
605+         } , 
606+         async  progress  =>  { 
607+           const  result  =  await  downloadAndInstallCmake ( 
608+             options . advancedOptions ! . cmakeVersion , 
609+             ( prog : GotProgress )  =>  { 
610+               const  percent  =  prog . percent  *  100 ; 
430611              progress . report ( { 
431-                 increment : 10 , 
612+                 increment : percent   -   progressState , 
432613              } ) ; 
614+               progressState  =  percent ; 
433615            } 
616+           ) ; 
434617
435-             await  updateVSCodeStaticConfigs ( 
436-               workspaceFolder . uri . fsPath , 
437-               selectedSDK . sdk , 
438-               selectedToolchain . toolchain . version , 
439-               options . advancedOptions ?. ninjaVersion , 
440-               options . advancedOptions ?. cmakeVersion 
441-             ) ; 
618+           if  ( result )  { 
619+             this . _logger . debug ( "Successfully installed CMake." ) ; 
442620
443621            progress . report ( { 
444-               increment : 10 , 
622+               increment : 100 , 
445623            } ) ; 
446624
447-             const  cmakeUpdateResult  =  await  cmakeUpdateSDK ( 
448-               workspaceFolder . uri , 
449-               selectedSDK . sdk , 
450-               selectedToolchain . toolchain . version , 
451-               selectedPicotool  ??  "2.0.0" 
452-             ) ; 
453- 
454-             if  ( ! cmakeUpdateResult )  { 
455-               void  window . showWarningMessage ( 
456-                 "Failed to update CMakeLists.txt for new SDK version." 
457-               ) ; 
458-             } 
459- 
460-             progress . report ( { 
461-               // show sdk installed notification 
462-               message : `Successfully installed SDK ${ selectedSDK . label }  .` , 
463-               increment : 10 , 
464-             } ) ; 
625+             void  window . showInformationMessage ( "Successfully installed CMake." ) ; 
465626
466627            return  true ; 
467-           }  else  { 
468-             progress . report ( { 
469-               message :
470-                 "Failed to install "  +  `toolchain ${ selectedToolchain . label }  .` , 
471-               increment : 60 , 
472-             } ) ; 
473- 
474-             return  false ; 
475628          } 
629+ 
630+           this . _logger . error ( "Failed to install CMake." ) ; 
631+ 
632+           progress . report ( { 
633+             increment : 100 , 
634+           } ) ; 
635+ 
636+           void  window . showWarningMessage ( "Failed to install CMake." ) ; 
637+ 
638+           return  false ; 
476639        } 
640+       ) ; 
641+ 
642+       if  ( ! result )  { 
643+         return ; 
644+       } 
645+     } 
646+ 
647+     result  =  await  window . withProgress ( 
648+       { 
649+         location : ProgressLocation . Notification , 
650+         title : "Updating project configuration..." , 
651+         cancellable : false , 
652+       } , 
653+       async  progress  =>  { 
654+         await  updateVSCodeStaticConfigs ( 
655+           workspaceFolder . uri . fsPath , 
656+           selectedSDK . sdk , 
657+           selectedToolchain . toolchain . version , 
658+           options . advancedOptions ?. ninjaVersion , 
659+           options . advancedOptions ?. cmakeVersion 
660+         ) ; 
477661
478662        progress . report ( { 
479-           // show sdk install failed notification 
480-           message :
481-             `Failed to install SDK ${ selectedSDK . label }  .`  + 
482-             "Make sure all requirements are met." , 
483-           increment : 100 , 
663+           increment : 50 , 
664+           message : "Project configuration updated." , 
484665        } ) ; 
485666
486-         return  false ; 
667+         const  cmakeUpdateResult  =  await  cmakeUpdateSDK ( 
668+           workspaceFolder . uri , 
669+           selectedSDK . sdk , 
670+           selectedToolchain . toolchain . version , 
671+           selectedPicotool  ??  "2.0.0" 
672+         ) ; 
673+ 
674+         progress . report ( { 
675+           increment : 50 , 
676+           message : "CMakeLists.txt updated." , 
677+         } ) ; 
678+ 
679+         if  ( ! cmakeUpdateResult )  { 
680+           void  window . showWarningMessage ( 
681+             "Failed to update CMakeLists.txt for new SDK version." 
682+           ) ; 
683+ 
684+           return  false ; 
685+         } 
686+ 
687+         return  true ; 
487688      } 
488689    ) ; 
489690
0 commit comments