yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
wasm_storage.h
Go to the documentation of this file.
1#ifndef YAZE_APP_PLATFORM_WASM_WASM_STORAGE_H_
2#define YAZE_APP_PLATFORM_WASM_WASM_STORAGE_H_
3
4#ifdef __EMSCRIPTEN__
5
6#include <atomic>
7#include <functional>
8#include <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/status/statusor.h"
13#include "nlohmann/json.hpp"
14
15namespace yaze {
16namespace platform {
17
28class WasmStorage {
29 public:
30 // ROM Storage Operations
31
38 static absl::Status SaveRom(const std::string& name,
39 const std::vector<uint8_t>& data);
40
46 static absl::StatusOr<std::vector<uint8_t>> LoadRom(const std::string& name);
47
53 static absl::Status DeleteRom(const std::string& name);
54
59 static std::vector<std::string> ListRoms();
60
61 // Project Storage Operations
62
69 static absl::Status SaveProject(const std::string& name,
70 const std::string& json);
71
77 static absl::StatusOr<std::string> LoadProject(const std::string& name);
78
84 static absl::Status DeleteProject(const std::string& name);
85
90 static std::vector<std::string> ListProjects();
91
92 // User Preferences Storage
93
99 static absl::Status SavePreferences(const nlohmann::json& prefs);
100
105 static absl::StatusOr<nlohmann::json> LoadPreferences();
106
111 static absl::Status ClearPreferences();
112
113 // Utility Operations
114
119 static absl::StatusOr<size_t> GetStorageUsage();
120
125 static bool IsStorageAvailable();
126
131 static absl::Status Initialize();
132
133 private:
134 // Database constants
135 static constexpr const char* kDatabaseName = "YazeStorage";
136 static constexpr int kDatabaseVersion = 1;
137 static constexpr const char* kRomStoreName = "roms";
138 static constexpr const char* kProjectStoreName = "projects";
139 static constexpr const char* kPreferencesStoreName = "preferences";
140 static constexpr const char* kPreferencesKey = "user_preferences";
141
142 // Internal helper for async operations
143 struct AsyncResult {
144 bool completed = false;
145 bool success = false;
146 std::string error_message;
147 std::vector<uint8_t> binary_data;
148 std::string string_data;
149 std::vector<std::string> string_list;
150 };
151
152 // Ensure database is initialized
153 static void EnsureInitialized();
154
155 // Check if we're running in a web context
156 static bool IsWebContext();
157
158 // Database initialized flag (thread-safe)
159 static std::atomic<bool> initialized_;
160};
161
162} // namespace platform
163} // namespace yaze
164
165#endif // __EMSCRIPTEN__
166
167#endif // YAZE_APP_PLATFORM_WASM_WASM_STORAGE_H_