1 | // Aseprite |
2 | // Copyright (C) 2019-2022 Igara Studio S.A. |
3 | // Copyright (C) 2001-2018 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifndef APP_FILE_SYSTEM_H_INCLUDED |
9 | #define APP_FILE_SYSTEM_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "base/paths.h" |
13 | #include "obs/signal.h" |
14 | #include "os/surface.h" |
15 | |
16 | #include <mutex> |
17 | #include <string> |
18 | #include <vector> |
19 | |
20 | namespace app { |
21 | |
22 | class IFileItem; |
23 | using FileItemList = std::vector<IFileItem*>; |
24 | |
25 | class FileSystemModule { |
26 | static FileSystemModule* m_instance; |
27 | |
28 | public: |
29 | FileSystemModule(); |
30 | ~FileSystemModule(); |
31 | |
32 | static FileSystemModule* instance(); |
33 | |
34 | // Marks all FileItems as deprecated to be refresh the next time |
35 | // they are queried through @ref FileItem::children(). |
36 | void refresh(); |
37 | |
38 | IFileItem* getRootFileItem(); |
39 | |
40 | // Returns the FileItem through the specified "path". |
41 | // Warning: You have to call path.fix_separators() before. |
42 | IFileItem* getFileItemFromPath(const std::string& path); |
43 | |
44 | void lock() { m_mutex.lock(); } |
45 | void unlock() { m_mutex.unlock(); } |
46 | |
47 | obs::signal<void(IFileItem*)> ItemRemoved; |
48 | |
49 | private: |
50 | std::mutex m_mutex; |
51 | }; |
52 | |
53 | class LockFS { |
54 | public: |
55 | LockFS(FileSystemModule* fs) : m_fs(fs) { |
56 | m_fs->lock(); |
57 | } |
58 | ~LockFS() { |
59 | m_fs->unlock(); |
60 | } |
61 | private: |
62 | FileSystemModule* m_fs; |
63 | }; |
64 | |
65 | class IFileItem { |
66 | public: |
67 | virtual ~IFileItem() { } |
68 | |
69 | virtual bool isFolder() const = 0; |
70 | virtual bool isBrowsable() const = 0; |
71 | virtual bool isHidden() const = 0; |
72 | |
73 | // Returns false if this item doesn't exist anymore (e.g. a file |
74 | // or folder that was deleted from other process). |
75 | virtual bool isExistent() const = 0; |
76 | |
77 | virtual const std::string& keyName() const = 0; |
78 | virtual const std::string& fileName() const = 0; |
79 | virtual const std::string& displayName() const = 0; |
80 | |
81 | virtual IFileItem* parent() const = 0; |
82 | virtual const FileItemList& children() = 0; |
83 | virtual void createDirectory(const std::string& dirname) = 0; |
84 | |
85 | virtual bool hasExtension(const base::paths& extensions) = 0; |
86 | |
87 | virtual double getThumbnailProgress() = 0; |
88 | virtual void setThumbnailProgress(double progress) = 0; |
89 | |
90 | virtual bool needThumbnail() const = 0; |
91 | virtual os::SurfaceRef getThumbnail() = 0; |
92 | virtual void setThumbnail(const os::SurfaceRef& thumbnail) = 0; |
93 | |
94 | }; |
95 | |
96 | } // namespace app |
97 | |
98 | #endif |
99 | |