private static void FindPackagesToInstall(ExternalToolProperties readin, UnzipToolReturnAccumulator accumulator, ProgramPathContainer programPathContainer) { var packages = new List <ToolPackage>(); int i = 1; var package = readin.GetPackageWithVersion(i); while (package != null) { // if the package is not a uri, it is stored locally in the tool-inf directory //if (!package.StartsWith("http")) // package = Path.Combine(tempToolPath, TOOL_INF, package); packages.Add(package); package = readin.GetPackageWithVersion(++i); } if (!Settings.Default.ToolFilePaths.ContainsKey(programPathContainer) || packages.Count > 0) { accumulator.AddInstallation(programPathContainer, packages); } }
private static string ProcessCommand(ExternalToolProperties readin, string tempToolPath, UnzipToolReturnAccumulator accumulator) { string command = readin.Command.Trim(); var programPathContainer = ToolMacros.GetProgramPathContainer(command); if (!ToolDescription.IsWebPageCommand(command) && programPathContainer == null) { if (command.StartsWith(ToolMacros.TOOL_DIR + "\\")) // Not L10N { command = command.Substring(ToolMacros.TOOL_DIR.Length + 1); } if (!File.Exists(Path.Combine(tempToolPath, command))) { accumulator.AddMessage(string.Format(Resources.ToolInstaller_AddToolFromProperties_Missing_the_file__0___Tool__1__import_failed, command, readin.Title)); return(null); } command = Path.Combine(ToolMacros.TOOL_DIR, command); } else if (programPathContainer != null) // If it is a ProgramPath macro { FindPackagesToInstall(readin, accumulator, programPathContainer); } return(command); }
private static void AddToolFromProperties(FileInfo file, UnzipToolReturnAccumulator accumulator, ToolInfo toolInfo, string placeHolderToolPath, string tempToolPath, IDictionary <string, string> reportRenameMapping) { if (file.Name == INFO_PROPERTIES) { return; } ExternalToolProperties readin; try { readin = new ExternalToolProperties(file.FullName); } catch (Exception) { //Failed to read the .properties file accumulator.AddMessage(string.Format(Resources.ConfigureToolsDlg_unpackZipTool_Failed_to_process_file_0_The_tool_described_failed_to_import, file.Name)); return; } if (readin.Title == null || readin.Command == null) { accumulator.AddMessage(string.Format(TextUtil.LineSeparate( Resources.ConfigureToolsDlg_unpackZipTool_Invalid_Tool_Description_in_file__0__, Resources.ConfigureToolsDlg_unpackZipTool_Title_and_Command_are_required, Resources.ConfigureToolsDlg_unpackZipTool_skipping_that_tool_), file.Name)); return; } string command = ProcessCommand(readin, tempToolPath, accumulator); if (string.IsNullOrEmpty(command)) { return; } string reportTitle = readin.Input_Report_Name; List <AnnotationDef> annotations = new List <AnnotationDef>(); // Check we have the relevant report if (!string.IsNullOrWhiteSpace(reportTitle)) { if (reportRenameMapping.ContainsKey(reportTitle)) { //Apply report renaming if install in parallel was selectedd reportTitle = reportRenameMapping[reportTitle]; } // Check if they are still missing the report they want if (!ReportSharing.GetExistingReports().ContainsKey(PersistedViews.ExternalToolsGroup.Id.ViewName(reportTitle))) { accumulator.AddMessage(string.Format(Resources.UnpackZipToolHelper_UnpackZipTool_The_tool___0___requires_report_type_titled___1___and_it_is_not_provided__Import_canceled_, readin.Title, reportTitle)); return; } // Get annotations for this specific tool GetAnotations(readin, annotations); } //Check the ArgsCollector Dll exists. string dllPath = readin.Args_Collector_Dll; if (!string.IsNullOrEmpty(dllPath)) { // Handle case where they prepended the DllPath with $(ToolDir)\\. // ReSharper disable once LocalizableElement if (dllPath.StartsWith(ToolMacros.TOOL_DIR + "\\")) { dllPath = dllPath.Substring(ToolMacros.TOOL_DIR.Length + 1); } if (!File.Exists(Path.Combine(tempToolPath, dllPath))) { accumulator.AddMessage(string.Format(Resources.ToolInstaller_AddToolFromProperties_Missing_the_file__0___Tool__1__import_failed, dllPath, readin.Title)); return; } // Path to the dll gets renamed at the end of the UnpackZipTools Function when we // finally decide the directory for the $(ToolDir) } //Make sure tools get a unique title. string uniqueTitle = GetUniqueToolTitle(readin.Title); //Append each tool to the return value accumulator.AddTool(new ToolDescription(uniqueTitle, command, readin.Arguments, readin.Initial_Directory, readin.Output_to_Immediate_Window.Contains(@"True"), reportTitle, dllPath, readin.Args_Collector_Type, placeHolderToolPath, annotations, toolInfo.PackageVersion, toolInfo.PackageIdentifier, toolInfo.PackageName)); }
public IList<ToolStoreItem> GetToolStoreItems() { if (FailToConnect) throw new ToolExecutionException(FailToConnectMessage); if (ToolStoreItems != null) return ToolStoreItems; var tools = new List<ToolStoreItem>(); if (_toolDir == null) return tools; foreach (var toolDir in _toolDir.GetFiles()) { if (toolDir == null || toolDir.DirectoryName == null) continue; string fileName = Path.GetFileNameWithoutExtension(toolDir.Name); string path = Path.Combine(toolDir.DirectoryName, fileName); using (new TemporaryDirectory(path)) { using (var zipFile = new ZipFile(toolDir.FullName)) { // extract files zipFile.ExtractAll(path, ExtractExistingFileAction.OverwriteSilently); var toolInf = new DirectoryInfo(Path.Combine(path, ToolInstaller.TOOL_INF)); if (!Directory.Exists(toolInf.FullName)) continue; if (!toolInf.GetFiles(ToolInstaller.INFO_PROPERTIES).Any()) continue; var pictures = toolInf.GetFiles().Where(info => IMAGE_EXTENSIONS.Contains(info.Extension)).ToList(); Image toolImage = ToolStoreUtil.DefaultImage; if (pictures.Count != 0) { // try and read in the image try { using (var stream = new FileStream(pictures.First().FullName, FileMode.Open, FileAccess.Read)) { toolImage = Image.FromStream(stream); } } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { // if anything goes wrong -- just use the default image :) } } ExternalToolProperties readin; try { readin = new ExternalToolProperties(Path.Combine(toolInf.FullName, ToolInstaller.INFO_PROPERTIES)); } catch (Exception) { continue; } tools.Add(new ToolStoreItem(readin.Name, readin.Author, readin.Provider, readin.Version, readin.Description, readin.Identifier, toolImage, toolDir.FullName)); } } } // sort toollist by name tools.Sort(((item, storeItem) => String.Compare(item.Name, storeItem.Name, StringComparison.Ordinal))); return tools; }
private static string ProcessCommand(ExternalToolProperties readin, string tempToolPath, UnzipToolReturnAccumulator accumulator) { string command = readin.Command.Trim(); var programPathContainer = ToolMacros.GetProgramPathContainer(command); if (!ToolDescription.IsWebPageCommand(command) && programPathContainer == null) { if (command.StartsWith(ToolMacros.TOOL_DIR + "\\")) // Not L10N { command = command.Substring(ToolMacros.TOOL_DIR.Length + 1); } if (!File.Exists(Path.Combine(tempToolPath, command))) { accumulator.AddMessage(string.Format(Resources.ToolInstaller_AddToolFromProperties_Missing_the_file__0___Tool__1__import_failed, command, readin.Title)); return null; } command = Path.Combine(ToolMacros.TOOL_DIR, command); } else if (programPathContainer != null) // If it is a ProgramPath macro { FindPackagesToInstall(readin, accumulator, programPathContainer); } return command; }
private static ToolInfo GetToolInfo(DirectoryInfo toolInf, UnzipToolReturnAccumulator accumulator) { var toolInfo = new ToolInfo(); string infoFile = Path.Combine(toolInf.FullName, INFO_PROPERTIES); if (File.Exists(infoFile)) { ExternalToolProperties readin; try { readin = new ExternalToolProperties(infoFile); } catch (Exception) { // Failed to read the .properties file throw new ToolExecutionException(string.Format(Resources.ToolInstaller_GetToolInfo_Failed_to_process_the__0__file, INFO_PROPERTIES)); } toolInfo.SetPackageVersion(readin.Version); toolInfo.SetPackageIdentifier(readin.Identifier); toolInfo.SetPackageName(readin.Name); //Check for Package Installation specified in info.properties var ppc = ToolMacros.GetProgramPathContainer(readin.Command); if (ppc != null) { FindPackagesToInstall(readin, accumulator, ppc); } } else //No info.properties file in the tool-inf directory. { throw new ToolExecutionException(TextUtil.LineSeparate( Resources.ToolInstaller_UnpackZipTool_The_selected_zip_file_is_not_a_valid_installable_tool_, string.Format(Resources.ToolInstaller_GetToolInfo_Error__It_does_not_contain_the_required__0__in_the__1__directory_, INFO_PROPERTIES, TOOL_INF))); } return toolInfo; }
private static void GetAnotations(ExternalToolProperties readin, List<AnnotationDef> annotations) { for (int i = 1; ; i++) { string annotation = readin.GetAnnotation(i); if (string.IsNullOrEmpty(annotation)) break; annotations.Add(Settings.Default.AnnotationDefList[annotation]); } }
private static void FindPackagesToInstall(ExternalToolProperties readin, UnzipToolReturnAccumulator accumulator, ProgramPathContainer programPathContainer) { var packages = new List<ToolPackage>(); int i = 1; var package = readin.GetPackageWithVersion(i); while (package != null) { // if the package is not a uri, it is stored locally in the tool-inf directory //if (!package.StartsWith("http")) // Not L10N // package = Path.Combine(tempToolPath, TOOL_INF, package); packages.Add(package); package = readin.GetPackageWithVersion(++i); } if (!Settings.Default.ToolFilePaths.ContainsKey(programPathContainer) || packages.Count > 0) accumulator.AddInstallation(programPathContainer, packages); }
private static void AddToolFromProperties(FileInfo file, UnzipToolReturnAccumulator accumulator, ToolInfo toolInfo, string placeHolderToolPath, string tempToolPath, IDictionary<string, string> reportRenameMapping) { if (file.Name == INFO_PROPERTIES) return; ExternalToolProperties readin; try { readin = new ExternalToolProperties(file.FullName); } catch (Exception) { //Failed to read the .properties file accumulator.AddMessage(string.Format(Resources.ConfigureToolsDlg_unpackZipTool_Failed_to_process_file_0_The_tool_described_failed_to_import, file.Name)); return; } if (readin.Title == null || readin.Command == null) { accumulator.AddMessage(string.Format(TextUtil.LineSeparate( Resources.ConfigureToolsDlg_unpackZipTool_Invalid_Tool_Description_in_file__0__, Resources.ConfigureToolsDlg_unpackZipTool_Title_and_Command_are_required, Resources.ConfigureToolsDlg_unpackZipTool_skipping_that_tool_), file.Name)); return; } string command = ProcessCommand(readin, tempToolPath, accumulator); if (string.IsNullOrEmpty(command)) return; string reportTitle = readin.Input_Report_Name; List<AnnotationDef> annotations = new List<AnnotationDef>(); // Check we have the relevant report if (!string.IsNullOrWhiteSpace(reportTitle)) { if (reportRenameMapping.ContainsKey(reportTitle)) { //Apply report renaming if install in parallel was selectedd reportTitle = reportRenameMapping[reportTitle]; } // Check if they are still missing the report they want if (!ReportSharing.GetExistingReports().ContainsKey(PersistedViews.ExternalToolsGroup.Id.ViewName(reportTitle))) { accumulator.AddMessage(string.Format(Resources.UnpackZipToolHelper_UnpackZipTool_The_tool___0___requires_report_type_titled___1___and_it_is_not_provided__Import_canceled_, readin.Title, reportTitle)); return; } // Get annotations for this specific tool GetAnotations(readin, annotations); } //Check the ArgsCollector Dll exists. string dllPath = readin.Args_Collector_Dll; if (!string.IsNullOrEmpty(dllPath)) { // Handle case where they prepended the DllPath with $(ToolDir)\\. if (dllPath.StartsWith(ToolMacros.TOOL_DIR + "\\")) // Not L10N { dllPath = dllPath.Substring(ToolMacros.TOOL_DIR.Length + 1); } if (!File.Exists(Path.Combine(tempToolPath, dllPath))) { accumulator.AddMessage(string.Format(Resources.ToolInstaller_AddToolFromProperties_Missing_the_file__0___Tool__1__import_failed, dllPath, readin.Title)); return; } // Path to the dll gets renamed at the end of the UnpackZipTools Function when we // finally decide the directory for the $(ToolDir) } //Make sure tools get a unique title. string uniqueTitle = GetUniqueToolTitle(readin.Title); //Append each tool to the return value accumulator.AddTool(new ToolDescription(uniqueTitle, command, readin.Arguments, readin.Initial_Directory, readin.Output_to_Immediate_Window.Contains("True"), // Not L10N reportTitle, dllPath, readin.Args_Collector_Type, placeHolderToolPath, annotations, toolInfo.PackageVersion, toolInfo.PackageIdentifier, toolInfo.PackageName)); }