Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include <atomic>
26 :
27 : #include "global/modularity/ioc.h"
28 : #include "global/iprocess.h"
29 : #include "global/iglobalconfiguration.h"
30 : #include "global/io/ifilesystem.h"
31 : #include "interactive/iinteractive.h"
32 : #include "global/async/asyncable.h"
33 :
34 : #include "../iregisteraudiopluginsscenario.h"
35 : #include "../iknownaudiopluginsregister.h"
36 : #include "../iaudiopluginsscannerregister.h"
37 : #include "../iaudiopluginmetareaderregister.h"
38 : #include "../iaudiopluginsloadguard.h"
39 :
40 : namespace muse::audioplugins {
41 : class RegisterAudioPluginsScenario : public IRegisterAudioPluginsScenario, public Contextable, public async::Asyncable
42 : {
43 : public:
44 : GlobalInject<IGlobalConfiguration> globalConfiguration;
45 : GlobalInject<IProcess> process;
46 : GlobalInject<io::IFileSystem> fileSystem;
47 : GlobalInject<IKnownAudioPluginsRegister> knownPluginsRegister;
48 : GlobalInject<IAudioPluginsScannerRegister> scannerRegister;
49 : GlobalInject<IAudioPluginMetaReaderRegister> metaReaderRegister;
50 : GlobalInject<IAudioPluginsLoadGuard> loadGuard;
51 : ContextInject<IInteractive> interactive = { this };
52 :
53 : public:
54 18 : RegisterAudioPluginsScenario(const modularity::ContextPtr& iocCtx)
55 18 : : Contextable(iocCtx) {}
56 :
57 : void init();
58 :
59 : Ret markCrashedPluginsAsBroken();
60 :
61 : PluginScanResult scanPlugins(Progress* progress = nullptr) const override;
62 :
63 : Ret updatePluginsRegistry() override;
64 : Ret rescanAllPlugins() override;
65 :
66 : Ret registerNewPlugins(const io::paths_t& pluginPaths, bool validate) override;
67 : Ret unregisterRemovedPlugins(const PluginResourceIdList& pluginIds) override;
68 :
69 : Ret registerPlugin(const io::path_t& pluginPath) override;
70 : Ret validatePlugin(const io::path_t& pluginPath, const io::path_t& outputFile) override;
71 :
72 : private:
73 : Ret persistDiscoveredPlaceholders(const io::paths_t& pluginPaths);
74 : void processPluginsRegistration(const io::paths_t& pluginPaths);
75 : AudioPluginInfoList scanResult(const io::path_t& pluginPath, const io::path_t& resultFile, int code) const;
76 : RetVal<AudioPluginInfoList> validatePluginInfo(const io::path_t& pluginPath) const;
77 : AudioPluginInfo makeFailedPluginInfo(const io::path_t& pluginPath, int failCode) const;
78 : io::path_t scanResultFilePath(int64_t index) const;
79 : IAudioPluginMetaReaderPtr metaReader(const io::path_t& pluginPath) const;
80 : PluginType metaType(const io::path_t& pluginPath) const;
81 :
82 : Progress m_progress;
83 : std::atomic_bool m_aborted = false;
84 : };
85 : }
|