public AdvancedViewModel() { var source = new SourceInstallation(); Installations.Add(new InstallationDetailsViewModel(source, new UserInstallation())); Installations.Add(new InstallationDetailsViewModel(source, new SystemInstallation())); Installations.Add(new InstallationDetailsViewModel(source, new CustomInstallation())); }
public InstallationDetailsViewModel(SourceInstallation source, Installation target) { Source = source; Target = target; InstallCommand = new RelayCommand(() => { try { Installer ins = new Installer(Source, Target); if (MessageBox.Show($"Install in {ins.TargetPath}?", "Confirm install", MessageBoxButton.YesNo, MessageBoxImage.None, MessageBoxResult.No) == MessageBoxResult.Yes) { ins.Install(); } TargetVersion = ""; // hacky way to refresh property } catch (Exception ex) { if (MessageBox.Show("An exception occurred: " + ex.Message + "\r\n\r\nWould you like to report this error to the developer?", "Error", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Helpers.ErrorReporter.LaunchReporter(ex); } } }); RemoveCommand = new RelayCommand(() => { try { Installer ins = new Installer(Source, Target); if (MessageBox.Show($"Remove all files in {ins.TargetPath}?", "Confirm removal", MessageBoxButton.YesNo, MessageBoxImage.None, MessageBoxResult.No) == MessageBoxResult.Yes) { ins.Remove(); } TargetVersion = ""; // hacky way to refresh property } catch (Exception ex) { if (MessageBox.Show("An exception occurred: " + ex.Message + "\r\n\r\nWould you like to report this error to the developer?", "Error", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Helpers.ErrorReporter.LaunchReporter(ex); } } }, () => { return(Target.Installed); }); }