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 : #ifndef MUSE_IO_IFILESYSTEM_H
23 : #define MUSE_IO_IFILESYSTEM_H
24 :
25 : #include "global/modularity/imoduleinterface.h"
26 : #include "global/types/bytearray.h"
27 : #include "global/types/datetime.h"
28 : #include "global/types/retval.h"
29 :
30 : #include "path.h"
31 : #include "ioenums.h"
32 :
33 : namespace muse::io {
34 : class IFileSystem : MODULE_GLOBAL_INTERFACE
35 : {
36 778 : INTERFACE_ID(IFileSystem)
37 :
38 : public:
39 438 : virtual ~IFileSystem() = default;
40 :
41 : virtual Ret exists(const io::path_t& path) const = 0;
42 : virtual Ret remove(const io::path_t& path, bool onlyIfEmpty = false) = 0; // remove file or dir
43 : virtual Ret clear(const io::path_t& path) = 0; // clear dir
44 : virtual Ret copy(const io::path_t& src, const io::path_t& dst, bool replace = false) = 0;
45 : virtual Ret move(const io::path_t& src, const io::path_t& dst, bool replace = false) = 0;
46 :
47 : virtual Ret makePath(const io::path_t& path) const = 0;
48 : virtual Ret makeLink(const io::path_t& targetPath, const io::path_t& linkPath) const = 0;
49 :
50 : virtual EntryType entryType(const io::path_t& path) const = 0;
51 :
52 : //! NOTE In bytes
53 : virtual RetVal<uint64_t> fileSize(const io::path_t& path) const = 0;
54 : virtual RetVal<uint64_t> availableSpace(const io::path_t& path) const = 0;
55 :
56 : virtual RetVal<io::paths_t> scanFiles(const io::path_t& rootDir, const std::vector<std::string>& filters,
57 : ScanMode mode = ScanMode::FilesInCurrentDirAndSubdirs) const = 0;
58 :
59 : enum class Attribute {
60 : Hidden
61 : };
62 :
63 : virtual void setAttribute(const io::path_t& path, Attribute attribute) const = 0;
64 : virtual bool setPermissionsAllowedForAll(const io::path_t& path) const = 0;
65 :
66 : virtual RetVal<ByteArray> readFile(const io::path_t& filePath) const = 0;
67 : virtual Ret readFile(const io::path_t& filePath, ByteArray& data) const = 0;
68 : virtual Ret writeFile(const io::path_t& filePath, const ByteArray& data) = 0;
69 :
70 : //! Streaming write
71 : virtual RetVal<StreamId> openStream(const io::path_t& filePath, OpenMode mode) = 0;
72 : virtual Ret writeToStream(StreamId fileId, const ByteArray& data, uint64_t offset = STREAM_POS_CURRENT) = 0;
73 : virtual Ret closeStream(StreamId fileId) = 0;
74 :
75 : //! NOTE File info
76 : virtual io::path_t temporaryDirectoryPath() const = 0;
77 : virtual io::path_t canonicalFilePath(const io::path_t& filePath) const = 0;
78 : virtual io::path_t absolutePath(const io::path_t& filePath) const = 0;
79 : virtual io::path_t absoluteFilePath(const io::path_t& filePath) const = 0;
80 : virtual io::path_t cleanPath(const io::path_t& filePath) const = 0;
81 : virtual bool isSymLink(const io::path_t& filePath) const = 0;
82 : virtual io::path_t symLinkTarget(const io::path_t& filePath) const = 0;
83 : virtual DateTime birthTime(const io::path_t& filePath) const = 0;
84 : virtual DateTime lastModified(const io::path_t& filePath) const = 0;
85 : virtual Ret isWritable(const io::path_t& filePath) const = 0;
86 : };
87 : }
88 :
89 : #endif // MUSE_IO_IFILESYSTEM_H
|