Exemplo n.º 1
0
        public async Task InstallPlugin(PluginEntry plugin, IProgress <AsyncProgressEntry> progress = null,
                                        CancellationToken cancellation = default(CancellationToken))
        {
            var destination = GetPluginDirectory(plugin.Id);

            try {
                plugin.IsInstalling = true;

                var data = await CmApiProvider.GetDataAsync($"plugins/get/{plugin.Id}", progress, cancellation);

                if (data == null || cancellation.IsCancellationRequested)
                {
                    return;
                }

                await Task.Run(() => {
                    if (Directory.Exists(destination))
                    {
                        FileUtils.Recycle(destination);
                    }

                    using (var stream = new MemoryStream(data, false))
                        using (var archive = new ZipArchive(stream)) {
                            archive.ExtractToDirectory(destination);
                        }
                }, cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return;
                }

                plugin.InstalledVersion = plugin.Version;
                File.WriteAllText(Path.Combine(destination, ManifestFileName), JsonConvert.SerializeObject(plugin));

                if (plugin.IsEnabled)
                {
                    PluginEnabled?.Invoke(this, new PluginEventArgs {
                        PluginId = plugin.Id
                    });
                }
            } catch (Exception e) when(e.IsCancelled())
            {
            } catch (Exception e) {
                NonfatalError.Notify(ToolsStrings.Plugins_CannotInstall, e);
            } finally {
                plugin.IsInstalling = false;
            }
        }
Exemplo n.º 2
0
 internal void OnPluginEnabled(PluginEntry plugin, bool value)
 {
     (value ? PluginEnabled : PluginDisabled)?.Invoke(this, new AppAddonEventHandlerArgs {
         PluginId = plugin.Id
     });
 }
Exemplo n.º 3
0
 public void RemoveAddon(PluginEntry plugin)
 {
     throw new NotImplementedException();
 }