1 // Aseprite
2 // Copyright (C) 2001-2018  David Capello
3 //
4 // This program is distributed under the terms of
5 // the End-User License Agreement for Aseprite.
6 
7 #ifndef APP_FILE_SYSTEM_H_INCLUDED
8 #define APP_FILE_SYSTEM_H_INCLUDED
9 #pragma once
10 
11 #include "base/mutex.h"
12 #include "base/paths.h"
13 
14 #include <string>
15 #include <vector>
16 
17 namespace she {
18   class Surface;
19 }
20 
21 namespace app {
22 
23   class IFileItem;
24 
25   typedef std::vector<IFileItem*> FileItemList;
26 
27   class FileSystemModule {
28     static FileSystemModule* m_instance;
29 
30   public:
31     FileSystemModule();
32     ~FileSystemModule();
33 
34     static FileSystemModule* instance();
35 
36     // Marks all FileItems as deprecated to be refresh the next time
37     // they are queried through @ref FileItem::children().
38     void refresh();
39 
40     IFileItem* getRootFileItem();
41 
42     // Returns the FileItem through the specified "path".
43     // Warning: You have to call path.fix_separators() before.
44     IFileItem* getFileItemFromPath(const std::string& path);
45 
lock()46     void lock() { m_mutex.lock(); }
unlock()47     void unlock() { m_mutex.unlock(); }
48 
49   private:
50     base::mutex m_mutex;
51   };
52 
53   class LockFS {
54   public:
LockFS(FileSystemModule * fs)55     LockFS(FileSystemModule* fs) : m_fs(fs) {
56       m_fs->lock();
57     }
~LockFS()58     ~LockFS() {
59       m_fs->unlock();
60     }
61   private:
62     FileSystemModule* m_fs;
63   };
64 
65   class IFileItem {
66   public:
~IFileItem()67     virtual ~IFileItem() { }
68 
69     virtual bool isFolder() const = 0;
70     virtual bool isBrowsable() const = 0;
71     virtual bool isHidden() const = 0;
72 
73     virtual std::string keyName() const = 0;
74     virtual std::string fileName() const = 0;
75     virtual std::string displayName() const = 0;
76 
77     virtual IFileItem* parent() const = 0;
78     virtual const FileItemList& children() = 0;
79     virtual void createDirectory(const std::string& dirname) = 0;
80 
81     virtual bool hasExtension(const base::paths& extensions) = 0;
82 
83     virtual she::Surface* getThumbnail() = 0;
84     virtual void setThumbnail(she::Surface* thumbnail) = 0;
85   };
86 
87 } // namespace app
88 
89 #endif
90