root/trunk/src/core/include/hydrogen/helpers/filesystem.h @ 2255

Revision 2255, 8.9 KB (checked in by jeremyz, 23 months ago)

Filesystem: add 'const QString& sys_path=0' parameter to boostrap static function

Line 
1
2#ifndef H2C_FILESYSTEM_H
3#define H2C_FILESYSTEM_H
4
5#include <hydrogen/object.h>
6#include <QtCore/QString>
7
8namespace H2Core {
9
10/**
11 * Filesystem is a thin layer over QDir, QFile and QFileInfo
12 */
13class Filesystem : public H2Core::Object {
14        H2_OBJECT
15    public:
16        /** flags available for Filesystem::check_permissions */
17        enum file_perms {
18            is_dir =0x01,
19            is_file=0x02,
20            is_readable=0x04,
21            is_writable=0x08,
22            is_executable=0x10
23        };
24
25        /**
26         * check user and system filesystem usability
27         * \param logger is a pointer to the logger instance which will be used
28         * \param sys_path an alternate system data path
29         */
30        static bool bootstrap( Logger* logger, const QString& sys_path=0 );
31
32        /** returns system data path */
33        static QString sys_data_path();
34        /** returns user data path */
35        static QString usr_data_path();
36
37        /** returns system core config path */
38        static QString sys_core_config();
39        /** returns user core config path */
40        static QString usr_core_config();
41        /** returns system gui config path */
42        static QString sys_gui_config();
43        /** returns user gui config path */
44        static QString usr_gui_config();
45        /** returns system empty sample file path */
46        static QString empty_sample();
47        /** returns system empty song file path */
48        static QString empty_song();
49        /** returns system click file path */
50        static QString click_file();
51        /** returns click file path from user directory if exists, otherwise from system */
52        static QString usr_click_file();
53        /** returns the path to the drumkit XSD (xml schema definition) file */
54        static QString drumkit_xsd( );
55        /** returns the path to the pattern XSD (xml schema definition) file */
56        static QString pattern_xsd( );
57
58        /** returns gui image path */
59        static QString img_dir();
60        /** returns documentation path */
61        static QString doc_dir();
62        /** returns internationalization path */
63        static QString i18n_dir();
64        /** returns user songs path */
65        static QString songs_dir();
66        /** returns user patterns path */
67        static QString patterns_dir();
68        /** returns system drumkits path */
69        static QString sys_drumkits_dir();
70        /** returns user drumkits path */
71        static QString usr_drumkits_dir();
72        /** returns user playlist path */
73        static QString playlists_dir();
74        /** returns system demos path */
75        static QString demos_dir();
76        /** returns system xsd path */
77        static QString xsd_dir();
78
79        /* DRUMKIT */
80        /** returns list of usable system drumkits ( see Filesystem::drumkits_list ) */
81        static QStringList sys_drumkits_list( );
82        /** returns list of usable user drumkits ( see Filesystem::drumkits_list ) */
83        static QStringList usr_drumkits_list( );
84        /**
85         * returns true if the drumkit exists within usable system or user drumkits
86         * \param dk_name the drumkit name
87         */
88        static bool drumkit_exists( const QString& dk_name );
89        /**
90         * returns path for a drumkit within user drumkit path
91         * \param dk_name the drumkit name
92         */
93        static QString drumkit_usr_path( const QString& dk_name );
94        /**
95         * returns path for a drumkit searching within user then system drumkits
96         * \param dk_name the drumkit name
97         */
98        static QString drumkit_path_search( const QString& dk_name );
99        /**
100         * returns the directory holding the named drumkit searching within user then system drumkits
101         * \param dk_name the drumkit name
102         */
103        static QString drumkit_dir_search( const QString& dk_name );
104        /**
105         * returns true if the path contains a usable drumkit
106         * \param dk_location the root drumkit location
107         */
108        static bool drumkit_valid( const QString& dk_path );
109        /**
110         * returns the path to the xml file within a suposed drumkit path
111         * \param dk_path the path to the drumkit
112         */
113        static QString drumkit_file( const QString& dk_path );
114
115        /* PATTERNS */
116        /** returns a list of existing patterns */
117        static QStringList patterns_list( );
118
119        /* SONGS */
120        /** returns a list of existing songs */
121        static QStringList songs_list( );
122        /**
123         * returns true if the song file exists
124         * \param sg_name the song name
125         */
126        static bool song_exists( const QString& sg_name );
127
128        /** send current settings information to logger with INFO severity */
129        static void info();
130
131        /**
132         * returns true if the given path is an existing regular file
133         * \param path the path to the file to check
134         * \param silent output not messages if set to true
135         */
136        static bool file_exists( const QString& path, bool silent=false );
137        /**
138         * returns true if the given path is an existing readable regular file
139         * \param path the path to the file to check
140         * \param silent output not messages if set to true
141         */
142        static bool file_readable( const QString& path, bool silent=false );
143        /**
144         * returns true if the given path is a possibly writable file (may exist or not)
145         * \param path the path to the file to check
146         * \param silent output not messages if set to true
147         */
148        static bool file_writable( const QString& path, bool silent=false );
149        /**
150         * returns true if the given path is an existing executable regular file
151         * \param path the path to the file to check
152         * \param silent output not messages if set to true
153         */
154        static bool file_executable( const QString& path, bool silent=false );
155        /**
156         * returns true if the given path is a readable regular directory
157         * \param path the path to the file to check
158         * \param silent output not messages if set to true
159         */
160        static bool dir_readable( const QString& path, bool silent=false );
161        /**
162         * returns true if the given path is a writable regular directory
163         * \param path the path to the file to check
164         * \param silent output not messages if set to true
165         */
166        static bool dir_writable( const QString& path, bool silent=false );
167        /**
168         * returns true if the path is a readable and writable regular directory, create if it not exists
169         * \param path the path to the file to check
170         * \param create will try to create path if not exists and set to true
171         * \param silent output not messages if set to true
172         */
173        static bool path_usable( const QString& path, bool create=true, bool silent=false );
174        /**
175         * writes to a file
176         * \param dst the destination path
177         * \param content then string to write
178         */
179        static bool write_to_file( const QString& dst, const QString& content );
180        /**
181         * copy a source file to a destination
182         * \param src source file path
183         * \param dsr destination file path
184         * \param overwrite allow to overwrite an existing file if set to true
185         */
186        static bool file_copy( const QString& src, const QString& dst, bool overwrite=false );
187        /**
188         * remove a path
189         * \param path the path to be removed
190         * \param recursive performe recursive removal if set to true
191         */
192        static bool rm( const QString& path, bool recursive=false );
193        /**
194         * create a path
195         * \param path the path to the directory to be created
196         */
197        static bool mkdir( const QString& path );
198
199    private:
200        static Logger* __logger;                    ///< a pointer to the logger
201        static bool check_sys_paths();              ///< returns true if the system path is consistent
202        static bool check_usr_paths();              ///< returns true if the user path is consistent
203        static bool rm_fr( const QString& path );   ///< recursively remove a path
204
205        /**
206         * returns a list of usable drumkits, which means having a readable drumkit.xml file
207         * \param path the path to search in for drumkits
208         */
209        static QStringList drumkits_list( const QString& path );
210        /**
211         * return true if all the asked permissions are ok
212         * \param path the path to the file to check
213         * \param perms bit mask of file_perms
214         * \param silent output not messages if set to true
215         */
216        static bool check_permissions( const QString& path, const int perms, bool silent );
217
218        static QString __sys_data_path;     ///< the path to the system files
219        static QString __usr_data_path;     ///< the path to the user files
220};
221
222};
223
224#endif  // H2C_FILESYSTEM_H
225
226/* vim: set softtabstop=4 expandtab: */
Note: See TracBrowser for help on using the browser.