Beispiel #1
0
 private void ScanSourcesForTemplatesAndLangPacks(IReadOnlyList <MountPointScanSource> sourceList, ScanResult scanResult)
 {
     // only scan for templates & langpacks if no components were found.
     foreach (MountPointScanSource source in sourceList.Where(x => !x.AnythingFound))
     {
         ScanMountPointForTemplatesAndLangpacks(source, scanResult);
     }
 }
Beispiel #2
0
        private void ScanMountPointForTemplatesAndLangpacks(MountPointScanSource source, ScanResult scanResult)
        {
            bool        isCopiedIntoPackagesDirectory;
            string      actualScanPath;
            IMountPoint scanMountPoint = null;

            if (!source.ShouldStayInOriginalLocation)
            {
                if (!TryCopyForNonFileSystemBasedMountPoints(source.MountPoint, source.Location, _paths.User.Packages, false, out actualScanPath))
                {
                    return;
                }

                // Try get an existing mount point for the scan location
                if (!_environmentSettings.SettingsLoader.TryGetMountPointFromPlace(actualScanPath, out scanMountPoint))
                {
                    // The mount point didn't exist, try creating a new one
                    foreach (IMountPointFactory factory in _environmentSettings.SettingsLoader.Components.OfType <IMountPointFactory>())
                    {
                        if (factory.TryMount(_environmentSettings, null, actualScanPath, out scanMountPoint))
                        {
                            break;
                        }
                    }
                }

                if (scanMountPoint == null)
                {
                    _environmentSettings.Host.FileSystem.FileDelete(actualScanPath);
                    return;
                }

                isCopiedIntoPackagesDirectory = true;
            }
            else
            {
                actualScanPath = source.Location;
                scanMountPoint = source.MountPoint;
                isCopiedIntoPackagesDirectory = false;
            }

            // look for things to install
            foreach (IGenerator generator in _environmentSettings.SettingsLoader.Components.OfType <IGenerator>())
            {
                IList <ITemplate> templateList = generator.GetTemplatesAndLangpacksFromDir(scanMountPoint, out IList <ILocalizationLocator> localizationInfo);

                foreach (ILocalizationLocator locator in localizationInfo)
                {
                    scanResult.AddLocalization(locator);
                }

                foreach (ITemplate template in templateList)
                {
                    scanResult.AddTemplate(template);
                }

                source.FoundTemplates |= templateList.Count > 0 || localizationInfo.Count > 0;
            }

            // finalize the result
            if (source.FoundTemplates)
            {
                // add the MP
                _environmentSettings.SettingsLoader.AddMountPoint(scanMountPoint);
                // add the MP to the scan result
                scanResult.AddInstalledMountPointId(scanMountPoint.Info.MountPointId);
            }
            else
            {
                // delete the copy
                if (!source.FoundTemplates && isCopiedIntoPackagesDirectory)
                {
                    try
                    {
                        // The source was copied to packages and then scanned for templates.
                        // Nothing was found, and this is a copy that now has no use, so delete it.
                        _environmentSettings.SettingsLoader.ReleaseMountPoint(scanMountPoint);

                        // It's always copied as an archive, so it's a file delete, not a directory delete
                        _environmentSettings.Host.FileSystem.FileDelete(actualScanPath);
                    }
                    catch (Exception ex)
                    {
                        _environmentSettings.Host.LogDiagnosticMessage($"During ScanMountPointForTemplatesAndLangpacks() cleanup, couldn't delete source copied into the packages dir: {actualScanPath}", "Install");
                        _environmentSettings.Host.LogDiagnosticMessage($"\tError: {ex.Message}", "Install");
                    }
                }
            }
        }
        private void ScanMountPointForTemplatesAndLangpacks(MountPointScanSource source, ScanResult scanResult)
        {
            _ = source ?? throw new ArgumentNullException(nameof(source));
            // look for things to install
            foreach (IGenerator generator in _environmentSettings.SettingsLoader.Components.OfType <IGenerator>())
            {
                IList <ITemplate> templateList = generator.GetTemplatesAndLangpacksFromDir(source.MountPoint, out IList <ILocalizationLocator> localizationInfo);

                foreach (ILocalizationLocator locator in localizationInfo)
                {
                    scanResult.AddLocalization(locator);
                }

                foreach (ITemplate template in templateList)
                {
                    scanResult.AddTemplate(template);
                }

                source.FoundTemplates |= templateList.Count > 0 || localizationInfo.Count > 0;
            }
        }