Example #1
0
        public Disk(Folder root, PluginRepo repo, FileManagerWithHistory manager)
        {
            InitializeComponent();

            Repo    = repo;
            Manager = manager;
            Tree    = new FileTree(root);

            FileTree.ItemsSource = new [] { Tree.Root };
            PutFilesOnPanel(root.EnumerateFiles());
        }
Example #2
0
        /// <summary>Gets all installed versions of package <paramref name="packageId" />, if any.</summary>
        /// <param name="packageId">The package identifier.</param>
        /// <param name="verify">
        ///   Whether to verify if each version, and its dependencies, are correctly
        ///   installed.
        /// </param>
        public IEnumerable <NuGetVersion> FindInstalledPluginVersions(string packageId,
                                                                      bool verify = false)
        {
            var pkgs = PluginRepo.FindPackageById(packageId);

            if (verify)
            {
                pkgs = pkgs.Where(p => PluginRepo.IsPluginInstalled(p.Identity, Solution));
            }

            return(pkgs.Select(p => p.Identity.Version));
        }
Example #3
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            var repo = new PluginRepo(new [] {
                typeof(IFileOpener),
                typeof(IFileIcon),
                typeof(IMenuItem)
            });

            var pluginFiles = GetPluginFiles();

            repo.RegisterPlugins(pluginFiles.Select(Assembly.LoadFile));
            var w = new MainWindow(repo);

            w.Show();
        }
        public MainWindow(PluginRepo repo)
        {
            InitializeComponent();

            Repo = repo;

            var folders = WinFolder.GetRootFolders().ToArray();
            var disks   = folders
                          .Select(folder => new Disk(folder, repo, new WinFileManager(folder))
            {
                Header = folder.Path.GetFileName()
            });

            foreach (var disk in disks)
            {
                DiskTabs.Items.Add(disk);
            }

            Active              = (Disk)DiskTabs.Items[0];
            Active.PathChanged += SetPathText;
            SetPathText(folders[0].Path);
            DiskTabs.SelectionChanged += ChangeActiveManager;
            DiskTabs.SelectedIndex     = 0;
        }
Example #5
0
        private async Task EditConfig()
        {
            if (selectedConfig == null)
            {
                await ShowNoConfigSelectedMessage();

                return;
            }

            if (selectedConfig.IsRemote)
            {
                await js.AlertError(Loc["RemoteConfig"], Loc["CannotEditRemoteConfig"]);

                return;
            }

            // Check if we have all required plugins
            var loadedPlugins = PluginRepo.GetPlugins();

            if (selectedConfig.Metadata.Plugins != null)
            {
                foreach (var plugin in selectedConfig.Metadata.Plugins)
                {
                    if (!loadedPlugins.Any(p => p.FullName == plugin))
                    {
                        await js.AlertWarning(Loc["MissingPlugin"], $"{Loc["MissingPluginText"]}: {plugin}");
                    }
                }
            }

            // Check if the previous config was saved
            if (ConfigService.SelectedConfig != null && ConfigService.SelectedConfig != selectedConfig && ConfigService.SelectedConfig.HasUnsavedChanges())
            {
                if (!await js.Confirm(Loc["UnsavedChanges"], Loc["UnsavedChangesText"], Loc["Cancel"]))
                {
                    return;
                }
            }

            ConfigService.SelectedConfig = selectedConfig;

            var section = PersistentSettings.OpenBulletSettings.GeneralSettings.ConfigSectionOnLoad;
            var uri     = string.Empty;

            if (selectedConfig.Mode == ConfigMode.DLL)
            {
                uri = "config/edit/metadata";
            }
            else
            {
                uri = section switch
                {
                    ConfigSection.Metadata => "config/edit/metadata",
                    ConfigSection.Readme => "config/edit/readme",
                    ConfigSection.Stacker => selectedConfig.Mode == ConfigMode.CSharp ? "config/edit/code" : "config/edit/stacker",
                    ConfigSection.LoliCode => selectedConfig.Mode == ConfigMode.CSharp ? "config/edit/code" : "config/edit/lolicode",
                    ConfigSection.Settings => "config/edit/settings",
                    ConfigSection.CSharpCode => "config/edit/code",
                    _ => throw new NotImplementedException()
                };
            }

            VolatileSettings.DebuggerLog = new();
            Nav.NavigateTo(uri);
        }
Example #6
0
        /// <summary>
        ///   Installs the latest version of package <paramref name="packageId" /> that matches
        ///   <paramref name="versionRange" />. Package data, and <paramref name="metadata" /> will be
        ///   saved to the package json configuration file. If plugin already exists try to update its
        ///   version.
        /// </summary>
        /// <param name="packageId">The package name</param>
        /// <param name="metadata">Optional metadata to associate</param>
        /// <param name="versionRange">The version constraint</param>
        /// <param name="allowPrereleaseVersions">
        ///   Whether to include pre-release version in the search
        ///   results
        /// </param>
        /// <param name="framework">Which .NET framework should the package be compatible with</param>
        /// <param name="cancellationToken"></param>
        /// <returns>Success of operation</returns>
        /// <exception cref="ArgumentException"><paramref name="packageId" /> contains only white spaces</exception>
        public async Task <bool> InstallAsync(
            string packageId,
            TMeta metadata                      = default,
            VersionRange versionRange           = null,
            bool allowPrereleaseVersions        = false,
            NuGetFramework framework            = null,
            CancellationToken cancellationToken = default)
        {
            if (packageId == null)
            {
                throw new ArgumentNullException(nameof(packageId));
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentException($"{nameof(packageId)} contains only white spaces");
            }

            try
            {
                var version = (await SearchMatchingVersion(packageId, versionRange, framework, cancellationToken).ConfigureAwait(false)).Max();

                if (version == null)
                {
                    return(false);
                }

                LogTo.Trace($"Install requested for plugin {packageId} {version.ToNormalizedString()}");

                // Check if this package was already installed in a previous run
                PackageIdentity packageIdentity = new PackageIdentity(packageId, version);

                // If plugin exact version already exists, abort
                if (PluginRepo.IsPluginInstalled(packageIdentity, Solution))
                {
                    LogTo.Information($"Plugin {packageId} is already installed with version {version.ToNormalizedString()}");

                    return(true);
                }

                // If plugin already exists in a different version, try to update it
                if (PluginRepo.FindPluginById(packageId) != null)
                {
                    LogTo.Information("Plugin already exist with a different version. Redirecting to UpdateAsync.");

                    return(await UpdateAsync());
                }

                // If plugin doesn't exist, go ahead and install it
                return(await Solution.InstallPluginAsync(
                           packageIdentity,
                           metadata,
                           allowPrereleaseVersions,
                           cancellationToken));
            }
            catch (InvalidOperationException ex1) when(ex1.InnerException is OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                LogTo.Error(
                    $"Unexpected exception while installing packages: {(ex is AggregateException aggEx ? string.Join("; ", aggEx.InnerExceptions.Select(x => x.Message)) : ex.Message)}");

                throw;
            }
        }
Example #7
0
 public LocalPluginPackage <TMeta> FindInstalledPluginById(string packageId) => PluginRepo.FindPluginById(packageId);
Example #8
0
 /// <summary>Saves the local plugin repository state to file</summary>
 /// <returns>Success of operation</returns>
 public Task <bool> SaveConfigAsync()
 {
     return(PluginRepo.SaveAsync());
 }