Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
directory_manager.h
1// SPDX-FileCopyrightText: © 2019-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <utility>
7
8#include "utils/types.h"
9
10#include "juce_wrapper.h"
11
13{
14public:
114
123 virtual fs::path get_prefix () const = 0;
124
131 virtual fs::path get_user_dir (bool force_default) = 0;
132
139 virtual fs::path get_default_user_dir () = 0;
140
146 virtual fs::path get_dir (DirectoryType type);
147
148 virtual ~IDirectoryManager () = default;
149};
150
155class DirectoryManager : public IDirectoryManager
156{
157public:
158 using UserDirProvider = std::function<fs::path ()>;
159 using DefaultUserDirProvider = std::function<fs::path ()>;
160 using ApplicationDirPathProvider = std::function<fs::path ()>;
161
162public:
163 DirectoryManager (
164 UserDirProvider user_dir_provider,
165 DefaultUserDirProvider default_user_dir_provider,
166 ApplicationDirPathProvider application_dir_path_provider)
167 : user_dir_provider_ (std::move (user_dir_provider)),
168 default_user_dir_provider_ (std::move (default_user_dir_provider)),
169 application_dir_path_provider_ (std::move (application_dir_path_provider))
170 {
171 }
172 ~DirectoryManager () override = default;
173
174 fs::path get_prefix () const override;
175 fs::path get_user_dir (bool force_default) override;
176 fs::path get_default_user_dir () override;
177
178private:
179 UserDirProvider user_dir_provider_;
180 DefaultUserDirProvider default_user_dir_provider_;
181 ApplicationDirPathProvider application_dir_path_provider_;
182};
183
184struct TestingDirectoryManager : public IDirectoryManager
185{
186 TestingDirectoryManager () = default;
187 Q_DISABLE_COPY_MOVE (TestingDirectoryManager)
188 ~TestingDirectoryManager () override { remove_testing_dir (); }
189
190 fs::path get_user_dir (bool force_default) override;
191
197 const fs::path &get_testing_dir ();
198
201
202 fs::path get_prefix () const override;
203 fs::path get_default_user_dir () override;
204
206 fs::path testing_dir_;
207};
fs::path get_user_dir(bool force_default) override
Gets the zrythm directory, either from the settings if non-empty, or the default ($XDG_DATA_DIR/zryth...
fs::path get_prefix() const override
Returns the prefix or in the case of Windows the root dir (C/program files/zrythm) or in the case of ...
fs::path get_default_user_dir() override
Returns the default user "zrythm" dir.
virtual fs::path get_user_dir(bool force_default)=0
Gets the zrythm directory, either from the settings if non-empty, or the default ($XDG_DATA_DIR/zryth...
virtual fs::path get_default_user_dir()=0
Returns the default user "zrythm" dir.
virtual fs::path get_prefix() const =0
Returns the prefix or in the case of Windows the root dir (C/program files/zrythm) or in the case of ...
virtual fs::path get_dir(DirectoryType type)
Returns a Zrythm directory specified by type.
DirectoryType
Type of directory.
@ SYSTEM_LOCALEDIR
Localization under "share".
@ SYSTEM_PARENT_DATADIR
"share" under SYSTEM_PREFIX.
@ SYSTEM_BINDIR
"bin" under SYSTEM_PREFIX.
@ USER_TOP
Main zrythm directory from gsettings.
@ SYSTEM_PARENT_LIBDIR
libdir name under SYSTEM_PREFIX.
@ SYSTEM_BUNDLED_PLUGINSDIR
libdir/zrythm/lv2
@ SYSTEM_SPECIAL_LV2_PLUGINS_DIR
Special external Zrythm plugins path (not part of the Zrythm source code).
@ SYSTEM_PREFIX
The prefix, or in the case of windows installer the root dir (C/program files/zrythm),...
@ USER_PROJECTS
Subdirs of USER_TOP.
fs::path get_user_dir(bool force_default) override
Gets the zrythm directory, either from the settings if non-empty, or the default ($XDG_DATA_DIR/zryth...
fs::path testing_dir_
Zrythm directory used during unit tests.
fs::path get_default_user_dir() override
Returns the default user "zrythm" dir.
fs::path get_prefix() const override
Returns the prefix or in the case of Windows the root dir (C/program files/zrythm) or in the case of ...
void remove_testing_dir()
Clears testing_dir and removes the testing dir from the disk.
const fs::path & get_testing_dir()
Returns the current testing dir.