Ejemplo n.º 1
0
        static void GetAllDataFiles(string dataDirectory, FilePack filePack)
        {
            //Logger.Info(string.Format("Scanning directory [{0}]...", directory));
            var dataFiles = Directory.GetFiles(dataDirectory);

            foreach (var dataFile in dataFiles)
            {
                filePack.AddDataFile(dataFile);
            }
            foreach (string subDir in Directory.GetDirectories(dataDirectory))
            {
                GetAllDataFiles(subDir, filePack);
            }
        }
Ejemplo n.º 2
0
        static void GetScannableFilePacks(FileConfiguration fileConfig, string appDir, string probeDir,
                                          IEnumerable <AddinFilePack> addinFilePacks, ref FilePackResult filePackResult)
        {
            //Logger.Info(string.Format("Scanning directory [{0}]...", directory));
            if (!Path.IsPathRooted(probeDir)) //如果该探测路径是相对路径
            {
                probeDir = Path.Combine(appDir, probeDir);
            }

            if (!Directory.Exists(probeDir))
            {
                return;
            }

            //探测路径下的所有文件夹都被视为潜在的插件文件夹
            var addinDirectories = Directory.GetDirectories(probeDir);

            foreach (var addinDirectory in addinDirectories)
            {
                FilePack filePack      = null;
                var      addinFilePack = addinFilePacks != null?GetMatchingFilePack(addinDirectory, addinFilePacks) : null;

                foreach (var fileScanner in _fileScanners)
                {
                    filePack = fileScanner.GetFilePack(probeDir, addinDirectory, fileConfig.ManifestFile, addinFilePack);
                    if (filePack != null)
                    {
                        break;
                    }
                }
                if (filePack != null)
                {
                    filePackResult.AddAddinFilePack(filePack);
                }
            }
        }
Ejemplo n.º 3
0
 internal void AddAddinFilePack(FilePack addinFilePack)
 {
     _addinFilePacks = _addinFilePacks ?? new List <FilePack>();
     _addinFilePacks.Add(addinFilePack);
 }
Ejemplo n.º 4
0
        internal override FilePack GetFilePack(string probeDirectory, string addinDirectory, string manifestFile,
                                               AddinFilePack addinFilePack)
        {
            var addinDirectoryName = Path.GetFileName(addinDirectory);
            var filePack           = new FilePack {
                AddinDirectoryName = addinDirectoryName, AddinProbeDirectory = probeDirectory
            };

            //位于插件文件夹下面的文件都被视为潜在包含插件配置的清单文件或程序集文件
            //但最终这些文件到底是插件配置文件、程序集文件或数据文件,要看文件内容来决定
            var files = Directory.GetFiles(addinDirectory);

            if (addinFilePack != null)
            {
                var shouldRescan = false;
                foreach (var file in files)
                {
                    if (IsAssembly(file))
                    {
                        shouldRescan |= IsScannableAssemblyFile(file, addinFilePack);
                        filePack.AddAssemblyFile(file);
                    }
                    else if (filePack.ManifestFile == null && file.EndsWith(manifestFile, StringComparison.InvariantCultureIgnoreCase))
                    {
                        shouldRescan         |= IsScannableManifestFile(file, addinFilePack);
                        filePack.ManifestFile = file;
                    }
                    else
                    {
                        filePack.AddDataFile(file);
                    }
                }
                if (!shouldRescan)
                {
                    return(null);
                }
            }
            else
            {
                foreach (var file in files)
                {
                    if (IsAssembly(file))
                    {
                        filePack.AddAssemblyFile(file);
                    }
                    else if (filePack.ManifestFile == null && file.EndsWith(manifestFile, StringComparison.InvariantCultureIgnoreCase))
                    {
                        filePack.ManifestFile = file;
                    }
                    else
                    {
                        filePack.AddDataFile(file);
                    }
                }
            }

            //位于插件文件夹的子文件夹中的文件都被视为数据文件
            var dataDirectories = Directory.GetDirectories(addinDirectory);

            foreach (var dataDirectory in dataDirectories)
            {
                GetAllDataFiles(dataDirectory, filePack);
            }

            return(filePack.ManifestFile == null ? null : filePack);
        }