public static Dictionary <string /*versionNumber*/, ToolPackageInfo> GetToolPackageInfo() { Dictionary <string, ToolPackageInfo> toolPackageDictionary = new Dictionary <string, ToolPackageInfo>(); try { ProgressWindow pWindow = new ProgressWindow(); pWindow.Show(); //pWindow.SetStatusLabel("Gathering information about installed components in 2013. . ."); //ToolPackageInfo toolPackage2013 = new ToolPackageInfo("2013"); //toolPackage2013.SetToolInfo(tools2013, pWindow); //toolPackageDictionary.Add("2013", toolPackage2013); //pWindow.SetStatusLabel("Gathering information about installed components in 2014. . ."); //ToolPackageInfo toolPackage2014 = new ToolPackageInfo("2014"); //toolPackage2014.SetToolInfo(tools2014, pWindow); //toolPackageDictionary.Add("2014", toolPackage2014); //pWindow.SetStatusLabel("Gathering information about installed components in 2015. . ."); //ToolPackageInfo toolPackage2015 = new ToolPackageInfo("2015"); //toolPackage2015.SetToolInfo(tools2015, pWindow); //toolPackageDictionary.Add("2015", toolPackage2015); //pWindow.SetStatusLabel("Gathering information about installed components in 2016. . ."); //ToolPackageInfo toolPackage2016 = new ToolPackageInfo("2016"); //toolPackage2016.SetToolInfo(tools2016, pWindow); //toolPackageDictionary.Add("2016", toolPackage2016); pWindow.SetStatusLabel("Gathering information about installed components in 2017. . ."); ToolPackageInfo toolPackage2017 = new ToolPackageInfo("2017"); toolPackage2017.SetToolInfo(tools2017, pWindow); toolPackageDictionary.Add("2017", toolPackage2017); pWindow.SetStatusLabel("Gathering information about installed components in 2018. . ."); ToolPackageInfo toolPackage2018 = new ToolPackageInfo("2018"); toolPackage2018.SetToolInfo(tools2018, pWindow); toolPackageDictionary.Add("2018", toolPackage2018); pWindow.SetStatusLabel("Gathering information about installed components in 2019. . ."); ToolPackageInfo toolPackage2019 = new ToolPackageInfo("2019"); toolPackage2019.SetToolInfo(tools2019, pWindow); toolPackageDictionary.Add("2019", toolPackage2019); pWindow.SetStatusLabel("Gathering information about installed components in 2020. . ."); ToolPackageInfo toolPackage2020 = new ToolPackageInfo("2020"); toolPackage2020.SetToolInfo(tools2020, pWindow); toolPackageDictionary.Add("2020", toolPackage2020); if (null != pWindow) { pWindow.Close(); } } catch (Exception ex) { MessageBox.Show("Failed to get the information of tool package.\n" + ex.Message, "Get Tool Package Info", MessageBoxButton.OK, MessageBoxImage.Warning); } return(toolPackageDictionary); }
private static bool CreateDefaultDirectories(ToolPackageInfo packageInfo) { bool created = false; try { string installDirectory = packageInfo.InstallDirectory; string addinDirectory = Path.Combine(installDirectory, "HOK-Addin.bundle"); string contentDirectory = Path.Combine(addinDirectory, "Contents_Beta"); string resourceDirectory = Path.Combine(contentDirectory, "Resources"); string x64Directory = Path.Combine(contentDirectory, "x64"); string x86Directory = Path.Combine(contentDirectory, "x86"); if (!Directory.Exists(addinDirectory)) { Directory.CreateDirectory(addinDirectory); } if (!Directory.Exists(contentDirectory)) { Directory.CreateDirectory(contentDirectory); } if (!Directory.Exists(resourceDirectory)) { Directory.CreateDirectory(resourceDirectory); } if (!Directory.Exists(x64Directory)) { Directory.CreateDirectory(x64Directory); } if (!Directory.Exists(x86Directory)) { Directory.CreateDirectory(x86Directory); } created = Directory.Exists(resourceDirectory); } catch (Exception ex) { MessageBox.Show("Failed to create default directories.\n" + ex.Message, "Create Directories", MessageBoxButton.OK, MessageBoxImage.Warning); } return(created); }
public static ToolPackageInfo UninstallTool(ToolPackageInfo packageInfo, out int removedTools) { ToolPackageInfo installedPackage = packageInfo; removedTools = 0; try { List <string> toolNames = installedPackage.ToolInfoDictionary.Keys.ToList(); foreach (string toolName in toolNames) { ToolInfo tInfo = installedPackage.ToolInfoDictionary[toolName]; if (tInfo.IsSelected) { bool removed = true; foreach (string path in tInfo.FilePaths) { string installPath = installedPackage.InstallDirectory + path; if (File.Exists(installPath)) { try { File.Delete(installPath); } catch { removed = false; } } } if (removed) { tInfo.InstallVersionInfo = null; tInfo.InstallVersionNumber = "Not Installed"; installedPackage.ToolInfoDictionary.Remove(toolName); installedPackage.ToolInfoDictionary.Add(toolName, tInfo); removedTools++; } } } } catch (Exception ex) { MessageBox.Show(packageInfo.TargetSoftware + " cannot be installed.\n" + ex.Message, "Install Tool", MessageBoxButton.OK, MessageBoxImage.Warning); } return(installedPackage); }
private void comboBoxTarget_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (comboBoxTarget.SelectedItem != null) { ToolPackageInfo selectedPackage = (ToolPackageInfo)comboBoxTarget.SelectedItem; List<ToolInfo> toolInfoList = selectedPackage.ToolInfoDictionary.Values.ToList(); toolInfoList = toolInfoList.OrderBy(t => t.ToolName).ToList(); dataGridTool.ItemsSource = null; dataGridTool.ItemsSource = toolInfoList; } } catch (Exception ex) { MessageBox.Show("Cannot display the list of tools.\n"+ex.Message, "Target Software Changed", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static ToolPackageInfo InstallTool(ToolPackageInfo packageInfo, out int installedTools) { ToolPackageInfo installedPackage = packageInfo; installedTools = 0; try { if (CreateDefaultDirectories(installedPackage)) { var selectedItems = from tool in installedPackage.ToolInfoDictionary.Values where tool.IsSelected select tool; if (selectedItems.Count() > 0) { List <ToolInfo> selectedTools = selectedItems.ToList(); var selectedFiles = from file in selectedItems select file.FilePaths; int numFiles = selectedFiles.Count(); ProgressWindow pWindow = new ProgressWindow(); pWindow.RefreshProgressBar(numFiles); pWindow.SetStatusLabel("Installing selected tools in " + installedPackage.TargetSoftware + " . . ."); pWindow.Show(); double progressValue = 0; foreach (ToolInfo tInfo in selectedTools) { bool copied = true; foreach (string path in tInfo.FilePaths) { string betaPath = installedPackage.BetaDirectory + path; string installPath = installedPackage.InstallDirectory + path; if (File.Exists(betaPath)) { try { File.Copy(betaPath, installPath, true); } catch { copied = false; } } progressValue++; pWindow.SetProgressBar(progressValue); } if (!string.IsNullOrEmpty(tInfo.ExePath)) { MessageBoxResult result = MessageBox.Show("The desktop version of " + tInfo.ToolName + " will be installed.\nPlease follow the on-screen instructions to complete the process.", "ClickOnce Installeation", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (result == MessageBoxResult.OK) { Process.Start(tInfo.ExePath); } } if (copied) { tInfo.InstallVersionInfo = tInfo.BetaVersionInfo; tInfo.InstallVersionNumber = tInfo.BetaVersionNumber; installedPackage.ToolInfoDictionary.Remove(tInfo.ToolName); installedPackage.ToolInfoDictionary.Add(tInfo.ToolName, tInfo); installedTools++; } } if (null != pWindow) { pWindow.Close(); } } } } catch (Exception ex) { MessageBox.Show(packageInfo.TargetSoftware + " cannot be installed.\n" + ex.Message, "Install Tool", MessageBoxButton.OK, MessageBoxImage.Warning); } return(installedPackage); }
private void buttonInstall_Click(object sender, RoutedEventArgs e) { try { int selectedIndex = comboBoxTarget.SelectedIndex; ToolPackageInfo toolPackage = (ToolPackageInfo)comboBoxTarget.SelectedItem; List<ToolInfo> toolInfoList = (List<ToolInfo>)dataGridTool.ItemsSource; bool selected = false; if (toolDictionary.ContainsKey(toolPackage.VersionNumber)) { foreach (ToolInfo info in toolInfoList) { if (info.IsSelected) { selected = true; } if (toolDictionary[toolPackage.VersionNumber].ToolInfoDictionary.ContainsKey(info.ToolName)) { toolDictionary[toolPackage.VersionNumber].ToolInfoDictionary.Remove(info.ToolName); toolDictionary[toolPackage.VersionNumber].ToolInfoDictionary.Add(info.ToolName, info); } } } if (selected) { if (CheckPrerequisite()) { toolPackage = toolDictionary[toolPackage.VersionNumber]; int installedTools = 0; toolPackage = ToolManager.InstallTool(toolPackage, out installedTools); if (installedTools > 0) { MessageBoxResult msgResult = MessageBox.Show(installedTools.ToString() + " tools were successfully installed.\nThe new Addins will be available when Revit is restarted.\nWould you like to exit the installer?", "Installation Complete", MessageBoxButton.YesNo, MessageBoxImage.Question); if (msgResult == MessageBoxResult.Yes) { this.Close(); } else { if (toolDictionary.ContainsKey(toolPackage.VersionNumber)) { toolDictionary.Remove(toolPackage.VersionNumber); toolDictionary.Add(toolPackage.VersionNumber, toolPackage); } //bind to combo box if (toolDictionary.Count > 0) { comboBoxTarget.ItemsSource = null; dataGridTool.ItemsSource = null; List<ToolPackageInfo> toolList = toolDictionary.Values.ToList(); toolList = toolList.OrderBy(t => t.TargetSoftware).ToList(); comboBoxTarget.ItemsSource = toolList; comboBoxTarget.DisplayMemberPath = "TargetSoftware"; comboBoxTarget.SelectedIndex = selectedIndex; } } } } } } catch (Exception ex) { MessageBox.Show("Failed to install selected tools.\n"+ex.Message, "Install Addins", MessageBoxButton.OK, MessageBoxImage.Warning); } }