private void RescanIfRequired()
        {
            if (Manifest == null)
            {
                Manifest   = ManifestLoader.LoadDefaultManifest();
                PluginsExt = ManifestLoader.LoadPlugins(Manifest);
            }

            directoryCatalog.Refresh();

            var loadedFiles   = directoryCatalog.LoadedFiles;
            var scannedFiles  = Manifest?.ScannedAssemblies ?? Array.Empty <AssemblyInfo>();
            var isRequireScan = loadedFiles.Count != scannedFiles.Length;

            if (!isRequireScan)
            {
                for (var i = 0; i < loadedFiles.Count; i++)
                {
                    var loadedFileName = loadedFiles[i].ToLower();
                    var scannedFile    = scannedFiles[i];

                    var loadedVersion  = AssemblyName.GetAssemblyName(loadedFileName).Version.ToString();
                    var scannedVersion = scannedFile.Version;

                    if (loadedFileName != scannedFile.Name.ToLower() || loadedVersion != scannedVersion)
                    {
                        isRequireScan = true;
                        break;
                    }
                }
            }

            if (isRequireScan)
            {
                LoadParts();
            }

            if (Plugins == null)
            {
                Plugins = ManifestLoader.LoadPlugins <IPluginMetadata>(Manifest);
            }
        }
Exemple #2
0
        private void AnalyzePackage(XtbPlugin plugin)
        {
            var files = plugin.Files;

            bool install = false, update = false, otherFilesFound = false;

            if (string.IsNullOrEmpty(plugin.MinimalXrmToolBoxVersion))
            {
                plugin.Compatibilty = CompatibleState.Other;
            }
            else
            {
                plugin.Compatibilty = IsPluginDependencyCompatible(new Version(plugin.MinimalXrmToolBoxVersion));
            }

            var currentVersion      = new Version(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue);
            var currentVersionFound = false;

            var manifest = ManifestLoader.LoadDefaultManifest();

            foreach (var file in files)
            {
                if (Path.GetFileName(file).Length == 0)
                {
                    continue;
                }

                var directoryName = Path.GetDirectoryName(file);
                if (directoryName == null)
                {
                    continue;
                }

                if (directoryName.ToLower().EndsWith("plugins"))
                {
                    // Only check version of files in the Plugins folder
                    var existingPluginFile =
                        plugins.FirstOrDefault(p => file.ToLower().EndsWith(p.Name.ToLower()));
                    if (existingPluginFile == null)
                    {
                        install = true;
                    }
                    else
                    {
                        var pluginInfo = manifest.PluginMetadata
                                         .FirstOrDefault(p => p.AssemblyFilename.ToLower() == existingPluginFile.FullName.ToLower());

                        // If a file is found, we check version only if the file
                        // contains classes that implement IXrmToolBoxPlugin
                        if (pluginInfo == null)
                        {
                            otherFilesFound = true;
                            continue;
                        }

                        var existingFileVersion = new Version(pluginInfo.Version);

                        if (existingFileVersion < currentVersion)
                        {
                            currentVersion      = existingFileVersion;
                            currentVersionFound = true;
                        }

                        if (existingFileVersion < new Version(plugin.Version))
                        {
                            update = true;
                        }
                    }
                }
            }

            if (currentVersionFound)
            {
                plugin.CurrentVersion = currentVersion;
            }

            if (otherFilesFound || update)
            {
                plugin.RequiresXtbRestart = true;
            }

            if (plugin.Compatibilty != CompatibleState.Compatible)
            {
                plugin.Action = PackageInstallAction.Unavailable;
            }
            else if (update)
            {
                plugin.Action = PackageInstallAction.Update;
            }
            else if (install)
            {
                plugin.Action = PackageInstallAction.Install;
            }
            else
            {
                plugin.Action = PackageInstallAction.None;
            }
        }