internal static ProductCatalog CreateProduct(ApplicationFiles applicationFiles) { var product = new ProductCatalog { Name = LauncherConstants.ProductName, Author = LauncherConstants.Author, ApplicationType = applicationFiles.Type, Dependencies = new List <Dependency> { CreateDependency(applicationFiles.Executable, applicationFiles.Type, true) } }; foreach (var file in applicationFiles.Files) { product.Dependencies.Add(CreateDependency(file, applicationFiles.Type)); } Logger.Debug($"Product created: {product}"); return(product); }
private static int Main(string[] args) { SetLogging(); Parser.Default.ParseArguments <LaunchOptions>(args).WithParsed(launchOptions => { if (string.IsNullOrEmpty(launchOptions.XmlOutput)) { launchOptions.XmlOutput = Directory.GetCurrentDirectory(); } if (string.IsNullOrEmpty(launchOptions.OriginPathRoot)) { launchOptions.OriginPathRoot = DefaultFileRootPath; } if (string.IsNullOrEmpty(launchOptions.SourceDirectory)) { launchOptions.SourceDirectory = Directory.GetCurrentDirectory(); } if (string.IsNullOrEmpty(launchOptions.XmlOutput)) { launchOptions.XmlOutput = Directory.GetCurrentDirectory(); } LaunchOptions = launchOptions; }); if (LaunchOptions is null) { Logger.Fatal("Failed parsing arguments."); return(-1); } try { var dir = new DirectoryInfo(LaunchOptions.SourceDirectory); var files = dir.GetFilesByExtensions(true, SupportedFileEndings); var applicationFileInfos = FileUtilities.GetApplicationFiles(files.ToList(), LaunchOptions.BuildType).ToList(); if (applicationFileInfos.Count != LauncherConstants.ApplicationFileNames.Length) { throw new InvalidOperationException("Unexpected number of applications files found."); } if (!Enum.TryParse <ApplicationType>(LaunchOptions.ApplicationType, true, out var applicationType)) { throw new InvalidOperationException( $"Could not parse '{LaunchOptions.ApplicationType}' into a real ApplicationType"); } var applicationFiles = new ApplicationFiles(applicationType); FillData(applicationFileInfos, applicationFiles); if (!applicationFiles.Validate()) { throw new InvalidOperationException("The file set was not valid"); } var product = CatalogUtilities.CreateProduct(applicationFiles); var catalog = CreateCatalogOrIntegrate(in product, out var actualNewDependencies); WriteXmlFile(catalog, LaunchOptions.XmlOutput); if (!string.IsNullOrEmpty(LaunchOptions.FilesCopyLocation)) { product = catalog.FindMatchingCatalog(product.Name, product.ApplicationType); var filesToCopy = applicationFiles.AllFiles.Where(x => actualNewDependencies.Contains(x.Name)); CopyFiles(product, filesToCopy, LaunchOptions.FilesCopyLocation); } Logger.Info("Operation succeeded successfully!"); } catch (Exception e) { Logger.Fatal(e, $"The tool failed with an error: {e.Message}"); Console.ReadKey(); return(e.HResult); } return(0); }