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); 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); }
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); }