Beispiel #1
0
        public async Task <bool> InstallLatestVersionOfLibraryAsync(LibraryListItem libraryListItem)
        {
            if (IsLibraryInstalled(libraryListItem.Library))
            {
                return(true);
            }

            libraryListItem.ButtonText = "Installing";
            await LoadSourcesAsync();

            if (!TryGetLibraryWithNameAndVersion(libraryListItem.Library, out var library))
            {
                return(false);
            }

            var absPath = _directoryService.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            CreateTemporaryDirectory(absPath);

            var zipPath     = "tmp/" + library + ".zip";
            var extractPath = "tmp/" + library;
            var toPath      = PluginsDirectory + library;

            await _webResourceFetcher.DownloadFileAsync(library.DownloadPath, zipPath);

            ExtractDllFromZip(zipPath, extractPath, toPath);
            library.PathOnDisk = toPath;
            _pluginLoader.AddPluginFromDirectory(absPath + "/" + toPath, library);
            UpdateInstalledLibraries();
            InstalledLibraryItems.Add(new LibraryListItem(library, library.Name)
            {
                ButtonText = "Uninstall"
            });
            libraryListItem.ButtonText = "Installed";
            return(true);
        }