hydrogen 1.2.3
Filesystem.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef H2C_FILESYSTEM_H
24#define H2C_FILESYSTEM_H
25
26#include <core/Object.h>
27#include <QtCore/QString>
28
29namespace H2Core
30{
31
36 class Filesystem : public H2Core::Object<Filesystem>
37 {
39 public:
48
53 enum class Lookup {
61 stacked = 0,
63 user = 1,
65 system = 2
66 };
67
70 enum class DrumkitType {
73 System = 0,
76 User = 1,
85 };
86
87 static const QString songs_ext;
88 static const QString scripts_ext;
89 static const QString patterns_ext;
90 static const QString playlist_ext;
91 static const QString drumkit_ext;
92 static const QString themes_ext;
93 static const QString songs_filter_name;
94 static const QString themes_filter_name;
95 static const QString scripts_filter_name;
96 static const QString patterns_filter_name;
97 static const QString playlists_filter_name;
98
104 static bool bootstrap( Logger* logger, const QString& sys_path=nullptr );
105
107 static QString sys_data_path();
109 static QString usr_data_path();
110
112 static QStringList ladspa_paths();
113
115 static QString sys_config_path();
117 static QString usr_config_path();
119 static QString empty_sample_path();
144 static QString empty_song_path();
147 static QString default_song_name();
149 static QString untitled_song_name();
156 static QString click_file_path();
158 static QString usr_click_file_path();
160 static QString drumkit_xsd( );
162 static QString drumkit_xsd_path( );
165 static QStringList drumkit_xsd_legacy_paths( );
167 static QString pattern_xsd_path( );
169 static QString playlist_xsd_path( );
171 static QString log_file_path();
172
174 static QString img_dir();
176 static QString doc_dir();
178 static QString i18n_dir();
180 static QString scripts_dir();
182 static QString songs_dir();
184 static QString song_path( const QString& sg_name );
186 static QString patterns_dir();
188 static QString patterns_dir( const QString& dk_name );
190 static QString pattern_path( const QString& dk_name, const QString& p_name );
192 static QString plugins_dir();
194 static QString sys_drumkits_dir();
196 static QString usr_drumkits_dir();
198 static QString playlists_dir();
200 static QString playlist_path( const QString& pl_name );
202 static QString untitled_playlist_file_name();
204 static QString cache_dir();
206 static QString repositories_cache_dir();
208 static QString demos_dir();
210 static QString xsd_dir();
211 static QString xsd_legacy_dir();
213 static QString tmp_dir();
214 static QString usr_theme_dir();
215 static QString sys_theme_dir();
221 static QString tmp_file_path( const QString& base );
222
223 /* DRUMKIT */
225 static QString prepare_sample_path( const QString& fname );
227 static bool file_is_under_drumkit( const QString& fname);
229 static int get_basename_idx_under_drumkit( const QString& fname);
231 static QStringList sys_drumkit_list( );
233 static QStringList usr_drumkit_list( );
238 static bool drumkit_exists( const QString& dk_name );
243 static QString drumkit_usr_path( const QString& dk_name );
244 static QString drumkit_default_kit();
277 static QString drumkit_path_search( const QString& dk_name, Lookup lookup = Lookup::stacked, bool bSilent = false );
284 static QString drumkit_dir_search( const QString& dk_name, Lookup lookup );
289 static bool drumkit_valid( const QString& dk_path );
294 static QString drumkit_file( const QString& dk_path );
295
299 static QString drumkit_xml();
300
306 static QString drumkit_backup_path( const QString& dk_path );
307
308 /* PATTERNS */
312 static QStringList pattern_drumkits();
316 static QStringList pattern_list();
321 static QStringList pattern_list( const QString& path );
322
323 /* SONGS */
325 static QStringList song_list( );
327 static QStringList song_list_cleared( );
332 static bool song_exists( const QString& sg_name );
333
351 static bool isSongPathValid( const QString& sSongPath, bool bCheckExistance = false );
352
358 static QString validateFilePath( const QString& sPath );
359
360 static QStringList theme_list();
361
363 static void info();
364
365 /* PLAYLISTS */
367 static QStringList playlist_list( );
368
374 static bool file_exists( const QString& path, bool silent=false );
380 static bool file_readable( const QString& path, bool silent=false );
386 static bool file_writable( const QString& path, bool silent=false );
392 static bool file_executable( const QString& path, bool silent=false );
398 static bool dir_exists( const QString& path, bool silent=false );
404 static bool dir_readable( const QString& path, bool silent=false );
410 static bool dir_writable( const QString& path, bool silent=false );
417 static bool path_usable( const QString& path, bool create=true, bool silent=false );
418
422 static QString absolute_path( const QString& sFilename, bool bSilent = false );
428 static QString ensure_session_compatibility( const QString& sPath );
434 static bool write_to_file( const QString& dst, const QString& content );
443 static bool file_copy( const QString& src, const QString& dst, bool overwrite=false, bool bSilent = false );
451 static bool rm( const QString& path, bool recursive=false, bool bSilent = false );
456 static bool mkdir( const QString& path );
457
459 static const QString& getPreferencesOverwritePath();
461 static void setPreferencesOverwritePath( const QString& sPath );
462
467 static DrumkitType determineDrumkitType( const QString& sPath );
468
485 static QString rerouteDrumkitPath( const QString& sDrumkitPath );
486
487 private:
488 static Logger* __logger;
489 static bool check_sys_paths();
490 static bool check_usr_paths();
491 static bool rm_fr( const QString& path, bool bSilent = false );
492
501 static QStringList drumkit_list( const QString& path );
508 static bool check_permissions( const QString& path, const int perms, bool silent );
509
533 static QString __sys_data_path;
534 static QString __usr_data_path;
535 static QString __usr_cfg_path;
536 static QString __usr_log_path;
537 static QStringList __ladspa_paths;
538 };
539
543 inline void Filesystem::setPreferencesOverwritePath( const QString& sPath ) {
545 }
546
547};
548#endif // H2C_FILESYSTEM_H
549
550/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:224
static Logger * logger()
return the logger instance
Definition Object.h:103
Filesystem is a thin layer over QDir, QFile and QFileInfo.
Definition Filesystem.h:37
static QStringList song_list()
returns a list of existing songs
static QString __usr_cfg_path
the path to the user config file
Definition Filesystem.h:535
static bool file_copy(const QString &src, const QString &dst, bool overwrite=false, bool bSilent=false)
copy a source file to a destination
static QString scripts_dir()
returns user scripts path
static const QString patterns_filter_name
Definition Filesystem.h:96
static QString playlist_xsd_path()
returns the path to the playlist pattern XSD (xml schema definition) file
static QString validateFilePath(const QString &sPath)
Takes an arbitrary path, replaces white spaces by underscores and removes all characters apart from l...
static QString demos_dir()
returns system demos path
static QString song_path(const QString &sg_name)
returns user song path, add file extension
static QString ensure_session_compatibility(const QString &sPath)
If Hydrogen is under session management, we support for paths relative to the session folder.
static QString sys_data_path()
returns system data path
static bool dir_readable(const QString &path, bool silent=false)
returns true if the given path is a readable regular directory
file_perms
flags available for check_permissions()
Definition Filesystem.h:41
static QString cache_dir()
returns user cache path
static const QString patterns_ext
Definition Filesystem.h:89
static bool drumkit_exists(const QString &dk_name)
returns true if the drumkit exists within usable system or user drumkits
static bool check_usr_paths()
returns true if the user path is consistent
static const QString scripts_filter_name
Definition Filesystem.h:95
static bool file_executable(const QString &path, bool silent=false)
returns true if the given path is an existing executable regular file
static bool isSongPathValid(const QString &sSongPath, bool bCheckExistance=false)
Checks the path pointing to a .h2song.
static bool drumkit_valid(const QString &dk_path)
returns true if the path contains a usable drumkit
static QString playlist_path(const QString &pl_name)
returns user playlist path, add file extension
static QStringList drumkit_list(const QString &path)
static void setPreferencesOverwritePath(const QString &sPath)
Definition Filesystem.h:543
static bool check_permissions(const QString &path, const int perms, bool silent)
static QString usr_config_path()
returns user config path
static QString songs_dir()
returns user songs path
static QString pattern_xsd_path()
returns the path to the pattern XSD (xml schema definition) file
static const QString themes_ext
Definition Filesystem.h:92
static QString playlists_dir()
returns user playlist path
static DrumkitType determineDrumkitType(const QString &sPath)
static QString usr_click_file_path()
returns click file path from user directory if exists, otherwise from system
static QString empty_sample_path()
returns system empty sample file path
static QStringList playlist_list()
returns a list of existing playlists
static QString absolute_path(const QString &sFilename, bool bSilent=false)
Convert a direct to an absolute path.
static QString plugins_dir()
returns user plugins path
static bool file_writable(const QString &path, bool silent=false)
returns true if the given path is a possibly writable file (may exist or not)
static QStringList theme_list()
static QString usr_drumkits_dir()
returns user drumkits path
static QString untitled_song_name()
returns untitled song name
static bool check_sys_paths()
returns true if the system path is consistent
static const QString & getPreferencesOverwritePath()
Definition Filesystem.h:540
static QStringList ladspa_paths()
returns user ladspa paths
static QStringList drumkit_xsd_legacy_paths()
static QStringList pattern_list()
returns a list of existing patterns
static QString sys_drumkits_dir()
returns system drumkits path
static bool rm(const QString &path, bool recursive=false, bool bSilent=false)
remove a path
static QString drumkit_backup_path(const QString &dk_path)
Create a backup path from a drumkit path.
static QStringList song_list_cleared()
returns a list of existing songs, excluding the autosaved one
static QString usr_theme_dir()
static QString drumkit_xsd_path()
returns the path to the drumkit XSD (xml schema definition) file
static QString doc_dir()
returns documentation path
static const QString scripts_ext
Definition Filesystem.h:88
static QStringList usr_drumkit_list()
returns list of usable user drumkits ( see Filesystem::drumkit_list )
static QString repositories_cache_dir()
returns user repository cache path
static bool file_is_under_drumkit(const QString &fname)
Checks if the given filepath is under an existing user or system drumkit path, not the existence of t...
static QString prepare_sample_path(const QString &fname)
Returns the basename if the given path is under an existing user or system drumkit path,...
static bool rm_fr(const QString &path, bool bSilent=false)
recursively remove a path
static bool dir_writable(const QString &path, bool silent=false)
returns true if the given path is a writable regular directory
static int get_basename_idx_under_drumkit(const QString &fname)
Returns the index of the basename if the given path is under an existing user or system drumkit path,...
static QString img_dir()
returns gui image path
static QString rerouteDrumkitPath(const QString &sDrumkitPath)
Reroutes stored drumkit paths pointing to a temporary AppImage system data folder to the current AppI...
static bool file_exists(const QString &path, bool silent=false)
returns true if the given path is an existing regular file
static QString __usr_data_path
the path to the user files
Definition Filesystem.h:534
static QString empty_song_path()
Provides the full path to the current empty song.
Lookup
Whenever a drumkit is loaded by name a collision between a user and a system drumkit carrying the sam...
Definition Filesystem.h:53
@ system
Only search the system drumkits.
@ stacked
First, looks in the system drumkits and, afterwards, in the user drumkits.
@ user
Only search the user drumkits.
static QString drumkit_dir_search(const QString &dk_name, Lookup lookup)
returns the directory holding the named drumkit searching within user then system drumkits
static QString m_sPreferencesOverwritePath
If this variable is non-empty, its content will be used as an alternative to store and load the prefe...
Definition Filesystem.h:496
static QString click_file_path()
Returns a string containing the path to the click.wav file used in the metronome.
static QStringList sys_drumkit_list()
returns list of usable system drumkits ( see Filesystem::drumkit_list )
static QString drumkit_path_search(const QString &dk_name, Lookup lookup=Lookup::stacked, bool bSilent=false)
Returns the path to a H2Core::Drumkit folder.
static const QString playlists_filter_name
Definition Filesystem.h:97
static QString sys_config_path()
returns system config path
static bool mkdir(const QString &path)
create a path
static QString drumkit_file(const QString &dk_path)
returns the path to the xml file within a supposed drumkit path
static QStringList pattern_drumkits()
returns a list of existing drumkit sub dir into the patterns directory
static QString __sys_data_path
Path to the system files set in Filesystem::bootstrap().
Definition Filesystem.h:533
static bool bootstrap(Logger *logger, const QString &sys_path=nullptr)
check user and system filesystem usability
static QString pattern_path(const QString &dk_name, const QString &p_name)
returns user patterns path, add file extension
static QString __usr_log_path
the path to the log file
Definition Filesystem.h:536
static bool write_to_file(const QString &dst, const QString &content)
writes to a file
static Logger * __logger
a pointer to the logger
Definition Filesystem.h:488
static const QString playlist_ext
Definition Filesystem.h:90
static QString i18n_dir()
returns internationalization path
static const QString songs_filter_name
Definition Filesystem.h:93
static QString xsd_legacy_dir()
static QString tmp_dir()
returns temp path
DrumkitType
Determines were to find a kit and whether it is writable by the current user.
Definition Filesystem.h:70
@ SessionReadWrite
Kit was loaded via a NSM session, OSC command, or CLI option, only persist for the current Hydrogen s...
@ User
Kit was installed by the user, is automatically loaded, and most probably writable.
@ System
Kit was installed with Hydrogen, is automatically loaded, and most probably readonly.
@ SessionReadOnly
Kit was loaded via a NSM session, OSC command, or CLI option, only persist for the current Hydrogen s...
static void info()
send current settings information to logger with INFO severity
static QString usr_data_path()
returns user data path
static QString log_file_path()
returns the full path (including filename) of the logfile
static QString drumkit_usr_path(const QString &dk_name)
returns path for a drumkit within user drumkit path
static const QString drumkit_ext
Definition Filesystem.h:91
static const QString themes_filter_name
Definition Filesystem.h:94
static const QString songs_ext
Definition Filesystem.h:87
static QString sys_theme_dir()
static bool path_usable(const QString &path, bool create=true, bool silent=false)
returns true if the path is a readable and writable regular directory, create if it not exists
static QString drumkit_xml()
Returns filename and extension of the expected drumkit file.
static QString drumkit_xsd()
returns the drumkit XSD (xml schema definition) name
static QString tmp_file_path(const QString &base)
touch a temporary file under tmp_dir() and return it's path.
static QString default_song_name()
Default option to offer the user when saving an empty song to disk.
static QString xsd_dir()
returns system xsd path
static bool song_exists(const QString &sg_name)
returns true if the song file exists
static QStringList __ladspa_paths
paths to laspa plugins
Definition Filesystem.h:537
static QString untitled_playlist_file_name()
returns untitled playlist file name
static bool file_readable(const QString &path, bool silent=false)
returns true if the given path is an existing readable regular file
static bool dir_exists(const QString &path, bool silent=false)
returns true if the given path is a regular directory
static QString drumkit_default_kit()
static QString patterns_dir()
returns user patterns path
Class for writing logs to the console.
Definition Logger.h:42