RhythmGame 1.4.3
Loading...
Searching...
No Matches
SongAssetStore.h
Go to the documentation of this file.
1#ifndef RHYTHMGAME_SONGASSETSTORE_H
2#define RHYTHMGAME_SONGASSETSTORE_H
3
4#include <QByteArray>
5#include <QObject>
6#include <QString>
7#include <QTemporaryDir>
8
9#include <atomic>
10#include <filesystem>
11#include <functional>
12#include <memory>
13#include <optional>
14#include <unordered_map>
15#include <vector>
16
17namespace resource_managers {
18#ifdef RHYTHMGAME_USE_BACKBEAT
19class BackbeatSource;
20#endif
21
27class SongAssetStore : public QObject
28{
29 Q_OBJECT
30
31 public:
33 {
34 std::filesystem::path virtualPath;
35 std::optional<QByteArray> contents;
36 };
37
39 std::function<bool(const std::filesystem::path& virtualPath)>;
40 using EntryVisitor = std::function<void(ArchiveEntry entry)>;
41
42 explicit SongAssetStore(QObject* parent = nullptr);
43 ~SongAssetStore() override;
44#ifdef RHYTHMGAME_USE_BACKBEAT
45 void setBackbeatSource(std::shared_ptr<BackbeatSource> source);
46#endif
47
48 [[nodiscard]] auto read(const std::filesystem::path& virtualPath,
49 const std::atomic_bool* stop = nullptr) const
50 -> QByteArray;
51 [[nodiscard]] auto materialize(const std::filesystem::path& virtualPath,
52 const std::atomic_bool* stop = nullptr) const
53 -> std::filesystem::path;
54 [[nodiscard]] auto materializeRelative(
55 const std::filesystem::path& virtualDirectory,
56 const std::vector<std::filesystem::path>& relativePaths,
57 const std::atomic_bool* stop = nullptr) const
58 -> std::unordered_map<std::filesystem::path, std::filesystem::path>;
59 void walkArchive(const std::filesystem::path& archivePath,
60 const WantsContents& wantsContents,
61 const EntryVisitor& visitor,
62 std::atomic_bool* stop = nullptr) const;
63
64 [[nodiscard]] auto isArchived(
65 const std::filesystem::path& virtualPath) const -> bool;
66 [[nodiscard]] auto isVirtual(const std::filesystem::path& virtualPath) const
67 -> bool;
68
69 [[nodiscard]] static auto isArchivePath(const std::filesystem::path& path)
70 -> bool;
71 [[nodiscard]] static auto isSupportedArchivePath(
72 const std::filesystem::path& path) -> bool;
73 [[nodiscard]] static auto archiveSupportError(
74 const std::filesystem::path& path) -> QString;
75 [[nodiscard]] static auto isSplitArchivePath(
76 const std::filesystem::path& path) -> bool;
77 [[nodiscard]] static auto imageUrl(const std::filesystem::path& virtualPath)
78 -> QString;
79 [[nodiscard]] static auto imageUrl(const QString& virtualDirectory,
80 const QString& relativePath) -> QString;
81 [[nodiscard]] static auto audioUrl(const std::filesystem::path& virtualPath)
82 -> QString;
83 [[nodiscard]] static auto isAudioUrl(const QString& source) -> bool;
84 [[nodiscard]] static auto pathFromUrl(const QString& source)
85 -> std::filesystem::path;
86
87 Q_INVOKABLE [[nodiscard]] QString imageSource(
88 const QString& virtualDirectory,
89 const QString& relativePath) const;
90 Q_INVOKABLE [[nodiscard]] QString localFile(
91 const QString& virtualPath) const;
92 Q_INVOKABLE [[nodiscard]] QString containingFolder(
93 const QString& virtualPath) const;
94
95 private:
96 class Impl;
97
98 void materializeRequested(
99 const std::vector<std::filesystem::path>& virtualPaths,
100 const std::atomic_bool* stop = nullptr) const;
101
102 QTemporaryDir temporaryDirectory;
103 std::filesystem::path materializationDirectory;
104 std::unique_ptr<Impl> impl;
105#ifdef RHYTHMGAME_USE_BACKBEAT
106 std::shared_ptr<BackbeatSource> backbeat;
107#endif
108};
109
110} // namespace resource_managers
111
112#endif // RHYTHMGAME_SONGASSETSTORE_H
ReplaySource source
Definition BeatorajaReplayImporter.cpp:71
QString path
Definition Lr2SkinParser.cpp:87
Definition SongAssetStore.cpp:907
Definition SongAssetStore.h:28
static auto isAudioUrl(const QString &source) -> bool
Definition SongAssetStore.cpp:1513
static auto pathFromUrl(const QString &source) -> std::filesystem::path
Definition SongAssetStore.cpp:1519
auto isVirtual(const std::filesystem::path &virtualPath) const -> bool
Definition SongAssetStore.cpp:1138
auto read(const std::filesystem::path &virtualPath, const std::atomic_bool *stop=nullptr) const -> QByteArray
Definition SongAssetStore.cpp:1352
static auto imageUrl(const std::filesystem::path &virtualPath) -> QString
Definition SongAssetStore.cpp:1457
std::function< bool(const std::filesystem::path &virtualPath)> WantsContents
Definition SongAssetStore.h:39
Q_INVOKABLE QString containingFolder(const QString &virtualPath) const
Definition SongAssetStore.cpp:1564
std::function< void(ArchiveEntry entry)> EntryVisitor
Definition SongAssetStore.h:40
auto isArchived(const std::filesystem::path &virtualPath) const -> bool
Definition SongAssetStore.cpp:1205
void walkArchive(const std::filesystem::path &archivePath, const WantsContents &wantsContents, const EntryVisitor &visitor, std::atomic_bool *stop=nullptr) const
Definition SongAssetStore.cpp:1214
static auto archiveSupportError(const std::filesystem::path &path) -> QString
Definition SongAssetStore.cpp:1168
auto materializeRelative(const std::filesystem::path &virtualDirectory, const std::vector< std::filesystem::path > &relativePaths, const std::atomic_bool *stop=nullptr) const -> std::unordered_map< std::filesystem::path, std::filesystem::path >
Definition SongAssetStore.cpp:1255
Q_INVOKABLE QString localFile(const QString &virtualPath) const
Definition SongAssetStore.cpp:1546
static auto audioUrl(const std::filesystem::path &virtualPath) -> QString
Definition SongAssetStore.cpp:1504
auto materialize(const std::filesystem::path &virtualPath, const std::atomic_bool *stop=nullptr) const -> std::filesystem::path
Definition SongAssetStore.cpp:1402
Q_INVOKABLE QString imageSource(const QString &virtualDirectory, const QString &relativePath) const
Definition SongAssetStore.cpp:1539
static auto isArchivePath(const std::filesystem::path &path) -> bool
Definition SongAssetStore.cpp:1149
static auto isSplitArchivePath(const std::filesystem::path &path) -> bool
Definition SongAssetStore.cpp:1187
static auto isSupportedArchivePath(const std::filesystem::path &path) -> bool
Definition SongAssetStore.cpp:1158
Classes and functions related to loading and managing resources such as charts, sounds,...
Definition ProfileArenaIdentityProvider.h:12
std::optional< QByteArray > contents
Definition SongAssetStore.h:35
std::filesystem::path virtualPath
Definition SongAssetStore.h:34