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
70 static absl::Status SaveProject(const std::string& name,
71 const std::string& json,
72 bool replace_existing = true);
73
79 static absl::StatusOr<std::string> LoadProject(const std::string& name);
80
86 static absl::Status DeleteProject(const std::string& name);
87
92 static std::vector<std::string> ListProjects();
93
94 // User Preferences Storage
95
101 static absl::Status SavePreferences(const nlohmann::json& prefs);
102
107 static absl::StatusOr<nlohmann::json> LoadPreferences();
108
113 static absl::Status ClearPreferences();
114
115 // Utility Operations
116
121 static absl::StatusOr<size_t> GetStorageUsage();
122
127 static bool IsStorageAvailable();
128
133 static absl::Status Initialize();
134
135 private:
136 // Database constants
137 static constexpr const char* kDatabaseName = "YazeStorage";
138 static constexpr int kDatabaseVersion = 1;
139 static constexpr const char* kRomStoreName = "roms";
140 static constexpr const char* kProjectStoreName = "projects";
141 static constexpr const char* kPreferencesStoreName = "preferences";
142 static constexpr const char* kPreferencesKey = "user_preferences";
143
144 // Internal helper for async operations
145 struct AsyncResult {
146 bool completed = false;
147 bool success = false;
148 std::string error_message;
149 std::vector<uint8_t> binary_data;
150 std::string string_data;
151 std::vector<std::string> string_list;
152 };
153
154 // Ensure database is initialized
155 static void EnsureInitialized();
156
157 // Check if we're running in a web context
158 static bool IsWebContext();
159
160 // Database initialized flag (thread-safe)
161 static std::atomic<bool> initialized_;
162};
163
164} // namespace platform
165} // namespace yaze
166
167#endif // __EMSCRIPTEN__
168
169#endif // YAZE_APP_PLATFORM_WASM_WASM_STORAGE_H_