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