yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
rom_version_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_NET_ROM_VERSION_MANAGER_H_
2#define YAZE_APP_NET_ROM_VERSION_MANAGER_H_
3
4#include <map>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "rom/rom.h"
12
13#ifdef YAZE_WITH_JSON
14#include "nlohmann/json.hpp"
15#endif
16
17namespace yaze {
18
19namespace net {
20
26 std::string snapshot_id;
27 std::string description;
28 int64_t timestamp;
29 std::string rom_hash;
30 std::vector<uint8_t> rom_data;
32
33 // Metadata
34 std::string creator;
35 bool is_checkpoint; // Manual checkpoint vs auto-backup
36 bool is_safe_point; // Marked as "known good" by host
37
38#ifdef YAZE_WITH_JSON
39 nlohmann::json metadata; // Custom metadata (proposals applied, etc.)
40#endif
41};
42
48 std::string from_snapshot_id;
49 std::string to_snapshot_id;
50 std::vector<std::pair<size_t, std::vector<uint8_t>>> changes; // offset, data
52 std::vector<std::string> proposals_applied; // IDs of proposals in this diff
53};
54
67 public:
68 struct Config {
69 bool enable_auto_backup = true;
70 int auto_backup_interval_seconds = 300; // 5 minutes
71 size_t max_snapshots = 50;
72 size_t max_storage_mb = 500; // 500MB max for all snapshots
73 bool compress_snapshots = true;
75 };
76
77 explicit RomVersionManager(Rom* rom);
79
83 absl::Status Initialize(const Config& config);
84
88 absl::StatusOr<std::string> CreateSnapshot(const std::string& description,
89 const std::string& creator,
90 bool is_checkpoint = false);
91
95 absl::Status RestoreSnapshot(const std::string& snapshot_id);
96
100 absl::Status MarkAsSafePoint(const std::string& snapshot_id);
101
105 std::vector<RomSnapshot> GetSnapshots(bool safe_points_only = false) const;
106
110 absl::StatusOr<RomSnapshot> GetSnapshot(const std::string& snapshot_id) const;
111
115 absl::Status DeleteSnapshot(const std::string& snapshot_id);
116
120 absl::StatusOr<VersionDiff> GenerateDiff(const std::string& from_id,
121 const std::string& to_id) const;
122
126 absl::StatusOr<bool> DetectCorruption();
127
131 absl::Status AutoRecover();
132
136 absl::Status ExportSnapshot(const std::string& snapshot_id,
137 const std::string& filepath);
138
142 absl::Status ImportSnapshot(const std::string& filepath);
143
147 std::string GetCurrentHash() const;
148
152 absl::Status CleanupOldSnapshots();
153
166 Stats GetStats() const;
167
168 private:
171 std::map<std::string, RomSnapshot> snapshots_;
172 std::string last_known_hash_;
174
175 // Helper functions
176 std::string ComputeRomHash() const;
177 std::vector<uint8_t> CompressData(const std::vector<uint8_t>& data) const;
178 std::vector<uint8_t> DecompressData(
179 const std::vector<uint8_t>& compressed) const;
180 absl::Status ValidateRomIntegrity() const;
181 size_t GetTotalStorageUsed() const;
183};
184
196 public:
197 enum class ApprovalMode {
198 kHostOnly, // Only host can approve
199 kMajorityVote, // Majority of participants must approve
200 kUnanimous, // All participants must approve
201 kAutoApprove // No approval needed (dangerous!)
202 };
203
205 std::string proposal_id;
206 std::string status; // "pending", "approved", "rejected", "applied"
207 std::map<std::string, bool> votes; // username -> approved
208 int64_t created_at;
209 int64_t decided_at;
210 std::string snapshot_before; // Snapshot ID before applying
211 std::string snapshot_after; // Snapshot ID after applying
212 };
213
214 explicit ProposalApprovalManager(RomVersionManager* version_mgr);
215
219 void SetApprovalMode(ApprovalMode mode);
220
224 void SetHost(const std::string& host_username);
225
229 absl::Status SubmitProposal(const std::string& proposal_id,
230 const std::string& sender,
231 const std::string& description,
232 const nlohmann::json& proposal_data);
233
237 absl::Status VoteOnProposal(const std::string& proposal_id,
238 const std::string& username, bool approved);
239
243 absl::Status ApplyProposal(const std::string& proposal_id, Rom* rom);
244
248 absl::Status RejectProposal(const std::string& proposal_id);
249
253 absl::StatusOr<ApprovalStatus> GetProposalStatus(
254 const std::string& proposal_id) const;
255
259 std::vector<ApprovalStatus> GetPendingProposals() const;
260
264 bool IsProposalApproved(const std::string& proposal_id) const;
265
269 std::vector<ApprovalStatus> GetAuditLog() const;
270
271 private:
274 std::string host_username_;
275 std::map<std::string, ApprovalStatus> proposals_;
276 std::vector<std::string> participants_;
277
278 bool CheckApprovalThreshold(const ApprovalStatus& status) const;
279};
280
281} // namespace net
282
283} // namespace yaze
284
285#endif // YAZE_APP_NET_ROM_VERSION_MANAGER_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
Manages proposal approval workflow for collaborative sessions.
std::vector< std::string > participants_
void SetHost(const std::string &host_username)
absl::Status RejectProposal(const std::string &proposal_id)
absl::StatusOr< ApprovalStatus > GetProposalStatus(const std::string &proposal_id) const
std::vector< ApprovalStatus > GetAuditLog() const
absl::Status VoteOnProposal(const std::string &proposal_id, const std::string &username, bool approved)
bool IsProposalApproved(const std::string &proposal_id) const
absl::Status SubmitProposal(const std::string &proposal_id, const std::string &sender, const std::string &description, const nlohmann::json &proposal_data)
std::vector< ApprovalStatus > GetPendingProposals() const
bool CheckApprovalThreshold(const ApprovalStatus &status) const
absl::Status ApplyProposal(const std::string &proposal_id, Rom *rom)
ProposalApprovalManager(RomVersionManager *version_mgr)
std::map< std::string, ApprovalStatus > proposals_
Manages ROM versioning, snapshots, and rollback capabilities.
absl::StatusOr< VersionDiff > GenerateDiff(const std::string &from_id, const std::string &to_id) const
std::vector< uint8_t > DecompressData(const std::vector< uint8_t > &compressed) const
absl::StatusOr< std::string > CreateSnapshot(const std::string &description, const std::string &creator, bool is_checkpoint=false)
absl::StatusOr< RomSnapshot > GetSnapshot(const std::string &snapshot_id) const
absl::Status ExportSnapshot(const std::string &snapshot_id, const std::string &filepath)
std::map< std::string, RomSnapshot > snapshots_
absl::Status ValidateRomIntegrity() const
absl::Status ImportSnapshot(const std::string &filepath)
absl::Status Initialize(const Config &config)
absl::StatusOr< bool > DetectCorruption()
absl::Status RestoreSnapshot(const std::string &snapshot_id)
absl::Status MarkAsSafePoint(const std::string &snapshot_id)
std::vector< uint8_t > CompressData(const std::vector< uint8_t > &data) const
absl::Status DeleteSnapshot(const std::string &snapshot_id)
std::vector< RomSnapshot > GetSnapshots(bool safe_points_only=false) const
Represents a versioned snapshot of ROM state.
std::vector< uint8_t > rom_data
Represents differences between two ROM versions.
std::vector< std::pair< size_t, std::vector< uint8_t > > > changes
std::vector< std::string > proposals_applied