示例#1
0
        protected override async Task ExecuteAsync(object parameter)
        {
            var pluginPresets = from item in _globalFrontendService.PresetExportList
                                group item by item.Plugin
                                into pluginGroup
                                let first = pluginGroup.First()
                                            select new
            {
                first.Plugin,
                Presets = pluginGroup.Select(gi => new { Preset = gi })
            };

            int totalPresets  = _globalFrontendService.PresetExportList.Count;
            int currentPreset = 0;

            _applicationService.StartApplicationOperation(this, "Exporting Presets",
                                                          totalPresets);
            var progress = _applicationService.GetApplicationProgress();

            await TaskHelper.Run(async() =>
            {
                var exportDirectory = _globalService.RuntimeConfiguration
                                      .NativeInstrumentsUserContentDirectory;

                if (!Directory.Exists(exportDirectory))
                {
                    LogTo.Warning($"Directory {exportDirectory} does not exist, using the default");
                }

                foreach (var pluginPreset in pluginPresets)
                {
                    Preset lastPreset = null;
                    try
                    {
                        await _presetDataPersisterService.OpenDatabase();

                        if (pluginPreset.Plugin.PresetParser == null)
                        {
                            _applicationService.AddApplicationOperationError(
                                $"Unable to update export presets for {pluginPreset.Plugin.PluginName} because it has no Preset Parser. Try to force-reload metadata for this plugin.");
                            continue;
                        }


                        using (var remotePluginInstance =
                                   _remoteVstService.GetRemotePluginInstance(pluginPreset.Plugin, false))
                        {
                            foreach (var preset in pluginPreset.Presets)
                            {
                                lastPreset = preset.Preset;
                                currentPreset++;
                                _applicationService.UpdateApplicationOperationStatus(
                                    currentPreset,
                                    $"Exporting {pluginPreset.Plugin.PluginName} - {preset.Preset.Metadata.PresetName}");

                                if (progress.CancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                var presetData = await _presetDataPersisterService.GetPresetData(preset.Preset);

                                if (preset.Preset.PresetBank == null)
                                {
                                    preset.Preset.PresetBank = preset.Preset.Plugin.RootBank;
                                    LogTo.Warning(
                                        $"Preset {preset.Preset.Metadata.PresetName} has no preset bank, using none.");
                                }

                                var presetExportInfo = new PresetExportInfo(preset.Preset)
                                {
                                    FolderMode           = _globalService.RuntimeConfiguration.FolderExportMode,
                                    OverwriteMode        = _globalService.RuntimeConfiguration.FileOverwriteMode,
                                    UserContentDirectory = exportDirectory
                                };

                                if (!presetExportInfo.CanExport())
                                {
                                    _applicationService.AddApplicationOperationError(
                                        $"Cannot export {preset.Preset.Plugin} -{preset.Preset.Metadata.PresetName}. " +
                                        $"Reason: {presetExportInfo.CannotExportReason}");
                                    continue;
                                }

                                pluginPreset.Plugin.PresetParser.PluginInstance = remotePluginInstance;

                                if (_globalService.RuntimeConfiguration.ExportWithAudioPreviews &&
                                    pluginPreset.Plugin.PluginType == Plugin.PluginTypes.Instrument)
                                {
                                    await remotePluginInstance.LoadPlugin().ConfigureAwait(false);
                                    pluginPreset.Plugin.PresetParser.OnPluginLoad();
                                    remotePluginInstance.SetChunk(presetData, false);

                                    remotePluginInstance.ExportNksAudioPreview(presetExportInfo, presetData,
                                                                               preset.Preset.Plugin.GetAudioPreviewDelay());
                                }

                                remotePluginInstance.ExportNks(presetExportInfo, presetData);


                                pluginPreset.Plugin.PresetParser.OnAfterPresetExport();
                                preset.Preset.LastExported = DateTime.Now;
                                preset.Preset.UpdateLastExportedMetadata();
                            }

                            if (remotePluginInstance.IsLoaded)
                            {
                                pluginPreset.Plugin.PresetParser.OnPluginUnload();
                            }

                            remotePluginInstance.UnloadPlugin();
                        }
                    }
                    catch (Exception e)
                    {
                        var errorMessage =
                            $"Unable to export presets for {pluginPreset.Plugin.PluginName} because of {e.GetType().FullName}: {e.Message}. ";

                        if (lastPreset != null)
                        {
                            errorMessage +=
                                $"The preset causing the error was: {lastPreset.Metadata.PresetName} in bank path {lastPreset.Metadata.BankPath}";
                        }

                        _applicationService.AddApplicationOperationError(
                            errorMessage
                            );
                        LogTo.Debug(e.StackTrace);
                    }

                    await _presetDataPersisterService.CloseDatabase();

                    _dataPersisterService.SavePresetsForPlugin(pluginPreset.Plugin);
                }
            });

            _applicationService.StopApplicationOperation("Export completed");
        }
示例#2
0
        protected override async Task ExecuteThreaded(object parameter)
        {
            var pluginsToScan = GetPluginsToScan();


            var pluginsToUpdateMetadata =
                (from p in GlobalService.Plugins
                 where p.RequiresMetadataScan
                 orderby p.PluginName, p.DllFilename
                 select p).ToList();

            _applicationService.StartApplicationOperation(this, "Analyzing VST plugins: Loading missing metadata",
                                                          pluginsToUpdateMetadata.Count);

            var pluginsToRemove = new List <Plugin>();
            var mergedPlugins   = new List <(Plugin oldPlugin, Plugin mergedIntoPlugin)>();
            var progress        = _applicationService.GetApplicationProgress();

            // First pass: Load missing metadata
            try
            {
                var result = await TaskHelper.Run(
                    async() => await _pluginService.UpdateMetadata(pluginsToUpdateMetadata, progress), true,
                    progress.CancellationToken);

                pluginsToRemove = result.removedPlugins;
                mergedPlugins   = result.mergedPlugins;

                await _dispatcherService.InvokeAsync(() =>
                {
                    foreach (var plugin in pluginsToRemove)
                    {
                        GlobalService.Plugins.Remove(plugin);

                        if (pluginsToScan.Contains(plugin))
                        {
                            pluginsToScan.Remove(plugin);
                        }
                    }
                });
            }
            catch (Exception e)
            {
                _applicationService.AddApplicationOperationError(
                    $"Unable to update metadata because of {e.GetType().FullName}: {e.Message}");
                LogTo.Debug(e.StackTrace);
            }

            _applicationService.StopApplicationOperation("Analyzing VST plugins Metadata analysis complete.");

            if (mergedPlugins.Count > 0)
            {
                var sb = new StringBuilder();
                foreach (var merge in (from p in mergedPlugins orderby p.oldPlugin.LastKnownGoodDllPath select p))
                {
                    sb.AppendLine(
                        $"{merge.oldPlugin.LastKnownGoodDllPath} => {merge.mergedIntoPlugin.LastKnownGoodDllPath}");
                }


                var result = await _messageService.ShowAsync(
                    "Automatically merged different plugin DLLs to the same plugin. Affected plugin(s):" +
                    Environment.NewLine + Environment.NewLine +
                    sb + Environment.NewLine + Environment.NewLine +
                    "Would you like to abort the analysis now, so that you can review the settings for each affected plugin? (Highly recommended!)",
                    "Auto-merged Plugins", HelpLinks.SETTINGS_PLUGIN_DLL, MessageButton.YesNo, MessageImage.Question);

                if (result == MessageResult.Yes)
                {
                    // ReSharper disable once MethodSupportsCancellation
                    _dataPersisterService.Save();
                    _commandManager.ExecuteCommand(Commands.Application.CancelOperation);
                }
            }

            if (!progress.CancellationToken.IsCancellationRequested && !SkipPresetLoading)
            {
                _applicationService.StartApplicationOperation(this, "Analyzing VST plugins",
                                                              pluginsToScan.Count);
                progress = _applicationService.GetApplicationProgress();


                await TaskHelper.Run(
                    async() => await AnalyzePlugins(pluginsToScan.OrderBy(p => p.PluginName).ToList(),
                                                    progress.CancellationToken), true,
                    progress.CancellationToken);

                // ReSharper disable once MethodSupportsCancellation
                _dataPersisterService.Save();
            }


            if (progress.CancellationToken.IsCancellationRequested)
            {
                _applicationService.StopApplicationOperation("Plugin analysis cancelled.");
            }
            else
            {
                _applicationService.StopApplicationOperation("Plugin analysis completed.");
            }

            var unreportedPlugins =
                (from plugin in GlobalService.Plugins
                 where !plugin.IsReported && !plugin.DontReport && !plugin.IsSupported && plugin.HasMetadata &&
                 plugin.IsEnabled
                 select plugin).ToList();

            if (unreportedPlugins.Any())
            {
                var result = await _messageService.ShowCustomRememberMyChoiceDialogAsync(
                    "There are unsupported plugins which are not reported." +
                    Environment.NewLine +
                    "Would you like to report them, so we can implement support for them?",
                    "Report Unsupported Plugins", null, MessageButton.YesNo, MessageImage.Question,
                    "Don't ask again for the currently unreported plugins");


                if (result.result == MessageResult.Yes)
                {
                    _commandManager.ExecuteCommand(Commands.Plugin.ReportUnsupportedPlugins);
                }

                if (result.dontChecked)
                {
                    foreach (var plugin in unreportedPlugins)
                    {
                        plugin.DontReport = true;
                    }

                    _dataPersisterService.Save();
                }
            }
        }