2016-06-27 4 views
0

Généralement, la version EXE est définie dans le fichier Bundle.wxs. Est-il possible d'obtenir cette version dans le projet Bootstrapper Application où la logique du moteur backend pour le programme d'installation est écrite? J'ai créé une interface utilisateur personnalisée en utilisant WPF. J'ai besoin de montrer la version dans l'interface utilisateur. Comment puis-je faire ceci? Veuillez nous conseiller Voici mon code d'application Bootstrapper.Obtention de la version de l'application à l'aide du projet Burn Bootstrapper

public class MainViewModel : ViewModelBase 
    { 
     private MINAClient minaClient; 

     //constructor 
     public MainViewModel(BootstrapperApplication bootstrapper) 
     { 

      this.IsThinking = false; 

      this.Bootstrapper = bootstrapper; 
      this.Bootstrapper.ApplyComplete += this.OnApplyComplete; 
      this.Bootstrapper.DetectPackageComplete += this.OnDetectPackageComplete; 
      this.Bootstrapper.PlanComplete += this.OnPlanComplete; 
      this.Bootstrapper.DetectComplete += this.DetectComplete; 

      this.Bootstrapper.CacheAcquireProgress += (sender, args) => 
      { 
       this.cacheProgress = args.OverallPercentage; 
       this.Progress = (this.cacheProgress + this.executeProgress)/2; 
      }; 
      this.Bootstrapper.ExecuteProgress += (sender, args) => 
      { 
       this.executeProgress = args.OverallPercentage; 
       this.Progress = (this.cacheProgress + this.executeProgress)/2; 
      }; 

      minaClient = new MINAClient(); 
      minaClient.initConnection("127.0.0.1", 9123); 
     } 

     #region Properties 

     private bool installEnabled; 
     public bool InstallEnabled 
     { 
      get { return installEnabled; } 
      set 
      { 
       installEnabled = value; 
       RaisePropertyChanged("InstallEnabled"); 
      } 
     } 

     private bool uninstallEnabled; 
     public bool UninstallEnabled 
     { 
      get { return uninstallEnabled; } 
      set 
      { 
       uninstallEnabled = value; 
       RaisePropertyChanged("UninstallEnabled"); 
      } 
     } 

     private bool isThinking; 
     public bool IsThinking 
     { 
      get { return isThinking; } 
      set 
      { 
       isThinking = value; 
       RaisePropertyChanged("IsThinking"); 
      } 
     } 

     private int progress; 
     public int Progress 
     { 
      get { return progress; } 
      set 
      { 
       this.progress = value; 
       minaClient.sendMessage(value); 
       RaisePropertyChanged("Progress"); 
      } 
     } 

     private int cacheProgress; 
     private int executeProgress; 

     public BootstrapperApplication Bootstrapper { get; private set; } 

     #endregion //Properties 

     #region Methods 

     public void InstallExecute() 
     { 
      Bootstrapper.Engine.Log(LogLevel.Verbose, "See actually i've called install method"); 
      IsThinking = true; 
      Bootstrapper.Engine.Plan(LaunchAction.Install); 
     } 

     public void UninstallExecute() 
     { 
      Bootstrapper.Engine.Log(LogLevel.Verbose, "See actually i've called un-install method"); 
      IsThinking = true; 
      Bootstrapper.Engine.Plan(LaunchAction.Uninstall); 
     } 

     public void ExitExecute() 
     { 
      CustomBA.BootstrapperDispatcher.InvokeShutdown(); 
     } 


     /// <summary> 
     /// Method that gets invoked when the Bootstrapper ApplyComplete event is fired. 
     /// This is called after a bundle installation has completed. Make sure we updated the view. 
     /// </summary> 
     private void OnApplyComplete(object sender, ApplyCompleteEventArgs e) 
     { 
      IsThinking = false; 
      InstallEnabled = false; 
      UninstallEnabled = false; 
      this.Progress = 100; 
      ExitExecute(); 
     } 

     void DetectComplete(object sender, DetectCompleteEventArgs e) 
     { 
      Bootstrapper.Engine.Log(LogLevel.Verbose,"fired! but does that give you any clue?! idiot!"); 
      if (LaunchAction.Uninstall == Bootstrapper.Command.Action) 
      { 
       Bootstrapper.Engine.Log(LogLevel.Verbose, "Invoking automatic plan for uninstall"); 
       Bootstrapper.Engine.Plan(LaunchAction.Uninstall); 
      } 
     } 

     /// <summary> 
     /// Method that gets invoked when the Bootstrapper DetectPackageComplete event is fired. 
     /// Checks the PackageId and sets the installation scenario. The PackageId is the ID 
     /// specified in one of the package elements (msipackage, exepackage, msppackage, 
     /// msupackage) in the WiX bundle. 
     /// </summary> 
     private void OnDetectPackageComplete(object sender, DetectPackageCompleteEventArgs e) 
     { 
      if (e.PackageId == "UpdaterServiceInstallerId" || e.PackageId == "MosquittoInstallerId" || e.PackageId == "AppsInstallerId") 
      { 
       if (e.State == PackageState.Absent) 
        InstallEnabled = true; 

       else if (e.State == PackageState.Present) 
        UninstallEnabled = true; 
      } 
     } 

     /// <summary> 
     /// Method that gets invoked when the Bootstrapper PlanComplete event is fired. 
     /// If the planning was successful, it instructs the Bootstrapper Engine to 
     /// install the packages. 
     /// </summary> 
     private void OnPlanComplete(object sender, PlanCompleteEventArgs e) 
     { 
      if (e.Status >= 0) 
       Bootstrapper.Engine.Apply(System.IntPtr.Zero); 
     } 


     #endregion //Methods 

     #region RelayCommands 

     private RelayCommand installCommand; 
     public RelayCommand InstallCommand 
     { 
      get 
      { 
       if (installCommand == null) 
        installCommand = new RelayCommand(() => InstallExecute(),() => InstallEnabled == true); 

       return installCommand; 
      } 
     } 

     private RelayCommand uninstallCommand; 
     public RelayCommand UninstallCommand 
     { 
      get 
      { 
       if (uninstallCommand == null) 
        uninstallCommand = new RelayCommand(() => UninstallExecute(),() => UninstallEnabled == true); 

       return uninstallCommand; 
      } 
     } 

     private RelayCommand exitCommand; 
     public RelayCommand ExitCommand 
     { 
      get 
      { 
       if (exitCommand == null) 
        exitCommand = new RelayCommand(() => ExitExecute()); 

       return exitCommand; 
      } 
     } 

     #endregion //RelayCommands 
    } 

Répondre

1
var bundleVersion = Bootstrapper.Engine.VersionVariables["WixBundleVersion"];