yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
hack_manifest_save_validation.cc
Go to the documentation of this file.
2
3#include <string>
4
5#include "absl/strings/str_cat.h"
6#include "absl/strings/str_format.h"
7#include "util/log.h"
8
9namespace yaze::editor {
10
12 const core::HackManifest& manifest, project::RomWritePolicy write_policy,
13 const std::vector<std::pair<uint32_t, uint32_t>>& ranges,
14 absl::string_view save_scope, const char* log_tag,
15 ToastManager* toast_manager) {
16 auto conflicts = manifest.AnalyzePcWriteRanges(ranges);
17 if (conflicts.empty()) {
18 return absl::OkStatus();
19 }
20
21 std::string error_msg = absl::StrFormat(
22 "Hack manifest write conflicts while saving %s:\n\n", save_scope);
23 for (const auto& conflict : conflicts) {
24 absl::StrAppend(
25 &error_msg,
26 absl::StrFormat("- Address 0x%06X is %s", conflict.address,
27 core::AddressOwnershipToString(conflict.ownership)));
28 if (!conflict.module.empty()) {
29 absl::StrAppend(&error_msg, " (Module: ", conflict.module, ")");
30 }
31 absl::StrAppend(&error_msg, "\n");
32 }
33
34 if (write_policy == project::RomWritePolicy::kAllow) {
35 LOG_DEBUG(log_tag, "%s", error_msg.c_str());
36 } else {
37 LOG_WARN(log_tag, "%s", error_msg.c_str());
38 }
39
40 if (toast_manager && write_policy == project::RomWritePolicy::kWarn) {
41 toast_manager->Show(
42 "Save warning: write conflict with hack manifest (see log)",
44 }
45
46 if (write_policy == project::RomWritePolicy::kBlock) {
47 if (toast_manager) {
48 toast_manager->Show(
49 "Save blocked: write conflict with hack manifest (see log)",
51 }
52 return absl::PermissionDeniedError("Write conflict with Hack Manifest");
53 }
54
55 return absl::OkStatus();
56}
57
58} // namespace yaze::editor
Loads and queries the hack manifest JSON for yaze-ASM integration.
std::vector< WriteConflict > AnalyzePcWriteRanges(const std::vector< std::pair< uint32_t, uint32_t > > &pc_ranges) const
Analyze a set of PC-offset ranges for write conflicts.
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
#define LOG_DEBUG(category, format,...)
Definition log.h:103
#define LOG_WARN(category, format,...)
Definition log.h:107
std::string AddressOwnershipToString(AddressOwnership ownership)
Editors are the view controllers for the application.
absl::Status ValidateHackManifestSaveConflicts(const core::HackManifest &manifest, project::RomWritePolicy write_policy, const std::vector< std::pair< uint32_t, uint32_t > > &ranges, absl::string_view save_scope, const char *log_tag, ToastManager *toast_manager)