Fission FSN
Loading...
Searching...
No Matches
fsCODRFileUtils.h
Go to the documentation of this file.
1/********************************************************************
2 * File: fsCODRFileUtils.h
3 * Purpose: Extension of file utils for the iOS ODR system
4 ********************************************************************/
5
6#ifndef FS_CODR_FILE_UTILS_H
7#define FS_CODR_FILE_UTILS_H
8
9// Use more specific includes to avoid namespace conflicts
10#include <fsCore/fsBaseTypes.h>
11#include "axmol.h"
12#include <mutex>
13#include <unordered_map>
14
15
16// Forward declare Objective-C classes
17#ifdef __OBJC__
19@class NSObject;
20@class NSData;
21@class NSBundle;
22#else
23typedef struct objc_object NSBundleResourceRequest;
24typedef struct objc_object NSObject;
25typedef struct objc_object NSData;
26typedef struct objc_object NSBundle;
27#endif
28
29#include <platform/apple/FileUtils-apple.h>
30
31class fsCODRFileUtils : public ax::FileUtilsApple {
32public:
33 static void install();
34
35 virtual bool init() override;
36 bool checkODRAvailability(std::string_view filename) const;
37 void preloadResource(std::string_view filename,
38 const std::function<void(bool)>& callback);
39 void cancelDownload(std::string_view filename);
40
41 // Required pure virtual overrides from FileUtils
42 virtual std::string getWritablePath() const override;
43 virtual std::string getNativeWritableAbsolutePath() const override;
44 virtual bool isFileExistInternal(std::string_view filename) const override;
45
46 // FileUtils overrides for ODR functionality
47 virtual FileUtils::Status getContents(std::string_view filename,
48 ax::ResizableBuffer* buffer) const override;
49 virtual std::string getStringFromFile(std::string_view filename) const override;
50 virtual ax::Data getDataFromFile(std::string_view filename) const override;
51 virtual bool writeStringToFile(std::string_view dataStr,
52 std::string_view fullPath) const override;
53 virtual bool writeDataToFile(const ax::Data& data,
54 std::string_view fullPath) const override;
55 virtual bool writeValueMapToFile(const ax::ValueMap& dict,
56 std::string_view fullPath) const override;
57 virtual bool writeValueVectorToFile(const ax::ValueVector& vecData,
58 std::string_view fullPath) const override;
59 virtual bool isFileExist(std::string_view filename) const override;
60 virtual bool isDirectoryExist(std::string_view dirPath) const override;
61 virtual bool isAbsolutePath(std::string_view path) const override;
62 std::string fullPathForFilename(std::string_view filename) const override;
63 std::unique_ptr<ax::IFileStream> openFileStream(std::string_view filePath, ax::IFileStream::Mode mode) const override;
64
65protected:
68
69private:
70 struct ODRStatus {
71 bool isDownloading{false};
72 bool isDownloaded{false};
73 NSBundleResourceRequest* request{nullptr};
74 };
75
76 mutable std::mutex _statusMutex;
77 mutable std::unordered_map<std::string, ODRStatus> _odrResourceStatus;
78 NSObject* _progressDelegate{nullptr};
79
80 int extractChapterNumber(const std::string& path) const;
81 std::string getODRTagForChapter(int chapterNum) const;
82 bool waitForResource(std::string_view filename, float timeoutSeconds);
83 std::string getODRPath(std::string_view filename) const;
84
85 fsCODRFileUtils::ODRStatus& ODRStatusGet(const std::string& tagName) const;
86 bool beginAccessingResources(const std::string& tagName) const;
87 void endAccessingResources(const std::string& tagName) const;
88 bool fileExistsInODR(const std::string& filename) const;
89 std::vector<uint8_t> getFileData(const std::string& filename) const;
90
91};
92
93#endif // FS_CODR_FILE_UTILS_H
bool checkODRAvailability(std::string_view filename) const
void cancelDownload(std::string_view filename)
virtual bool writeStringToFile(std::string_view dataStr, std::string_view fullPath) const override
virtual ax::Data getDataFromFile(std::string_view filename) const override
virtual bool isAbsolutePath(std::string_view path) const override
virtual bool writeDataToFile(const ax::Data &data, std::string_view fullPath) const override
std::unique_ptr< ax::IFileStream > openFileStream(std::string_view filePath, ax::IFileStream::Mode mode) const override
std::string fullPathForFilename(std::string_view filename) const override
virtual bool init() override
virtual bool isFileExist(std::string_view filename) const override
virtual ~fsCODRFileUtils()
virtual bool isDirectoryExist(std::string_view dirPath) const override
virtual bool writeValueMapToFile(const ax::ValueMap &dict, std::string_view fullPath) const override
virtual std::string getNativeWritableAbsolutePath() const override
virtual std::string getStringFromFile(std::string_view filename) const override
virtual bool isFileExistInternal(std::string_view filename) const override
virtual FileUtils::Status getContents(std::string_view filename, ax::ResizableBuffer *buffer) const override
virtual std::string getWritablePath() const override
virtual bool writeValueVectorToFile(const ax::ValueVector &vecData, std::string_view fullPath) const override
static void install()
Definition fsCODRFileUtils.mm:156
void preloadResource(std::string_view filename, const std::function< void(bool)> &callback)
Definition fsCODRFileUtils.mm:72
struct objc_object NSData
Definition fsCODRFileUtils.h:25
struct objc_object NSBundleResourceRequest
Definition fsCODRFileUtils.h:23
struct objc_object NSBundle
Definition fsCODRFileUtils.h:26
struct objc_object NSObject
Definition fsCODRFileUtils.h:24